添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
小眼睛的热带鱼  ·  Python equivalent of ...·  1 月前    · 
俊逸的火锅  ·  Python 控制台 — Blender ...·  3 周前    · 
健身的抽屉  ·  在 Google Cloud 上使用 ...·  3 周前    · 
直爽的黑框眼镜  ·  Difference between ...·  3 周前    · 
风流的板栗  ·  香港閱讀城·  11 月前    · 
考研的台灯  ·  OH 3.3.0 Frontail not ...·  1 年前    · 
知识渊博的斑马  ·  Excel ...·  2 年前    · 
自信的胡萝卜  ·  Nosql-neo4j-Cypher 语句 ...·  2 年前    · 

Clicking “build and run” on a WebGL game opens http://localhost:52334/ and allows me to play test.
If i try to run the index file directly i get:
“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.”
What is Unity doing with the “Build and run” button and how do i replicate it so i can run folders with old builds?

Unity is starting a simple local webserver when you us build&run. Most browsers restrict loading from file:// for security reasons.
You can server old builds from a local server yourself. Try IIS or the free apache or the quick http.server that comes with a python install.

Thanks for the info Schbkraft. Setting it up and working through all the little issues now.
There is no way to get Unity to call its simple server functionality on demand rather than only at the end of a build and run command?

Firefox let’s you use “file://” by default iirc and you can do the same in chrome with setting a flag.

In general you can get IIS setup locally fairly easily (included with Windows, just not enabled by default). I personally use mamp ( https://www.mamp.info/en/ ) when I’m abroad and don’t have access to our servers.

jRocket:

You could probably make an editor script to fire it up. I think the win executable is located at Unity\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\SimpleWebServer.exe

I tried this method and it not working. When I start webserver with arguments:
SimpleWebServer.exe “path to build index.html” “port”
and then go to url localhost: port I got 403 Forbidden response.

Also got messages in the console:
Starting web server at http://localhost:58505/
Handling request: /
Forbidden.
Handling request: /favicon.ico
Forbidden.

chrome add to link
–allow-file-access-from-files
=> “C:\Program Files (x86)\Google\Chrome\Application\chrome.exe” --allow-file-access-from-files

Then open index.html

chrome add to link
–allow-file-access-from-files
=> “C:\Program Files (x86)\Google\Chrome\Application\chrome.exe” --allow-file-access-from-files

Then open index.html

Thanks. But I took this code SimpleHTTPServer in C# · GitHub and run my own web server while testing webgl builds

Another way to run an ad hoc web server is to use Emscripten’s “emrun” tool, which is designed to host WebAssembly-compiled pages.

  • Download https://raw.githubusercontent.com/emscripten-core/emscripten/incoming/emrun.py and https://raw.githubusercontent.com/emscripten-core/emscripten/incoming/emrun.bat and place them to a directory you have in PATH environment variable.
  • Navigate on command line to a directory you want to host, and type
  • emrun --no_browser .

    to host that directory. Note the “.” as the last argument, which means “current directory”.

    If you want to also automate launching the page in a browser, you can execute e.g.

    emrun --browser=“c:\program files\mozilla firefox\firefox.exe” .

    I tried this method and it not working. When I start webserver with arguments:
    SimpleWebServer.exe “path to build index.html” “port”
    and then go to url localhost: port I got 403 Forbidden response.

    Also got messages in the console:
    Starting web server at http://localhost:58505/
    Handling request: /
    Forbidden.
    Handling request: /favicon.ico
    Forbidden.

    you can actually decompile SimpleWebServer.exe with dnspy and see why it gives 403 error

    i removed this part of code and it start to work

    bool flag4 = !context.Request.IsLocal;
                    if (flag4)
                        Console.WriteLine("Forbidden.");
                        msg = "<HTML><BODY>403 Forbidden.</BODY></HTML>";
                        response.StatusCode = 403;
                  

    Tested on Unity 2019.4.7f1. Create a batch file with content below, adapting for path differences:

    cd "C:\Program Files\Unity\Hub\Editor\2019.4.7f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit" python.exe "C:\Program Files\Unity\Hub\Editor\2019.4.7f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emrun.py" "[PATH TO index.html GENERATED DURING BUILD]"

    Poindexter’s approach may work if you have a 32-bit version of Python installed separately, but in my case I get “ModuleNotFoundError: No module named ‘win32api’”

    What I found works better is one of the below, where <old_WebGL_output_dir> is the path to the previous WebGL build you want to look at…

    If you do not have Python installed separately from Unity, you can use the included version which will look something like this (you may need to adjust the path to python.exe for your current version of Unity and the version of Python bundled with it):

    cd /d "<old_WebGL_output_dir>"
    "C:\Program Files\Unity\Hub\Editor\2019.4.7f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe" -m SimpleHTTPServer
    

    If you have Python 2.x installed separately (check in CMD with python --version) you can simply do

    cd /d "<old_WebGL_output_dir>"
    python -m SimpleHTTPServer
    

    If you have Python 3.x installed separately then it’s even simpler:

    python -m http.server --directory "<old_WebGL_output_dir>"
                  

    does anyone know why running the included SimpleWebServer.exe manually doesnt work (403 forbidden),
    but if you de-compile & build new exe yourself in VS, then it works fine…? (has exact same c# code)

    For Windows, I’ve been using WampServer for at least a decade with everything imaginable, and it has always worked great for me, including for Unity WebGL builds. You install it, add a folder like C:\wamp64\www\unity, then build your WebGL project right into a folder there (or if it’s somewhere else just cut/paste it to there). Then if your project build folder is called “my_project”, your files locally would be at C:\wamp64\www\unity\my_project. And you would open it in a web browser at http://localhost/unity/my_project :slight_smile:

    i’ve always been a Xampp guy :smile: that of course work great, (theres portable Xampp too),
    but trying to make tool to run web server manually.

    *and got it working, runs fine from commandline through mono:

    "C:/Program Files/Unity2019_4/Editor/Data/MonoBleedingEdge/bin/mono.exe" "C:/Program Files/Unity2019_4/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/SimpleWebServer.exe" "X:/YourProj/Builds/" 60606
     mgear:
    

    does anyone know why running the included SimpleWebServer.exe manually doesnt work (403 forbidden),
    but if you de-compile & build new exe yourself in VS, then it works fine…? (has exact same c# code)

    Tried it today, and it was working fine, no need to recompile (2021). I used Edge (the newer chromium one) and

    SimpleWebServer.exe "Path to FOLDER containing index.html" port
                  

    Hi! This conv has been super helpful. I do have a question, is there any way to create a permanent server/link from a webGL build? Hope my question makes sense. If only 3rd party’s can do that I would prefer it if it can use something that can only be accessible through a private link rather than a public server, I just want to create a link/server similar to how nunu studio does it with their exports. If anyone knows anything about that I would appreciate the help on that! Thanks

    Write this line : Cd C:\Program Files\Unity\Hub\Editor\2021.1.16f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools

    Then Write : SimpleWebServer.exe “HERE THE PATH FOLDER OF YOUR WEBGL BUILD” 8000

    Now open your browser and Write : localhost:8000

    Voila your game is live in local server.