I am attempting to detect WebGL support across multiple browsers and I\'ve encountered the following scenario. The current version of Firefox appears to report positive supp
As seen in http://www.browserleaks.com/webgl#howto-detect-webgl
This is a proper javascript function to detect WebGL support, with all kind of experimental WebGL context names and with checking of special cases, such as blocking WebGL functions by NoScript or TorBrowser.
It will report one of the three WebGL capability states:
- WebGL is enabled — return TRUE, or return
- WebGL object, if the first argument was passed
- WebGL is disabled — return FALSE, you can change it if you need>
- WebGL is not implimented — return FALSE
function webgl_detect(return_context)
{
if (!!window.WebGLRenderingContext) {
var canvas = document.createElement("canvas"),
names = ["webgl2", "webgl", "experimental-webgl", "moz-webgl", "webkit-3d"],
context = false;
for(var i=0;i< names.length;i++) {
try {
context = canvas.getContext(names[i]);
if (context && typeof context.getParameter == "function") {
// WebGL is enabled
if (return_context) {
// return WebGL object if the function's argument is present
return {name:names[i], gl:context};
}
// else, return just true
return true;
}
} catch(e) {}
}
// WebGL is supported, but disabled
return false;
}
// WebGL not supported
return false;
}