问题
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".
回答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.
回答2:
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");
}
来源:https://stackoverflow.com/questions/41006612/webgl-detected-as-supported-when-it-is-actually-not