0

I have a WebGL browser game that does not work for users that have the "Use hardware acceleration when available" setting unchecked in Chrome, they get a message that says "You need a browser which supports WebGL to run this content, please try using Firefox". I would like to catch this error, and display a custom message/send them to my guide page which shows them how to enable hardware acceleration in Chrome, so they don't get turned off and leave all together. How would I be able to do this?

error

gman
  • 83,286
  • 25
  • 191
  • 301
daniel metlitski
  • 635
  • 2
  • 11
  • 22

1 Answers1

0

The following piece of code would work for you:

var hasWebGL = (function() {
  if (!window.WebGLRenderingContext) {
    return 0;
  }

  var canvas = document.createElement('canvas');
  var gl = canvas.getContext("webgl");

  if (!gl) {
    gl = canvas.getContext("experimental-webgl");
    if (!gl) return 0;
  }

  return 1;
})();

if (!hasWebGL) alert('Custom message!');

But you might want to check the full script I found over there that checks webgl compatibility.

Hope it help you.

Mauro Aguilar
  • 579
  • 7
  • 18