I am trying to make a canvas app that responds to keyboard and mouse input. I have this code:
canvas = document.getElementById(\'canvas\');
canvas.addEventLi
encapsulate all of your js code within a window.onload function. I had a similar issue. Everything is loaded asynchronously in javascript so some parts load quicker than others, including your browser. Putting all of your code inside the onload function will ensure everything your code will need from the browser will be ready to use before attempting to execute.