From f5c3cb9145c267fabb679f273347fe4527cdbdbf Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Wed, 20 May 2026 20:36:39 -0700 Subject: [PATCH] Resume AudioContext on visibilitychange to fix SFX on mobile after tab switch --- game.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/game.js b/game.js index 6f1b069..3be3880 100644 --- a/game.js +++ b/game.js @@ -120,6 +120,13 @@ const SFX = (() => { return ctx; } + /* Resume AudioContext when user returns to the page on mobile */ + document.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') { + ctx.resume(); + } + }); + /* Core: play a tone with envelope */ function tone(freq, type, vol, attack, sustain, release, when) { const c = getCtx();