How do I run a local Unity WebGL (file:// url) build?

Viewed 45334

Multiple browsers (Chrome, Firefox, Internet Explorer) give the following error when trying to open a local Unity WebGL build:

It seems your browser does not support running Unity WebGL content from file:// urls. Please upload it to an http server, or try a different browser.

Microsoft Edge is able to run it, but I would like to know if there are any settings that can be changed to get it to run on Chrome/Firefox/other browsers.

4 Answers

just open your terminal and go into your directory (where the HTML file lies), and start the server using one of the commands below.

python -m CGIHTTPServer 8360
python -m http.server --cgi 8360
python3 -m http.server --cgi 8360

This will open the port for you.

Then direct your browser to http://localhost:8360/YOURFILENAME.html The default one would usually be index.html ;)

The correct way to run your Unity-WebGL app locally is to use a simple server.

Even Unity itself runs as a small web server run you run a WebGL build from the editor.

Here's one, Here's another, here's a whole list others

Turning off your browser security is as poor advice as turning off your virus scanner or your firewall. Don't do it. Especially when the correct way is so trivial.

These instructions were found in Dr. Tim Chamillard's game development course:

Firefox (recommended browser for running WebGL)

  1. Type about:config in the navigation bar
  2. Search for the security.fileuri.strict_origin_policy parameter
  3. Click that parameter to change it to false

Chrome

  1. Add a shortcut to Chrome on your desktop if you don't have one
  2. Right click the shortcut and select Properties
  3. Select the Target text box, go to the end, add a space and add --allow-file-access-from-files
  4. Double-click the index html file for the WebGL build and copy the URL in the navigation bar when the browser opens
  5. Close the browser
  6. Start the browser using the shortcut, paste in the URL you copied in Step 4 and press enter

Microsoft Edge

No need to do anything, WebGL builds work fine.

Safari

  1. Enable the develop menu using the preferences panel, under Advanced → “Show develop menu in menu bar”
  2. From the safari “Develop” menu, select “Disable local file restrictions”

As a general rule, restart your computer after making these changes since browsers require it and some don't.

For people who want a simple solution to this I made a windows application for the local hosting problem, You'll have just to input your WebGL game path and it will host your game locally with one click.

you can find the app here: https://uusoft.itch.io/unity-webgl-local-hoster

Related