Warning when running HTML5 game locally via .html file

If you create a HTML5 game and then try to run the game in your browser by double-clicking the .html file you produced, please be aware that this is not the correct method for testing your game or passing it around to other people. You will see that you get a warning dialogue advising you to use a web server setup instead.

Why is this?

Browsers will fail to load assets or run your game because of cross-site scripting, often shortened to XSS, which is a protection system within the browser designed to block a website's code affecting a local machine negatively. If the html file is local, it will be very strict with the protection. Typically, this will result in your game assets failing to load and possibly your game code being ignored also, leading to crashes  (however, the major browsers do differ in how strict they enforce this).

If you would like to read up on the details of XSS, start here: http://en.wikipedia.org/wiki/Cross-site_scripting

So how do I test my exported game correctly?

The obvious answer is to upload the game to your web server and test it there (you can find out how to do this from the article here), but if you want a way of testing files privately or you don't have access to your FTP where you are, etc., then you should look into setting up a local webserver application, such as WAMP or XAMPP. These will allow you to designate a folder on your machine which will then work with the software to mimic a webhost. You would then choose this folder when doing Create Executable in GM and the files would be ready for you to test with.

Now, assuming that you left your html output name as the default of "index.html", simply typing "localhost" (without the quotes) in your web browser address bar will then present you with your game, as this way the browser is able to perform all of the XSS checks it wants to and can verify that your webpage is safe to run properly. You will also be able to do this easily using the system tray icon which WAMP/XAMPP give you.

Please follow through your chosen web server's documentation as to how to set it up.

One warning: If you use Skype it has a setting "Use port 80 and 433 as alternatives for incoming connections" in Options > Advanced > Connection. If this is enabled it will block WAMP from starting up fully (unaware if this affects XAMPP also).

Have more questions? Submit a request


Article is closed for comments.