Search Unity

WebGL build doesn't load in browser

Discussion in 'Web' started by CaptainOtter, Aug 9, 2020.

  1. CaptainOtter

    CaptainOtter

    Joined:
    Aug 27, 2016
    Posts:
    11
    I'm creating a fresh URP project using Unity 2020.1.1f1. Then I build a WebGL project and zip the output files so that .zip contains index.html and TemplateData and the Build folders. I have tried uploading that zip to itch.io, and gamejolt.com but it doesn't work in either. It simply gets stuck right at the beginning like this: webgl-demo.png

    I have tried building with following settings with no luck:
    • Compression Enabled
    • Compression Disabled
    • Compression Enabled + Decompression Fallback
    • Development Build
    but none of those settings seem to make any difference. Project itself works, because if I use Build & Run and let Unity create fileserver to serve the game it works just fine. So it has to be something related to building the WebGL project. There are also no errors in the browser console. Same issue happens in all mainstream browsers.
     
    Last edited: Aug 9, 2020
    Tymianek, MilenaRocha and tantx like this.
  2. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    Did you figure it out? Running into similar issues with itch.io and unity 2020.1.3f1
     
  3. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    What does the web browser console say?
     
  4. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    Ran into it again this ludum dare. Iirc there were no errors in the console.

    I eventually got it to work, by using some permutation of suboptimal compression settings, can check tomorrow.

    Should be quite easy to reproduce though... I see a lot of ludum dare submissions stuck loading.

    Also, for me it happens in chrome, but not in ff, so maybe my issue is different than ops.
     
    giusti likes this.
  5. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    upload_2020-10-8_9-31-3.png

    These are the settings that finally worked for me.
     
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Thanks - where did you host your game? Is it available to play somewhere still?
     
  7. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    Here it is :) https://jhelsing.itch.io/petridish

    And this was the first one: https://jhelsing.itch.io/vincent

    Note that they don't exhibit the bug, though, as I disabled compression completely to make them playable for Chrome users.

    Also, like OP, it worked fine for me on the server that unity spun up, but not when deployed on Itch.
     
    AlbertoFdzM and SPeeD0fShAd0W like this.
  8. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Thanks. Looking at the content that is server by Itch.io via Chrome Network Devtools, it shows the following that the files Petridish.data.unityweb, Petridish.framework.js.unityweb and Petridish.wasm.unityweb are all properly served as gzip compressed, as is shown by the presence of the Content-Encoding: gzip header.

    They are doing the Right Thing when it comes to web hosting, and they employ a server-side compression cache to compress content on-demand when browsers visit them. When a server-side on-demand compression scheme is being used, developers should disable pre-compression in Unity build settings. So when uploading content to Itch.io, one should have Compression Format: Disabled and Decompression Fallback: Disabled.

    The other alternative is when a web server does not have an on-demand server-side compression engine in place. In that case, users should pre-compress the content on disk when doing the Unity build by enabling Compression Format: gzip, and then configure the server HTTP Response Header to advertise Content-Encoding: gzip for those files.
     

    Attached Files:

  9. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    Thanks for looking into it.

    I was curious why it failed originally, though, so I reproduced the issue today by creating a new clean 2D project in 2020.1.8f, building and pushing with default settings: brotli compression and no compression fallback.

    upload_2020-10-8_13-27-44.png

    It looks like itch.io does not set "Content-Encoding: br", though, and since there is no compression fallback, it fails. I guess that particular issue should be reported as a bug to itch.io, then?

    Anyways, I also tried enabling decompression fallback. This time however, I see no errors in the console, just a warning that the fallback is being used, but then it's stuck with no errors:

    upload_2020-10-8_13-34-55.png

    This, to me, looks like a bug in the unity compression fallback, though I'm not super-familiar with all the http response headers. WebGL.framework.js.unityweb has content-type: application/octet-stream for instance, which I don't really know whether is wrong or not... maybe it should say application/javascript?

    Anyways, you can try both projects if you want, password is "bug"

    - https://jhelsing.itch.io/compression-bug
    - https://jhelsing.itch.io/compression-bug-fallback

    I will delete them in a couple of weeks so they don't clutter my dashboard, though.
     
  10. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    That is correct. This is an Itch.io bug/missing feature - according to that result, they do not currently support on-disk pre-compressed Brotli content. Would be sweet if they added support for that!

    Hmm, what should this build show? When I visit it, I see a blue screen, no errors. Looking at the performance profile (https://share.firefox.dev/36LM6vA), I see that the Unity engine main loop is ticking, so the engine should be up and running, but there doesn't seem to be any content loaded. Is there supposed to be something in the scene?
     
  11. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    That's what it should show! It's just a fresh and clean unity 2d project, so blue means it works.

    What browser were you using? I tried the following browsers on the decompression fallback version:

    - Chrome 85 (on several machines): Hangs with empty loading bar, no errors. Tried in incognito as well.
    - Firefox 80: works
    - Edge: works
    - Chrome Android: Hangs
    - Firefox Android: Works
     
  12. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Testing https://jhelsing.itch.io/compression-bug-fallback on Windows 10 with
    - Firefox 81 works,
    - Chrome 85 works,
    - Edge 85 works

    Looking at the Network tab, when I was testing on Edge for the first run, I did see really slow download speed of the .wasm.br file, it took 39 seconds for Itch.io to serve the 622 kB WebGL.wasm.unityweb file, resulting in avg ~15.9kB/sec download speed. That seems like the core issue here.

    If you open the Network tab before visiting the page, it will show all the downloads that are active, and that are still processing. That will help debug whether a startup stall is due to slow download speeds, or due to Unity engine stalling. (You can do a 5-10 sec Performance profile snapshot when things have stalled to double-check if it's stalling in executing Unity code. In this case when I did that while the .wasm network transfer was still going, Performance profiler will show an empty list, as no Unity code is yet executing)
     
  13. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    Interesting... For me it downloads WebGL.wasm.unityweb almost instantly, and then it just hangs forever (or at least for 20 minutes)

    upload_2020-10-9_8-26-10.png

    I did some further testing, and found some really weird connections:

    - It only happens in Chrome and Chromium, not in Firefox, Edge, Epiphany
    - It happens in Chrome/Chromium on all my devices (2x Windows 10, Linux, Android)
    - Was an issue in Chromium 81 as well
    - I tried disabling wi-fi on my phone to see if that helped, but it didn't
    - The issue happens in both regular mode and incognito
    - BUT! If I log out of chrome it disappears, so it's somehow tied to my user, or perhaps just being logged in (I only have one user) and the weird thing is that being logged in seems to affect incognito mode as well.
    - I tried disabling all browser extensions, but it still didn't work

    So yeah, it seems somehow tied to my Chrome user.

    @jukka_j were you logged in when testing on Chrome?

    Would be interesting if @BuoyantOtter could do some similar testing.

    As for debugging the issue itself. Here's a screenshot of the profiler.

    upload_2020-10-9_9-7-32.png

    So at least it looks like it gets done decompressing then some stuff seems to be happening, and then sporadic "Task"s every other second (it just continues like that to the right). Sometimes I see GC and some event handling. Not really sure how to interpret that, though.

    upload_2020-10-9_9-11-46.png
     
  14. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    If you close the "Headers | Preview | Response | Timing" part I believe it should show the state of all the files.

    I was logged in to my Google account.

    I wonder if clearing the browser cache would have an effect.

    The decompress block occurs immediately when the files are received. The Unity engine does not seem to have run there yet, so it looks like it's still waiting for a file to come in.
     
  15. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    upload_2020-10-9_10-23-51.png

    It says "Finish" after 1.12 s, then nothing else happens.

    I got someone else to try it, and he had almost the same issues as I have:

    - It's stuck in normal mode
    - It's stuck in incognito mode
    - It works in guest mode (click your user in the top right and then guest)

    However, for him it started working in normal mode after he had visited the page in guest mode... This does not work for me.
     
  16. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Quite mysterious.. to double check, this elusive stuck-during-load only occurs when you enable precompressed files with decompression fallback turned on?
     
  17. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    Yeah, as far as I can tell, though it works with the node server unity spins up... Not sure how it serves its files encoding-wise
     
    tantx likes this.
  18. ahsen35813

    ahsen35813

    Joined:
    Sep 15, 2019
    Posts:
    9
    Extremely helpful thread, thank you!

    @bobbaluba I think you forgot to delete it because it's still there. Just wanted to let you know in case you forgot
     
  19. LootHunter

    LootHunter

    Joined:
    May 27, 2017
    Posts:
    66
    Similar problem here - except I can't even play on my computer. Web Player just starts to load and doesn't finish.
     
  20. BeorGames

    BeorGames

    Joined:
    Jul 28, 2018
    Posts:
    65
    Hello, I'm running on a similar problem, I've uploaded my game to Game Jolt and it's not playing, but it's available on Unity Play and working pretty fine: SkyKart - Unity Play what am I doing wrong?

    upload_2021-5-6_20-19-54.png
     
  21. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    288
    @BeorGames
    When I turn off hardware acceleration in Chrome, it works for some reason.:confused:
    upload_2021-5-7_17-4-29.png
     
  22. BeorGames

    BeorGames

    Joined:
    Jul 28, 2018
    Posts:
    65
    Hi! On Unity Play it's working 100%, the problem here is the build on Game Jolt, it's not working over there.
     
  23. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    288
    The site doesn't support Brotli.
    Try compiling and uploading it uncompressed.
     
  24. BeorGames

    BeorGames

    Joined:
    Jul 28, 2018
    Posts:
    65
    Hello! It's been a while...

    I can't upload an uncompressed file:
    upload_2021-5-21_20-48-28.png
     
  25. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    It doesn't matter whether you upload it in a zip or not. What matters is what you select in the unity player settings, which affects how the individual files in your project are compressed.

    upload_2021-5-25_14-42-42.png

    As far as I know, the zip itch wants you to upload is just used as a way of transporting everything at once. It will be unzipped in the other end before it's served.

    Also, even though you don't select compression format in publishing settings, itch will still compress your file with gzip before serving it, but iirc this type of compression doesn't cause issues.
     
    Fritsl likes this.
  26. BeorGames

    BeorGames

    Joined:
    Jul 28, 2018
    Posts:
    65
    Hello, actually my game has already been published using Gzip from as the compression format, I didn't understand if this is required or if I should leave it Disabled as in your screenshot.
    Also, I'm not trying to publish on Itch, I'm trying to publish on Game Jolt.

    Just a quick update, I managed to publish it using a Developer Build, but the Release Build don't load...
     
  27. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    The preferred setting for quickest load time is to public brotli-compressed Release version. If brotli is not possible on the web server, then to use gzip instead.

    It sounds like itch.io compresses the files even if one happened to upload uncompressed versions, which is great - but not all hosting services do such a patch-up after uploading the content, so double check using the Network tab in your browser.
     
  28. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    I am getting:

    "11.loader.js:1 Unable to parse Build/11.framework.js.gz! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header "Content-Encoding: gzip" present. Check browser Console and Devtools Network tab to debug."


    When trying to upload a project to GitHub Pages. It works on itch.io which is strange.
     
  29. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    So ?
    is unity able to output a webgl-functionnal app ?
     
  30. hardono

    hardono

    Joined:
    Oct 9, 2021
    Posts:
    4
  31. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    Strange....
    1st of all, nothing works when launching the index.html in local folder. It has to be on a server...

    2nd, when using gzip, the .gz files contain another .GZ that is broken....

    This is quite weird....
     
  32. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    browser console shows these errors, so can search about those
    upload_2021-10-12_14-42-7.png
     
  33. hardono

    hardono

    Joined:
    Oct 9, 2021
    Posts:
    4
    But I can build and run to Windows though... weird right?
     
  34. hardono

    hardono

    Joined:
    Oct 9, 2021
    Posts:
    4
    Thanks everyone. After re-checking everything again, the problem was caused by build.data.br not having the correct content-encoding
     
  35. giusti

    giusti

    Joined:
    Sep 15, 2019
    Posts:
    5
    Changing the compression in Edit -> Project Settings -> Player -> Publishing Settings to Disabled got it to work.
    Thank you bobbaluba!
     
    bobbaluba likes this.
  36. OliX_GC

    OliX_GC

    Joined:
    Jan 1, 2022
    Posts:
    2
    I am in the same problem.
     
  37. elliemary

    elliemary

    Joined:
    Jan 27, 2022
    Posts:
    1
    It's years later but I just wanted to shout out that the compression format = disabled worked for me. I'm hosting the files in s3 and embedding in weebly
     
  38. russisunni

    russisunni

    Joined:
    Oct 26, 2019
    Posts:
    8
    I think compression needs to be disabled in the Player->Publishing Settings.
     
    OhmVoraphob and andrlz like this.
  39. hidden13isme

    hidden13isme

    Joined:
    Aug 29, 2022
    Posts:
    2
    This is also the case for me. My 2D game won't load in the local browser, but my 3D game will. Not sure what's going on.
     
  40. jcdeleon141

    jcdeleon141

    Joined:
    Dec 6, 2019
    Posts:
    1
    I got mine working by simply turning on Decompression Fallback. That is all I did, the rest are default settings (untouched)
     
    reinfeldx likes this.
  41. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    164
    Confirming that I just had the same result with this approach. I was getting a dark gray screen when I uploaded my initial HTML build to itch.io. Toggling on Decompression Fallback solved the problem.
     
  42. joelsours

    joelsours

    Joined:
    Apr 4, 2021
    Posts:
    1
    I was having trouble, but this thread fix it thx's
     
  43. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    Hilarious that the default setup for a unity 2021 LTS after swapping to the webGL target is unable to run because of this problem. With the build-in build-and-run option.
     
  44. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    For anyone having similar problems with WebGL, I assure you that long-term you're better off running an active web server (e.g. express.js) that serves that content. This costs you, ofc, depends on what you're after.
    If you have a small project, no addressables, limited connectivity, you could get away with it.
    You have incredible control over caching, headers, compression etc. Took me like 2-3 weeks to fully master front-end stuff, since I'm not a web dev myself, but it really paid off
     
  45. TiieuTiien

    TiieuTiien

    Joined:
    Aug 16, 2023
    Posts:
    1
    Thank you it helps me alottttt
     
    xucian likes this.
  46. MatrixNew

    MatrixNew

    Joined:
    Apr 16, 2020
    Posts:
    80

    Thx!!
     
    reinfeldx likes this.
  47. ankitrajdwivedi01

    ankitrajdwivedi01

    Joined:
    Aug 29, 2023
    Posts:
    5
    Follow these simple steps to run unity webgl game locally.
    1. Install python server in your local machine.
    2. Build your project from unity.
    3. Navigate to your build folder
    4. open cmd in current directory.
    5. Run command for windows user : > python -m http.server and > python3 -m http.server on Mac.
    6. It shows the port number.
    7. Open any browser in your system and type localhost: portNumber in my case it is localhost:8000 hit enter your game will run locally.
     
    xucian and reinfeldx like this.
  48. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    164
    This is a great tip. Thanks!
     
  49. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    I can attest to this, been using it for years for literally everything as a fallback when I wanted to start a web server, either a website-like, or simply transferring files, usually involving one windows device (on unix you'd use scp or the like)
     
    reinfeldx likes this.