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 support using the following check, even when the visitor's video card is black-listed and/or WebGL is disabled:
if (window.WebGLRenderingContext) {
// This is true in Firefox under certain circumstances,
// even when WebGL is disabled...
}
I've tried instructing my users to enable WebGL using the following steps. This has worked in some cases, but not always. Obviously, this is not something I can request of the general public:
- Type about:config in Firefox’s address bar
- To enable WebGL, set webgl.force-enabled to true
This has led me to create my own method for detecting support, which uses jQuery to inject a canvas element to detect support. This pulls on a number of techniques I found in various WebGL libraries and plugins. The trouble is, it is extremely difficult to test (any comments on whether the link below works for you are much appreciated!). To make this an objective question, I would like to know if there's a universally accepted way to detect WebGL support across all browsers.
TEST URL:
In order to detect browsers that support WebGL, but leaving out older browsers with may not support it well (as needed in WebGL detected as supported when it is actually not for ruling out Android 4.4.2 devices), I am adding a tighter, though unrelated check:
In addition to @Andrew answer, there is also experimental mode which can be supported. I have written following snippet of code:
Change
canvasID
variable according to your ID.Tested on Chrome, Safari, Firefox, Opera and IEs (8 to 10). In case of Safari remember that it's available, but you need to enable WebGL explicitly (enable the developer menu and enable Web GL option after).
From MDN:
[Oct 2014] I've updated modernizrs example to match their current implementation, which is a cleaned up version from http://get.webgl.org/ further below.
Modernizr does,
Chromium points to http://get.webgl.org/ for the canonical support implementation,
The excellent Three library has, in fact, a mechanism for detecting the following:
For WebGL, particularly, here is the code that is used:
That code snippet is part of a Detector class which may also display the corresponding error messages to the user.
* re "potential to exceed contexts or mem limit" see https://bugs.chromium.org/p/chromium/issues/detail?id=226868