From 8c965dcfd9b678ffa7fa04d217f6dca0d6bd1041 Mon Sep 17 00:00:00 2001 From: Sterling Archer Date: Sun, 31 May 2026 14:10:23 -0700 Subject: [PATCH] Mobile Audio bug fix --- game.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/game.js b/game.js index 073f504..14a1b4e 100644 --- a/game.js +++ b/game.js @@ -2159,3 +2159,40 @@ class Game { } window.addEventListener('DOMContentLoaded',()=>{ new Game(); }); + +(function() { + const el = document.createElement('div'); + el.id = 'audio-debug'; + el.style.cssText = 'position:fixed;bottom:0;left:0;right:0;background:rgba(0,0,0,0.85);color:#0f0;font:11px monospace;padding:6px;z-index:99999;max-height:160px;overflow-y:auto;pointer-events:none;'; + document.body.appendChild(el); + function log(msg) { + const line = document.createElement('div'); + line.textContent = new Date().toISOString().slice(11,19) + ' ' + msg; + el.appendChild(line); + el.scrollTop = el.scrollHeight; + } + window._adlog = log; + + const OrigAC = window.AudioContext || window.webkitAudioContext; + const PatchedAC = function(...args) { + const instance = new OrigAC(...args); + log('AudioContext created, state=' + instance.state); + const origResume = instance.resume.bind(instance); + instance.resume = function() { + log('resume() called, state=' + instance.state); + return origResume().then(() => { log('resume() resolved, state=' + instance.state); }).catch(e => { log('resume() FAILED: ' + e); }); + }; + return instance; + }; + PatchedAC.prototype = OrigAC.prototype; + if (window.AudioContext) window.AudioContext = PatchedAC; + if (window.webkitAudioContext) window.webkitAudioContext = PatchedAC; + + ['touchstart','touchend','pointerdown','click'].forEach(ev => { + document.addEventListener(ev, () => { + log(ev + ' fired'); + }, { passive: true }); + }); + + log('Debug ready. iOS=' + /iP(hone|ad|od)/.test(navigator.userAgent)); +})();