Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebGL Hanging on Firebase-hosted webapp with 2020.3

Discussion in 'Web' started by ferretnt, Mar 17, 2021.

  1. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Hi,

    We have a fairly complex WebGL app, which hangs on load with 2020.3.0f1 (works fine with 2019.4.) *only* when we deploy our files to Firebase hosting. When the build loads and is launched directly in chrome by unity (i.e. connection to localhost:xxxxx) everything loads and runs correctly.

    As soon as we deploy to firebase hosting and access [appname].web/app, the app hangs forever with the loading progress bar (we're using the default Unity WebGLTemplate) 90% complete.

    Strangely, the same WebGL project built as a debug build in 2020 works fine...

    I will try to provide more info, but WebGL builds take a long time to make, so it's easier to post this and then iterate in parallel making builds on a spare machine in the hope we find something, however the primary symptoms seem to be:

    2019: Works
    2020LTS-DevelopmentBuild: Works
    2020LTS-Release: Broken

    We don't see any output in chrome debug console other than:

    WebGLMacRelease.loader.js:1 [Deprecation] SharedArrayBuffer will require cross-origin isolation as of M91, around May 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details.
    (anonymous) @ WebGLMacRelease.loader.js:1
    /WebGLMacRelease/Bui…e.framework.js.gz:1 Uncaught SyntaxError: Invalid or unexpected token
    WebGLMacRelease.loader.js:1 Uncaught ReferenceError: unityFramework is not defined
    at HTMLScriptElement.r.onload (WebGLMacRelease.loader.js:1)
    WebGLMacRelease.loader.js:1 [UnityCache] 'https://[foo].web.app/WebGLMacRelease/Build/WebGLMacRelease.data.gz' successfully downloaded and stored in the indexedDB cache
     
  2. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Apologies, I can confirm that enabling decompression fallback results in builds that work (we're using gzip), however I can't seem to find a single example on the internet of somebody setting up firebase hosting to do this (which is mildly concerning...)

    Adding this in firebase.json didn't seem to be sufficient, to my surprise. If anyone has previously done this, I'd be grateful to know.

    Code (CSharp):
    1. {
    2.   "hosting": {
    3.     "public": "public",
    4.     "ignore": [
    5.       "firebase.json",
    6.       "**/.*",
    7.       "**/node_modules/**"
    8.     ]
    9.   },
    10.     "headers": [
    11.     {
    12.       "source": "**/*.gz",
    13.       "headers": [
    14.         {
    15.           "key": "Content-Encoding",
    16.           "value": "gzip"
    17.         }
    18.       ]
    19.     }
    20.   ]
    21. }
     
  3. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Further googling seems to imply that firebase GZips static files by default. Is that the problem, and actually the easiest solution is to disable compression entirely in the unity build and upload an uncompressed build to firebase, which will then gzip and serve? Or am I completely off base?

    (Sorry, long-time game developer desperately trying to understand web-tech...)
     
  4. TallJohn

    TallJohn

    Joined:
    Dec 3, 2019
    Posts:
    12
    Yes that is it exactly. I came at it being new to web-tech too so totally understand the challenges.

    I found it was very easy to get started with Firebase Hosting with non-compressed builds. However it is too expensive to host a game on Firebase Hosting in the long run if you have a lot of traffic.
     
  5. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Thanks for your thoughts TallJohn. Hosting cost isn't a problem for us as our users are very high value.

    The complete absence of technically detailed answers both here and on the Firebase forums says a lot though.
     
    Vixxd likes this.
  6. modegames

    modegames

    Joined:
    Dec 1, 2014
    Posts:
    37
    Keen to hear of any alternative solutions for hosting games on Firebase.

    I agree, I also believe that gzip is happening on the Firebase end. So you don't need the Unity option, but I could be wrong. You can also use data caching to reduce downloads and split up your assets with asset bundles.

    There is this page, this has been useful for us when hosting through other providers, as you need to be able to manage server settings with .htaccess files etc.
    https://docs.unity3d.com/Manual/webgl-server-configuration-code-samples.html