Hi, I was wondering, is it any way to detect browsers page reload?
I’d like to save some level data before it happens.
Your best bet is to save periodically and to let the player know to exit to the main menu in the game to ensure the game saves or to press a save button before leaving.
If you are willing to show the user a browser level warning dialog before leaving your game that can be used to prevent closing before saving in some situations. You only want to do that once if you do it at all.
Then you can use this to communicate the event to save
Using https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload only might work to let the game save without displaying a popup, you would need to test.
2 Likes