I have a kit that connects to a website and stores the cookies the website sends in response to logging in.
On some platforms I have to send the cookie back each time I call WWW while on other platforms it seems they use Session data instead. On all platforms, though, I scan for one particular cookie to validate login was successful.
Okay, background info out of the way…
The web player, was the exception to the rule as it did not allow me to SEND any custom cookies. I honestly have no idea how the web player worked but what I do know is that whenI logged in to the website, the webplayer got the cookies it was supposed to and, even though I never sent any header info with my WWW calls, the web player always behaved like the other platforms, as if I HAD sent the header info. The web player was a mystery to me…
Now comes WebGL and I am completely baffled even more. Now I AM allowed to send header info but it seems the player doesn’t receive any of the cookies the website sends out. According the documentation the server needs to send out certain headers and I modified my script to send out the example ones from the docs that allow access from anywhere. While testing my kit on other platforms (or to be precise, testing the WebGL build in the editor) I can clearly see the cookies and headers are being sent back to me including everything that I expect to see…
Then I build the project and when I run the project I get hardly any cookies at all. All I get are the “You have to verify each time” cookie and all the ones from the documentation and all the others the webpage sent out are all missing / never reach the game…
What’s the deal? How do I get a WebGL game to receive the headers that is sent to it?
I read in the documentation something that suggests WebGL games can only receive a certain set of headers and nothing else. Did I read that correctly? Does this mean that WebGL games cannot now (or will ever) be allowed to receive custom headers from WWW responses???
This isa rather urgent matter for me to solve so if anyone has any info I would be most grateful. Thanks
CORS is used when you access a server different from the one hosting the page. If you need more headers, you need to be hosted on the same server you are contacting.
This is a security restriction imposed by the browsers and will (most likely) not change in the future.
Notice that wether I comment the code out like above or not doesn’t make a difference. If I do a Build And Run Safari opens Localhost with a port and all I get is a “localhost was not found” error. Now if I browse to the folder where the built project was placed and double click the index.html so it loads in my browser as file:/// then it loads in Safari and Firefox just fine and both of them call localhost to connect and it works just fine… except for the fact that I don’t get the headers…
Actually, I am going to have to recant this entire post… let me start fresh:
I build the project to login via localhost. I hit Build and Run and Safari tries to open it with url localhost:[some port] but gets a response that localhost does not exist. If I open that same web page NOT from localhost but from the folder directly, it loads but doesn’t receive the headers.
I build the project to work from www.guild.site and I upload the project to www.guild.site/WebGLTest/. When I try to open index.html I get a “loading data from” message in my status bar, I can see the source code of index.html in my browser when I click on view source BUT forget about my kit not logging on, I can’t even see my project… The WebGL player simply does not appear at all so I have no idea wether my kit works or not because I can’t see the WebGL player…
I build the kit like 2 above but I run it from my local system by double clicking the file. Note that guild.site does not have those headers commented out and ARE actually returning them when I use my kit. Now, when I run the game from my local folder it loads the player just fine. When I click on the button to connect, it connects to www.guild.site but receives almost no headers or cookies even though I have those headers enabled that allow access from anywhere… ‘Access-Control-Allow-Origin: *’
I uploaded the entire folder as is, non development build, both compressed and release folders, everything exactly as it is locally… but nothing… Any ideas what I am doing wrong?
Thanks for that. Just noticed Safari throwing me 3 errors along those lines only on the JS files.
I renamed the .htaccess file to disable it and now I no longer get the error but I guess I now have to wait for 20Mb download to complete to see if anything is happening…
Anyway, this is a problem for Saturday. Gonna have to figure out what the secret is to getting WebGL projects to show up cause the files are there… but it is not being acknowledged as such… All I can think of is the .htaccess file blocking them somehow…
Thanks for the heads up on that…
Edit:
Full disclosure… I think I uploaded the wrong project… FacePalm… Still not sure why it doesn’t show up or do anything BUT I just tried running the other project from my HDD, accessing the login on guild.site and it worked perfectly… So not from the website, not from localhost, just from the folder where the files were generated… Double clicked and the project loaded in Safari. I clicked on login and received all the headers and cookies I expected! Now uploading to the website and see if it will continue to work… Fingers crossed
So I finally figured out how to get the project to load… finally! Turns out I need to merge the .htaccess file with the one I already use on my website…
Still experiencing some issues, though:
There is no loading screen. Wonder if that is because I chose the minimal build option? Would have thought there would always be a default loading bar, though. Replaceable but at least there by default…
My site is not returning the compressed version but the release version
Still have to test this again now but I was getting that error you mentioned in another thread as being due to browsers cache settings. As per your instructions in that thread I turned cache-ing off in my player settings.
“Nothing happening” and “Just wait for the 35Mb to download without a progress indicator”… might have gotten those two confused…
At least the good news is that with those 4 headers from the documentation added to my script it does solve the main issue of this thread, though. I am able to fetch all my headers and cookies as I would expect to from any platform. I can even do so from outside the domain. So my main issue is solved.