feat: save-on-pause via visibilitychange and beforeunload (#57) #69
Reference in New Issue
Block a user
Delete Branch "polish"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Auto-save game state when the browser tab is hidden or closed, preventing data loss on mobile.
How
Two event listeners added to
js/main.js:visibilitychange— saves whendocument.hiddenbecomes true (tab switch, minimize, app switch)beforeunload— saves when the user navigates away or closes the tab/windowBoth call the existing
saveGame()function, which persists tolocalStorageviathe-beacon-v2.Why
On mobile, switching apps or letting the screen sleep can kill the page before the 30-second auto-save interval fires. These two listeners cover the gap:
visibilitychangecatches tab switches and app switchesbeforeunloadcatches page closes and hard navigationsEpic
Part of #57 Night of Polish — Task 6: Mobile Polish
Testing
main.jsloads without syntax errors