HTML5 Problem with http requests

Marko03970

Member
Hello everyone,
I have a problem with http_get function. When I try to save the information on the server using http_get, the screen just turns in black. I did some research and as I can see it could be because of browser "XSS protection".Also, I found that it can be avoided by setting the header, so I added it on the server-side.
1602978611936.png
I made a server in javascript and I put it on mthe host to save the account details. Even I added this on the server-side, error occurs.

And yeah, everything is working well when I run the game on windows platform, but when I run it in browser, I'm getting this error.

Hope someone will know the solution, thanks.
 

FrostyCat

Member
Turn on your browser's developer tools and make sure it's actually about CORS headers. Other things can still block the request, for example making requests in plain HTTP while the page is served off HTTPS, or an unrelated crash in the engine.
 

Marko03970

Member
Yeah, I tried with developers too. This is what I'm getting there:
_Te: "Unhandled Exception - Uncaught { message : "trying to index variable which is not an array", longMessage : "trying to index variable which is not an array", stacktrace : [ "function _xM("trying to index variable which is not an array")↵", "function _tg(0, "31@1@")↵", "function _kh([instance], [instance], 285)↵", "function _F4([instance], [instance])↵", "function(769, 0, [instance], [instance])↵", "function(769, 0, [instance], [instance])↵", "function(769, 0)↵", "function _hC3()↵", "function _PB3()↵", "function _nB3(29864.07)↵" ], script : "", line : -1 } in file undefined at line undefined"
Maybe the problem is in the indexing variable that is not an array, but I'm not sure where is that array, because it's all working when running on the Windows platform.
 

FrostyCat

Member
The HTML5 export in 2.3.0 is quite poorly made and had numerous unexpected issues like this. You can get a better view where it comes from by running in debug mode (F6 from the IDE), but that won't fix it.
 

Marko03970

Member
Okay run the debugger on windows, and when I save information on the server, and when I restart the game and load everything. Then when I save it again it's all working well, but when I try to load for the second time I got this in the output: HttpError:HttpSendRequest: The operation timed out. Then I can click again the load button and everything is working but only second time it's not working. The same thing is on the browser, first-time everything is working both save and load, but when loaded and when I try to save again, a black screen occurs.
 

FrostyCat

Member
When I run it in debugger mode it's not opening (debugger). Did you mean to run debugger while testing on the windows platform or?
The IDE debugger does not work with the HTML5 export. You run with the target set to HTML5 and using the debug button (F6), then bring up the developer's tools in your browser.
 

FrostyCat

Member
That error no longer has anything to do with HTTP requests. It is telling you that in obj_player's Step event, a call to inventory_get_amount(205) is trying to index off something that isn't an array. Check the contents of that variable for potential omissions.
 

Marko03970

Member
Yeah, I added if (is_array) check in this function before using an array and now everything is working. It's nice that it is working, but why should I check if the variable is array when I know that I'm using this function on places where this array is already created 🤔 (for example, on windows this function was working well without any changes.)
 

Marko03970

Member
On browser everything is working, but there is still http error on windows. When I want to load info for second time (sometimes not second, then third time), it takes about 10 seconds (instead of one second as usually) and then everything is loaded. In console I'm getting this:
1603037969276.png
After that, whenever I use game_restart and press "continue" button, it's loading normally. Just this second/third time it's loading longer.Could it befixed, or it's because of server speed etc.?
 

FrostyCat

Member
Well then you need to inspect your server, and perhaps test it locally before deploying it to a live server.

In any case, when HTTP requests are involved, you always need to assume that something may go wrong. Have procedures in your code's off hand for when that happens.
 
Top