Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 201
k-venkatesan Avatar asked Jun 22 '20 15:06

k-venkatesan


People also ask

What is a WebGL URL?

WebGL: The URL of the document as shown in a browser's address bar. Android: If the application has been launched or activated using an Intent Filter, a deep link (App Link) URL.


Video Answer


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

like image 163
Charles Avatar answered Oct 18 '22 20:10

Charles


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.

like image 22
gman Avatar answered Oct 18 '22 18:10

gman


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.

like image 4
k-venkatesan Avatar answered Oct 18 '22 18:10

k-venkatesan