Game isn't loading in WebGL

Hopefully someone can assist me with this, I’ve been having this issue for almost three weeks now and it’s getting a bit frustrating.

I’m using an auth called keyauth for my game so that I can keep track of player stats, etc. I originally made a unity example using the auth (GitHub - KeyAuth/KeyAuth-Unity-Example) and it works for windows (mono and il2cpp), however when it comes to webgl, whenever I load the game it just doesn’t do anything… it freezes basically. If you view the link provided it’s basically that exact code expect for a few things, I removed all Threads, as well as Processes since I noticed that was causing an issue with il2cpp.

The main function that is causing it to mess up is the init function (from my auth) but I’m not sure why… I’m using WebClient to post data (upload values), and not sure if webgl is having an issue with WebClient and I need to use UnityWebRequest or what? I already tried to use RestClient and got the same error (just freezing)… any ideas at all??

I glanced over the code and noticed Environment.Exit() calls. Did a quick search, if you run this in a Unity app, it will essentially lock up . That could be the reason. Try replacing that with Application.Quit() so at least the program ends gracefully.

You said you removed “Threads and Processes” … that could also be causing issues. If the code was designed to run asynchronously, it’s often non-trivial to make it work single-threaded (which is the current state of WebGL: single-threading only, which would be the issues you experienced at first). Perhaps it’s trying to process a response that hasn’t returned yet, or it is waiting for a response indefinitely because no other thread is receiving the input. Though if it works on Windows as single-threaded it should generally also work on the Web.

Are you aware that you also have a Console in browsers? In Chrome it’s Ctrl+Shift+I and then the Console tab. You can use that to look up errors or sprinkle the code with Debug.Log statements as that can be quite helpful.

I removed all of the Environment.Exit() calls and just put Debug.Logs there instead to see if it was exiting at all.

The threads that I removed were only used to display a warning then after so many seconds it would just quit the application so I don’t think that could be causing the issue but I put Debug.Log there as well to see if it’s happening there possibly. The Process that I removed was “Process.GetCurrentProcess()”. I removed this because a member of Unity Technologies said that I could not use that in webgl because it wasn’t supported.

I’ve tried just about everything that I can think of and still end up getting the same result.

So, I switched methods, but now am getting this:
8413974--1112361--upload_2022-9-4_5-43-25.png

Code I’m using:

Unfortunately, CORS errors are a bit mysterious for someone new to web development. You might want to read these first:
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors
https://enable-cors.org/

If I understand correctly, it is possible that that web API does not set the header for requests from localhost.