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
  • 100,619
  • 31
  • 269
  • 393
daniel metlitski
  • 747
  • 3
  • 11
  • 23

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
  • 1,093
  • 13
  • 22