The excellent Three library has, in fact, a mechanism for detecting the following:
- WebGL support
- File API support
- Workers support
For WebGL, particularly, here is the code that is used:
function webgl_support () {
try {
var canvas = document.createElement('canvas');
return !!window.WebGLRenderingContext &&
(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
} catch(e) {
return false;
}
};
That code snippet is part of a Detector class which may also display the corresponding error messages to the user.