feat: save-on-pause via visibilitychange and beforeunload (#57) #69

Merged
Timmy merged 1 commits from polish into main 2026-04-11 21:44:31 +00:00
Owner

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:

  1. visibilitychange — saves when document.hidden becomes true (tab switch, minimize, app switch)
  2. beforeunload — saves when the user navigates away or closes the tab/window

Both call the existing saveGame() function, which persists to localStorage via the-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:

  • visibilitychange catches tab switches and app switches
  • beforeunload catches page closes and hard navigations

Epic

Part of #57 Night of Polish — Task 6: Mobile Polish

  • Save-on-pause (visibility change event)

Testing

  • main.js loads without syntax errors
  • Bracket balance verified
  • Both listeners present and correctly wired
## 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`: 1. **`visibilitychange`** — saves when `document.hidden` becomes true (tab switch, minimize, app switch) 2. **`beforeunload`** — saves when the user navigates away or closes the tab/window Both call the existing `saveGame()` function, which persists to `localStorage` via `the-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: - `visibilitychange` catches tab switches and app switches - `beforeunload` catches page closes and hard navigations ## Epic Part of **#57 Night of Polish** — Task 6: Mobile Polish - ✅ Save-on-pause (visibility change event) ## Testing - [x] `main.js` loads without syntax errors - [x] Bracket balance verified - [x] Both listeners present and correctly wired
Timmy added 1 commit 2026-04-11 21:21:36 +00:00
feat: save-on-pause via visibilitychange and beforeunload (#57)
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s
2507a31ef2
Auto-save game state when the browser tab is hidden (visibilitychange)
or closed/navigated away (beforeunload). Prevents data loss on mobile
where tab switching can kill the page without a save interval firing.

Part of epic #57 Night of Polish — Task 6: Mobile Polish.
Timmy merged commit 4d902d48d0 into main 2026-04-11 21:44:31 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Timmy_Foundation/the-beacon#69