featuretest.js example


Result fields are interpreted as follows:

Usage

To incorporate the feature tests to your own code, copy over featuretest.js from this repository and call the browserFeatureTest function as shown in the code snippet below. See the page source of this .html file for a complete example.

    <html>
      <body>
        <script src="featuretest.js"></script>
        <script>
          function onFeatureTestComplete(results) {
            // Example: how to test for the presence of a certain API
            if (results.supportedApis.indexOf('IndexedDB') != -1) console.log('IndexedDB is supported!');

            // Example: how to find if WebGL comes without a performance caveat.
            if (results.webGLSupport.webgl1.supported && !results.webGLSupport.webgl1.performanceCaveat) console.log('Hardware-accelerated WebGL is supported!');

            // Example: dump all results as a whitespace-readable JSON string.
            console.log(JSON.stringify(results, null, 2));
          }
          browserFeatureTest(onFeatureTestComplete);
        </script>
      </body>
    </html>