PuzzleScript icon indicating copy to clipboard operation
PuzzleScript copied to clipboard

On startup query string may execute before all files loaded, and then crash

Open david-pfx opened this issue 1 year ago • 2 comments

The startup code in editor.js looks like this:

var fileToOpen=getParameterByName("demo");
if (fileToOpen!==null&&fileToOpen.length>0) {
	tryLoadFile(fileToOpen);
	code.value = "loading...";
} else {

It is possible for the query string to execute and try to load the file before all the JS files are loaded, causing a crash. The solution is simple. https://stackoverflow.com/a/11258137/1105562

window.addEventListener('load', function() {
    // your code here
})

I've checked it out and it works.

david-pfx avatar May 05 '23 00:05 david-pfx

good catch, thanks. Note to future, bug-fixing self: check you don't need to reduplicate this fix in the player

increpare avatar May 05 '23 09:05 increpare

I was able to reproduce it easily running locally: http://localhost:8000/src/editor.html?demo=sokoban

It's likely to turn up in other places, so it's going to need some thought where the fix should go. I can't PR that, so over to you!

david-pfx avatar May 06 '23 03:05 david-pfx

I looked into this, but I'm having trouble reproducing it. I've tried in private mode, both hosting locally and on puzzlescript.net, force refresh, different browsers. I wonder if there are some tools that might let me slow down the serving of specific files.

@david-pfx Can you remember what browser/operating system (including versions) you were using to produce this behaviour?

( Also: A note to myself to check the ready-state in addition to hooking up the event handler - https://stackoverflow.com/questions/13364613/how-to-know-if-window-load-event-was-fired-already )

increpare avatar Apr 27 '24 08:04 increpare

I mostly use the .bat file to run locally and (latest) Chrome for testing.

david-pfx avatar Apr 27 '24 09:04 david-pfx

Note to future self: I can consistently reproduce it on Chrome on MacOS, only in the src build (the compiled version compiles everything to a single js file, so won't exhibit this error), by opening up the network tools and turning on bandwidth throttling, but not deactivating the cash, and reloading.

Bildschirmfoto 2024-04-27 um 16 16 38

increpare avatar Apr 27 '24 14:04 increpare