Detection scheme for WebGL or Unity Plugin playback

Hi Folks,

Our project will be published online, and I would like to find a way to make the playback experience as seamless as possible for the end user. Is there a JavaScript or JQuery method for detecting if a browser can play a Unity WebGL project, and if it can’t, redirect the browser to a page with a version that runs with the plugin? I know I can get the browser type and version but I would prefer to not rely on a list of compatible/non-compatible WebGL browsers, and instead use something smart enough to detect the browser’s compatibility with WebGL.

Thanks for any leads or info.
–Kevin

There is a function in generated file UnityConfig.js, which can tell you about browser WebGL support:

var hasWebGL = (function ()
{
    if (!window.WebGLRenderingContext)
    {
        // Browser has no idea what WebGL is. Suggest they
        // get a new browser by presenting the user with link to
        // http://get.webgl.org
        return 0;
    }

    var canvas = document.createElement('canvas');
    var gl = canvas.getContext("webgl");
    if (!gl)
    {
        gl = canvas.getContext("experimental-webgl");
        if (!gl)
        {
            // Browser could not initialize WebGL. User probably needs to
            // update their drivers or get a new browser. Present a link to
            // http://get.webgl.org/troubleshooting
            return 0;
        }
    }
    return 1;
})();

I use it along with browser detection: To NOT run WebGL in IE, to run WebGL in Chrome, and in all other browsers I run WebPlayer as default. But if user don’t have WebPlayer installed, he can choose to run in WebGL instead (if supported by browser).

My project runs nicely also in Opera WebGL, in Safari not so much.

For browser type and version detection I recommend bowser.

For now it should be pretty simple to write since the only browsers we are officially supporting are desktop Firefox and Chrome. So you only have to check for those two.