Does PlayCanvas have API to check WebGL support?

Hello, does PlayCanvas have API functions to check if the browser supports WebGL and if WebGL is enabled/supported by the hardware? It looks like if I want to do it directly with WebGL there’s Just wondering if the engine has any code that already does that checking for you.

Hi @Chris,

So, if the Playcanvas pc.Application instance manages to boot and run then yes this browser supports WebGL.

If not, an exception is thrown at that instant, you can check the Playcanvas build loader (__start__.js) how it does this:

    try {
        app = new pc.Application(canvas, {
            elementInput: devices.elementInput,
            keyboard: devices.keyboard,
            mouse: devices.mouse,
            gamepads: devices.gamepads,
            touch: devices.touch,
            graphicsDeviceOptions: window.CONTEXT_OPTIONS,
            assetPrefix: window.ASSET_PREFIX || "",
            scriptPrefix: window.SCRIPT_PREFIX || "",
            scriptsOrder: window.SCRIPTS || []
    } catch (e) {
        if (e instanceof pc.UnsupportedBrowserError) {
            displayError('This page requires a browser that supports WebGL.<br/>' +
                    '<a href="">Click here to find out more.</a>');
        } else if (e instanceof pc.ContextCreationError) {
            displayError("It doesn't appear your computer can support WebGL.<br/>" +
                    '<a href="">Click here for more information.</a>');
        } else {
            displayError('Could not initialize application. Error: ' + e);


And there is also a property which can be used to check the WebGL1 vs WebGL2 context:

if( === true) {}

Thanks @Leonidas that’s good to know, thanks. So, that seems to cover the situation where the browser doesn’t support WebGL. I guess I didn’t see that error because I’ve been doing testing on devices that have WebGL either disabled or not supported by the hardware. With those devices PlayCanvas hangs at the load screen with progress 0% and no errors show in the console. Should I make a bug ticket for that? Seems like pc.ContextCreationError should cover that situation.

Hmm, good point, having the loader stuck 0% when WebGL is not available doesn’t make for a good experience.

@Chris definitely submit this issue. As a user I’d expect an error message to popup or something in the Playcanvas loader site.

1 Like

Bug report:

Tracked it down, in these situations the loading screen blocks visibility of the WebGL error. So, the UnsupportedBrowserError actually was triggering, but it was hidden behind the loading screen. For my own purposes I’m going to end up handling these errors elsewhere anyways, but it’s good to know they do trigger as expected.

Again thanks for the help.