Skip to content

fix(engine): defer AudioContext creation to first user gesture#3

Merged
saifulapm merged 1 commit into
mainfrom
fix/audiocontext-autoplay-warning
Apr 30, 2026
Merged

fix(engine): defer AudioContext creation to first user gesture#3
saifulapm merged 1 commit into
mainfrom
fix/audiocontext-autoplay-warning

Conversation

@saifulapm
Copy link
Copy Markdown
Contributor

@saifulapm saifulapm commented Apr 30, 2026

Summary

Closes #2.

tiks.init() constructed an AudioContext immediately, which trips Chrome's autoplay-policy warning (The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page) and leaves the context suspended. The first hover sound triggered via onPointerEnter then silently drops, because pointerenter is not a qualifying user gesture.

This change moves construction into the existing gesture-unlock listener so the AudioContext is born inside a real pointerdown / touchstart / mousedown / keydown event. The context comes up running, no warning fires, and post-gesture hovers play immediately.

Test plan

  • npm test — 70/70 pass
  • npm run typecheck — clean
  • npm run build — clean
  • Verified in Chrome and Safari

Constructing the AudioContext inside init() trips Chrome's autoplay-policy
warning ("AudioContext was not allowed to start") because init() typically
runs at module load, outside any user gesture. The context was then born
suspended, which silently dropped the very first sound — most visibly the
hover sound on pointerenter, which is not itself a qualifying gesture.

Move construction into the existing gesture-unlock path so the context
is created inside a real pointerdown / touchstart / mousedown / keydown.
The context comes up running and the next pointerenter plays as expected.
playSound bails silently when no context exists yet (no warning, no node).

Closes #2
@saifulapm saifulapm merged commit 638726d into main Apr 30, 2026
1 check passed
@saifulapm saifulapm deleted the fix/audiocontext-autoplay-warning branch April 30, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The AudioContext was not allowed to start.

1 participant