25

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.

gman
  • 100,619
  • 31
  • 269
  • 393
k-venkatesan
  • 655
  • 1
  • 8
  • 15
  • This is an interesting question because WebGL can be a replacement for Flash, but without the ability to just open a file it becomes at the very least tedious and limits its potential – Forestrf Aug 04 '21 at 21:52
  • Edge is not supporting now – Surya Nov 08 '21 at 20:48

4 Answers4

27

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 ;)

Charles
  • 463
  • 4
  • 9
  • It says there is no CGIHTTPServer installed. – Mert Jan 25 '21 at 16:32
  • so why not install it – Charles May 04 '21 at 14:31
  • 3
    Don't need the cgi parameter anymore. `python -m http.server ` works fine for me, though I usually add the -u parameter so I can see the output as it runs. (Using Python v3.9.2) – Sirius 5 Jun 30 '21 at 22:22
  • Seems this is pretty slow: see https://stackoverflow.com/questions/12905426/what-is-a-faster-alternative-to-pythons-http-server-or-simplehttpserver. Better to use Node or Git. – david.pfx Sep 23 '22 at 03:21
  • Doesn't seem to work with compressed builds. At least in my python 3.10 install, http.server does not serve the Content-Encoding header correctly, leading to an error in the WebGL Player – RHS Jan 27 '23 at 14:57
15

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.

gman
  • 100,619
  • 31
  • 269
  • 393
5

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.

k-venkatesan
  • 655
  • 1
  • 8
  • 15
  • 2
    Hardly horrible if it lets me work. Obviously, you should be aware of what you are changing, but especially in the case of Chrome (where a separate instance can be used to test WebGL and regular internet use) it is a very handy advice. I'd much rather do that than installing local web servers. – Eric Feb 18 '21 at 17:50
  • Does this mean that Microsoft Edge has bad security or that it can tell the difference between running a web page locally and accessing files in unsafe places? – Ingemar Ragnemalm Mar 27 '22 at 07:09
  • I absolutely understand that it is bad to turn off security measures, but when it is the only solution that works for me, I have no choice. So here is my solution: I develop on a laptop with the network turned off. When it is time to test online, I either move the files to another computer, or I turn up the security again. It is a hassle but better than not being able to run locally. – Ingemar Ragnemalm Mar 27 '22 at 07:10
  • @eric, I'm only guessing you believe, as I once did, that installing a webserver was a large task. It's not. There are big hairy install deep in your system webservers like apache or IIS (is that sill a thing?). And there are tiny webservers that are just [a simple command line tool you run](https://github.com/greggman/servez-cli) or a [simple app](https://greggman.github.io/servez/). This is 1-5 minute process. – gman Nov 03 '22 at 02:12
0

If you're still facing issues, I recommend checking out this link: uusoft.itch.io/unity-webgl-local-hoster. It's an excellent free and open-source tool that might help you out with hosting Unity WebGL builds locally. Give it a try and see if it resolves your problem!

EDIT: This code appears to be written by the OP

enhzflep
  • 12,927
  • 2
  • 32
  • 51