Proper way to detect WebGL support?

The excellent Three library has, in fact, a mechanism for detecting the following:

  1. WebGL support
  2. File API support
  3. 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.

Leave a Comment