Search Unity

Your browser does not support WebAssembly Threads.

Discussion in 'Web' started by perplex_bcn, Jul 25, 2019.

  1. perplex_bcn

    perplex_bcn

    Joined:
    Mar 1, 2013
    Posts:
    22
    Hi,

    I have a Unity project (2019.1.11f1)
    I've just generated the build for WebGL with no thread support
    Code (CSharp):
    1. PlayerSettings.WebGL.threadsSupport = false;
    However when trying load the build on Firefox, I see a dialog box showing the message: Your browser does not support WebAssembly Threads. So, the loading of the build is aborted.

    Digging into the UnityLoader.js file and inspecting the web page I realised that some conditional evaluations are wrong.
    At some point in the code you find:
    Code (CSharp):
    1. if(e.multithreading&&!UnityLoader.SystemInfo.hasWasmThreads)return void t("Your browser does not support WebAssembly Threads.");
    Inspecting the values in the web console we have the following:
    - !UnityLoader.SystemInfo.hasWasmThreads is boolean and evaluated as true
    - e.multithreading is a string and is evaluated as "false"
    - Finally, e.multithreading&&!UnityLoader.SystemInfo.hasWasmThreads is evaluated as true and the dialog box is shown.

    The way to avoid this behavior is replacing e.multithreading by e.multithreading=="true"

    Also found something similar earlier in the code:
    Code (JavaScript):
    1. n()?!UnityLoader.SystemInfo.hasThreads&&e.multithreading?r("Your browser does not support multithreading."):t()
    Just in case someone has the same problem. Will also report a bug.

    Regards.
     
  2. deus0

    deus0

    Joined:
    May 12, 2015
    Posts:
    256
    2020 this is still here? Was getting the error in fitefox. Will try this fix thank you :)
     
  3. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    It seems the issue is somewhere deeper, at least in 2020.1.0 (the most recent version I know to allow me to build with "PlayerSettings.WebGL.threadsSupport=true").
    In <ProjectName>.loader.js, the "u.SystemInfo.hasThreads" seems to return false on all browsers, and even if I remove that check manually, I then get "Current environment does not support SharedArrayBuffer, pthreads are not available".
    All my browsers are at latest versions, and I even tried enabling "Experimental WebAssembly" or "WebAssembly baseline compiler" in chrome (via about://flags). No result.
     
  4. wewear

    wewear

    Joined:
    Oct 18, 2021
    Posts:
    3
    Anyone solved this? I tried on 2022.2 Beta and still the same problem
     
    havokentity likes this.
  5. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    175
    A requirement for SharedArrayBuffers an multithreading to work is that your HTTP server has correct COOP and COEP, CORS headers setup.

    For local development an easy way is opening up a terminal, navigating to your build's folder and run this:

    Code (csharp):
    1. npx statikk --port 8000 --coi
    Afterwards you can navigate to http://localhost:8000 in your browser.

    You have to install node first (comes with npx).

    hth
     
    OmarVector likes this.
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    @tteneder's post is correct. In order to launch a web page that has been built with Native Multithreading enabled, one will need to configure the web server to provide the necessary site isolation headers COOP, COEP and CORP.

    These headers tell the browser how sensitive the data on a web page are, and how they should be treated with respect to possible Spectre and Meltdown family of vulnerabilities that multithreaded web pages potentially enable.

    The COOP, COEP and CORP headers are different from CORS, but similar in spirit.

    For more information on CORP, see https://resourcepolicy.fyi/ for more info on CORP.
    For more information on COOP and COEP, see https://docs.google.com/document/d/1zDlfvfTJ_9e8Jdc8ehuV4zMEu9ySMCiTGMS9y0GU92k/edit

    All browsers (Chromium-based, Firefox and Safari) readily support these headers.
     
    atteneder likes this.
  7. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    I have to catch up with the latest changes in Unity, but do we now support "real" threads in webgl? Last time I checked, there was only this hack, which I'm still using, and it was mostly for making async code compatible -- it still blocked and we had to be careful with not forcing an async to run sync (i.e.
    GetAwaiter().GetResult()
    )