detect the gpu (kinda)

This commit is contained in:
Jeff Carr 2017-11-29 12:16:44 +00:00
parent df678ad760
commit c1fb471d26
4 changed files with 464 additions and 4 deletions

View File

@ -0,0 +1,272 @@
/* Do not copy this file. Instead, do something like this in your
own code.
if (!window.WebGLRenderingContext) {
// Browser has no idea what WebGL is. Suggest they
// get a new browser by presenting the user with link to
// http://get.webgl.org
return;
}
gl = canvas.getContext("webgl");
if (!gl) {
// Browser could not initialize WebGL. User probably needs to
// update their drivers or get a new browser. Present a link to
// http://get.webgl.org/troubleshooting
return;
}
*/
var BrowserDetect = {
init: function () {
var info = this.searchString(this.dataBrowser) || {identity:"unknown"}
this.browser = info.identity;
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.platformInfo = this.searchString(this.dataPlatform) || this.dataPlatform["unknown"];
this.platform = this.platformInfo.identity;
var browserInfo = this.urls[this.browser];
if (!browserInfo) {
browserInfo = this.urls["unknown"];
} else if (browserInfo.platforms) {
var info = browserInfo.platforms[this.platform];
if (info) {
browserInfo = info;
}
}
this.urls = browserInfo;
},
searchString: function (data) {
for (var i = 0; i < data.length; i++){
var info = data[i];
var dataString = info.string;
var dataProp = info.prop;
this.versionSearchString = info.versionSearch || info.identity;
if (dataString) {
if (dataString.indexOf(info.subString) != -1) {
var shouldExclude = false;
if (info.excludeSubstrings) {
for (var ii = 0; ii < info.excludeSubstrings.length; ++ii) {
if (dataString.indexOf(info.excludeSubstrings[ii]) != -1) {
shouldExclude = true;
break;
}
}
}
if (!shouldExclude)
return info;
}
} else if (dataProp) {
return info;
}
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) {
return;
}
return parseFloat(dataString.substring(
index + this.versionSearchString.length + 1));
},
dataBrowser: [
{ string: navigator.userAgent,
subString: "Chrome",
excludeSubstrings: ["OPR/", "Edge/"],
identity: "Chrome"
},
{ string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{ string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
},
{ string: navigator.vendor,
subString: "Opera",
identity: "Opera"
},
{ string: navigator.userAgent,
subString: "Android",
identity: "Android"
},
{ string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{ string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{ string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{ string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{// for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{ string: navigator.userAgent,
subString: "Edge/",
identity: "Edge"
},
{ string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{ // for IE11+
string: navigator.userAgent,
subString: "Trident",
identity: "Explorer",
versionSearch: "rv"
},
{ string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataPlatform: [
{ string: navigator.platform,
subString: "Win",
identity: "Windows",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"},
{url: "http://www.opera.com/", name: "Opera"},
{url: "http://www.google.com/chrome/", name: "Google Chrome"},
{url: "http://www.microsoft.com/en-us/windows/windows-10-upgrade ", name: "Edge"},
{url: "http://www.microsoft.com/ie", name: "Internet Explorer"}
]
},
{ string: navigator.platform,
subString: "Mac",
identity: "Mac",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"},
{url: "http://www.google.com/chrome/", name: "Google Chrome"},
{url: "http://www.opera.com/", name: "Opera"},
{url: "http://www.webkit.org/", name: "WebKit Developer Builds"}
]
},
{ string: navigator.userAgent,
subString: "iPhone",
identity: "iPhone/iPod",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"}
]
},
{ string: navigator.platform,
subString: "iPad",
identity: "iPad",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"}
]
},
{ string: navigator.userAgent,
subString: "Android",
identity: "Android",
browsers: [
{url: "https://market.android.com/details?id=org.mozilla.firefox", name: "Mozilla Firefox"},
{url: "https://market.android.com/details?id=com.opera.browser", name: "Opera Mobile"}
]
},
{ string: navigator.platform,
subString: "Linux",
identity: "Linux",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"},
{url: "http://www.google.com/chrome/", name: "Google Chrome"},
{url: "http://www.opera.com/", name: "Opera"}
]
},
{ string: "unknown",
subString: "unknown",
identity: "unknown",
browsers: [
{url: "http://www.mozilla.com/en-US/firefox/new/", name: "Mozilla Firefox"},
{url: "http://www.google.com/chrome/", name: "Google Chrome"},
{url: "http://www.opera.com/", name: "Opera"},
{url: "http://www.webkit.org/", name: "WebKit Developer Builds"}
]
}
],
/*
upgradeUrl: Tell the user how to upgrade their browser.
troubleshootingUrl: Help the user.
platforms: Urls by platform. See dataPlatform.identity for valid platform names.
*/
urls: {
"Chrome": {
upgradeUrl: "http://www.google.com/support/chrome/bin/answer.py?answer=95346",
troubleshootingUrl: "http://www.google.com/support/chrome/bin/answer.py?answer=1220892"
},
"Firefox": {
upgradeUrl: "http://www.mozilla.com/en-US/firefox/new/",
troubleshootingUrl: "https://support.mozilla.com/en-US/kb/how-do-i-upgrade-my-graphics-drivers"
},
"Opera": {
platforms: {
"Android": {
upgradeUrl: "https://market.android.com/details?id=com.opera.browser",
troubleshootingUrl: "http://www.opera.com/support/"
}
},
upgradeUrl: "http://www.opera.com/",
troubleshootingUrl: "http://www.opera.com/support/"
},
"Android": {
upgradeUrl: null,
troubleshootingUrl: null
},
"Safari": {
platforms: {
"iPhone/iPod": {
upgradeUrl: "http://www.apple.com/ios/",
troubleshootingUrl: "http://www.apple.com/support/iphone/"
},
"iPad": {
upgradeUrl: "http://www.apple.com/ios/",
troubleshootingUrl: "http://www.apple.com/support/ipad/"
},
"Mac": {
upgradeUrl: "http://www.webkit.org/",
troubleshootingUrl: "https://support.apple.com/kb/PH21426"
}
},
upgradeUrl: "http://www.webkit.org/",
troubleshootingUrl: "https://support.apple.com/kb/PH21426"
},
"Explorer": {
upgradeUrl: "http://www.microsoft.com/ie",
troubleshootingUrl: "http://msdn.microsoft.com/en-us/library/ie/bg182648(v=vs.85).aspx"
},
"Edge": {
upgradeUrl: "http://www.microsoft.com/en-us/windows/windows-10-upgrade",
troubleshootingUrl: "http://msdn.microsoft.com/en-us/library/ie/bg182648(v=vs.85).aspx"
},
"unknown": {
upgradeUrl: null,
troubleshootingUrl: null
}
}
};

72
detect_gpu.html Normal file
View File

@ -0,0 +1,72 @@
<HTML>
<HEAD><TITLE> Banner</TITLE>
</HEAD>
<body >
<script LANGUAGE= "javascript">
/*
// this code doesn't seem to be correct
if (window.WebGLRenderingContext) {
alert('Your browser does not support WebGL');
}
*/
var canvas = document.createElement('canvas');
var gl;
var debugInfo;
var vendor;
var renderer;
document.write("<br>Trying to create a webgl object<br>");
try {
gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
} catch (e) {
}
if (gl) {
debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
document.write(debugInfo + "<br><br>");
document.write(vendor + "<br><br>");
document.write(renderer + "<br><br>");
} else {
document.write("<br>Failed gl=NULL<br>");
}
// Sample output:
//
// » console.log(renderer);
// ATI Technologies Inc. AMD Radeon R9 M370X OpenGL Engine
</script>
<h2>All objects in canvas.getContext('webgl')</h2>
<table>
<script language="JavaScript" type="text/javascript">
for (var n in gl) {
document.write("<tr>");
document.write("<th align='left'>webgl." + n + "<\/th>");
document.write("<th align='left'>" + gl[n] + "<\/th>");
document.write("<\/tr>");
}
</script>
</table>
<h2>All objects in gl.getExtension('WEBGL_debug_renderer_info')</h2>
<table>
<script language="JavaScript" type="text/javascript">
for (var n in debugInfo) {
document.write("<tr>");
document.write("<th align='left'>debugInfo." + n + "<\/th>");
document.write("<th align='left'>" + gl[n] + "<\/th>");
document.write("<\/tr>");
}
</script>
</table>
</body></HTML>

View File

@ -15,10 +15,30 @@
<br>
<br>
Your web browser is:
Your web browser is:<br><br>
<script LANGUAGE= "javascript">
document.write(navigator.userAgent + "<br><br>");
document.write(navigator.appName + "<br><br>");
document.write("userAgent = " + navigator.userAgent + "<br><br>");
document.write("appName = " + navigator.appName + "<br><br>");
var canvas = document.createElement('canvas');
var gl;
var debugInfo;
var vendor;
var renderer;
gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
if (gl) {
debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
document.write("vendor = " + vendor + "<br><br>");
document.write("renderer = " + renderer + "<br><br>");
} else {
document.write("<br>Failed gl=NULL<br>");
}
</script>
@ -41,6 +61,7 @@ document.write(navigator.appName + "<br><br>");
<a href="javascript1.html">java test1</a><br/>
<a href="javascript2.html">java test2</a><br/>
<a href="javascript3.html">java test3</a><br/>
<a href="detect_gpu.html">dump javascript webgl info</a><br/>
<a href="javascript_dump/">dump javascript info</a><br/>
<br>
@ -49,6 +70,13 @@ document.write(navigator.appName + "<br><br>");
onChange= "alert('changing this will cause an alert')">
</FORM>
<br>
<a href="https://developer.mozilla.org/en-US/docs/Web/API/Window">Official Mozilla Window Object documentation</a><br/>
<a href="https://get.webgl.org/troubleshooting/">Official webgl troubleshooting site</a><br/>
<a href="official_webgl_troubleshooting.html">Official webgl troubleshooting site (local copy)</a><br/>
<br>
<h2>All objects in window.navigator</h2>
<table>
<script language="JavaScript" type="text/javascript">
@ -114,7 +142,8 @@ document.write(navigator.appName + "<br><br>");
<a href="stuff" onMouseOver="alert('onMouseOver')">Test onMouseOver event</a><br>
<script>
document.write("<img src='favicon.ico'>")
document.write("<img src='favicon.ico'>");
document.bgColor = "white";
/*
var x=window.confirm("Are you sure you want to quit")
if (x)

View File

@ -0,0 +1,87 @@
<!DOCTYPE html>
<html>
<!--
This page attempts to redirect users to a page specific to their
browser. Contact the Khronos WebGL group to update the URL for
your browser or add your browser to the list of browsers.
-->
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>WebGL Troubleshooting</title>
<script type="text/javascript" src="https://get.webgl.org/troubleshooting/DoNotCopyOrLinkThisFileElseYouWillNotGetAutoUpdatedHelpForYourUsers.js"></script>
<script type="text/javascript">
window.onload = main;
function main() {
var link = document.getElementById("link");
var b = BrowserDetect;
b.init();
var name = b.browser;
if (name == "unknown") {
name = "your browser";
}
// check if the browser even knows what WebGL is
if (!window.WebGLRenderingContext) {
link.innerHTML = "Click Here to learn about upgrading "
+ name + " on " + b.platform + " to a browser that supports WebGL";
link.href = b.urls.upgradeUrl || "http://get.webgl.org";
return;
}
link.innerHTML = "Click Here for WebGL troubleshooting info for "
+ name + " on " + b.platform;
link.href = b.urls.troubleshootingUrl;
}
</script>
<style>
/* zero margins */
html, body { margin:0; padding:0; background-color: #888;}
/* trigger scolling */
p { margin:10em 0; }
/* position:fixed */
.outer { position:fixed; top:0; left:0; width:100%; height:100%; }
/* certering */
.middle { height:100%; display:table; margin:0 auto; }
.inner { vertical-align:middle; display:table-cell; }
.msg {
background-color: white;
border: 15px solid white;
border-radius: 15px;
}
</style>
<!--[if lte IE 6]>
<style>
/* position:fixed for ie6 */
html { overflow-x:auto; overflow-y:hidden; }
body { overflow-y:auto; height:100%; }
.outer { position:absolute; }
</style>
<![endif]-->
<!--[if lte IE 7]>
<style>
/* centering for ie6/ie7 */
.middle { position:absolute; top:50%; left:50%; height:auto; }
.inner { position:relative; top:-50%; left:-50%; }
</style>
<![endif]-->
</style>
</head>
<body>
<div class="outer">
<div class="middle">
<div class="inner">
<div class="msg">
<a id="link"></a>
</div>
</div>
</div>
</div></body>
</html>