Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

(BUG) Unity Web GL build preview only works once

Discussion in 'WebGL' started by son1cman, Apr 29, 2019.

  1. son1cman

    son1cman

    Joined:
    Jan 2, 2015
    Posts:
    15
    Im currently debugging my gamejam for ludumdare, when i click build and run (webgl build) it open on chrome normally, but if you build and run again it say :
    This site can’t be reached
    localhost refused to connect.

    If i close unity and open the project again it will build and display normally but a second, third try it wont make it work.

    Notes:

    I create a bran new projects (no scripts) just the default scene and still getting the same bug.
     
    kartoonist435 likes this.
  2. TommyTheITGuy

    TommyTheITGuy

    Joined:
    Jun 11, 2015
    Posts:
    49
    https://docs.unity3d.com/Manual/webgl-building.html

    My suggestion for a work around is to make a simple script that calls BuildPipeline.BuildPlayer and then runs Chrome with the specified flag to open the index.html file. Or just build to the same directory and run a local http server to view the game in Chrome (I recommend MiniWeb for Windows).

    However, seems like Unity does not host the server after second build & run - you should report it as a bug.
     
  3. kartoonist435

    kartoonist435

    Joined:
    Feb 14, 2015
    Posts:
    71
    Did you ever report this? I'm running into the same issue suddenly. I've never had this problem and haven't changed anything in my files or chrome.
     
  4. kartoonist435

    kartoonist435

    Joined:
    Feb 14, 2015
    Posts:
    71
    I was able to download the project from collaborate on another computer and build and run worked perfectly on that machine. On my original computer I tried redownloading the collab version, still can’t build and run more than once. Tried uninstalling and reinstalling Unity and still can’t build and run more than once. I’ve also restarted my computer but at this point sounds like a computer/driver/corruption issue somewhere between Unity and this local server it creates to test WebGL.
     
  5. vadimtihonyuk

    vadimtihonyuk

    Joined:
    Feb 26, 2018
    Posts:
    32
    Just create simple server on node js + express to serve public files and then drop your build in public folder
     
  6. kartoonist435

    kartoonist435

    Joined:
    Feb 14, 2015
    Posts:
    71
    I get your suggestion but this doesn't explain why the same version same everything suddenly stops working with build and run. I had this working on a different computer and it just started doing this to me again. I has worked for a long time so there is clearly some error or change in the builds or cache that is causing this. I need to know how Unity is creating this server to run these and why suddenly it won't let build and run like it is supposed to.