From 0c76b200cc68c59772df930acd34a58bd6272c7f Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sat, 7 Feb 2026 13:10:27 +0100 Subject: Catch rejected play() promises from browser autoplay policy Browsers reject .play() with a DOMException when the user hasn't interacted with the document yet. Add .catch(() => {}) to all 9 play() call sites to suppress the uncaught promise rejection. Co-Authored-By: Claude Opus 4.6 --- webAO/packets/handlers/handleMC.ts | 2 +- webAO/packets/handlers/handleRMC.ts | 2 +- webAO/packets/handlers/handleZZ.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleMC.ts b/webAO/packets/handlers/handleMC.ts index 8a1c0a2..44237ea 100644 --- a/webAO/packets/handlers/handleMC.ts +++ b/webAO/packets/handlers/handleMC.ts @@ -24,7 +24,7 @@ export const handleMC = (args: string[]) => { music.src = `${AO_HOST}sounds/music/${encodeURI(track.toLowerCase())}`; } music.loop = looping; - music.play(); + music.play().catch(() => {}); try { musicname = client.chars[charID].name; diff --git a/webAO/packets/handlers/handleRMC.ts b/webAO/packets/handlers/handleRMC.ts index 7758844..0cc6aa7 100644 --- a/webAO/packets/handlers/handleRMC.ts +++ b/webAO/packets/handlers/handleRMC.ts @@ -17,7 +17,7 @@ export const handleRMC = (args: string[]) => { music.currentTime += parseFloat( music.totime + (new Date().getTime() / 1000 - music.offset), ).toFixed(3); - music.play(); + music.play().catch(() => {}); }, false, ); diff --git a/webAO/packets/handlers/handleZZ.ts b/webAO/packets/handlers/handleZZ.ts index 31ceef5..0496d42 100644 --- a/webAO/packets/handlers/handleZZ.ts +++ b/webAO/packets/handlers/handleZZ.ts @@ -18,6 +18,6 @@ export const handleZZ = (args: string[]) => { const oldvolume = client.viewport.getSfxAudio().volume; client.viewport.getSfxAudio().volume = 1; client.viewport.getSfxAudio().src = `${AO_HOST}sounds/general/sfx-gallery.opus`; - client.viewport.getSfxAudio().play(); + client.viewport.getSfxAudio().play().catch(() => {}); client.viewport.getSfxAudio().volume = oldvolume; }; -- cgit