I have a Unity project (2019.1.11f1)
I’ve just generated the build for WebGL with no thread support 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:
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:
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.
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 .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.
@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.
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]( https://discussions.unity.com/t/774290 page-3#post-9059386) 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())