0

I am using WebGL from a WebView in Android. For detecting whether WebGL is supported or not, I am using this function.

Android KitKat devices do not have WebGL support enabled, as mentioned everywhere. However, in my 4.4.2 test device, the detection function is returning true, and when invoking http://webglreport.com from a WebView it also says WebGL1 is supported.

Unsurprisingly, nothing gets rendered. So I would like to avoid using the WebGL version of the page if WebGL is not going to work.

Is there any way I could detect better for webGL? Or should I just say "if Android < 5, don't even try to check whether WebGL is supported, as it may lie".

Community
  • 1
  • 1
Jose Gómez
  • 2,891
  • 2
  • 28
  • 52

2 Answers2

1

I've had similar experiences with Android devices. Solved by blacklisting Android browser (and, if I understand correctly, stock web view as well). Updated Chrome usually works fine.

Kirill Dmitrenko
  • 2,964
  • 20
  • 28
  • Thanks. I can't really blacklist the WebView, since the goal is for a hybrid app using WebView. – Jose Gómez Dec 07 '16 at 09:26
  • 1
    There may be another way. Try to render small simple scene and read it back from a framebuffer. If it's appear fine, then the application can continue to use a WebGL code path. Otherwise, show an error message of use a fallback. – Kirill Dmitrenko Dec 07 '16 at 09:35
0

In line with @kirill-dmitrenko's answer, but avoiding parsing User Agents, I have blacklisted all browsers that do not support the "let" construct (http://caniuse.com/#feat=let), which though unrelated, seems to be supported by all modern browsers supporting webgl:

var supported;

try {
    var canvas = document.createElement('canvas');
    supported = !! window.WebGLRenderingContext && (canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
} catch(e) { supported = false; }

try {
    // let is by no means required, but will help us rule out some old browsers: http://caniuse.com/#feat=let
    eval('let foo = 123;');
} catch (e) { supported = false; }

if (supported === false) {
    console.log("WebGL is not supported");
}
Jose Gómez
  • 2,891
  • 2
  • 28
  • 52