Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTMLCanvas 'getContext' is not a supported property or method

I've just lauched a HTML5 game application, and I keep receiving 'object doesn't support property or method 'getContext' errors logs from some of my users.

My setup only allows users with Chrome (16<), Firefox (9<) or IE (9<) to play the game. IE (<9) users gets a chromeframe installation in their face.

Its only some of my IE9 users that throw this exception. I've played the game on several windows machines with IE9, both vista and windows 7.

Searching my source, for the function call getContext, I get the same pattern. I create a canvas element using document.createElement, and then i call getContext('2d'), the next line.

var buffer = /** @type {!HTMLCanvasElement} */ (document.createElement('canvas')),
    ctx = /** @type {!CanvasRenderingContext2D} */ (buffer.getContext('2d')),
    draw = function(ctx) {
       /**
        * Alot of drawing calls.
        */
    };
draw(ctx);

Given that alot of my IE9 users run the game as it should, i don't think that this is a problem with my code, but rather some toolbar/plugin or setting in IE9 that is tripping me here.

What do you guys think ?

like image 234
Firecow Avatar asked Feb 16 '12 07:02

Firecow


1 Answers

After inserting <meta http-equiv="X-UA-Compatible" content="chrome=1, IE=edge"> we have reduced the bug count a lot, we still have a few, but that could be users logging in with weird browsers that the chromeframe install check doesn't catch.

chrome=1 means 'use chrome frame' if its there.

IE=edge means 'use highest possible version of IE'.

So i'll go with that for now.

like image 66
Firecow Avatar answered Oct 13 '22 21:10

Firecow