Skip to content

Fix WKWebview AudioContext "zombie" state in visibility change#2888

Open
GuoLei1990 wants to merge 3 commits intogalacean:dev/2.0from
GuoLei1990:fix/ios-audio
Open

Fix WKWebview AudioContext "zombie" state in visibility change#2888
GuoLei1990 wants to merge 3 commits intogalacean:dev/2.0from
GuoLei1990:fix/ios-audio

Conversation

@GuoLei1990
Copy link
Member

@GuoLei1990 GuoLei1990 commented Feb 3, 2026

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix

What is the current behavior? (You can also link to an open issue here)
On iOS WKWebView, when the app switches to background and returns to foreground, AudioContext may be in a "zombie" state — state reports "suspended", but calling resume() alone won't restart audio rendering.

What is the new behavior (if this is a feature change)?
When visibilitychange event detects audio needs to be resumed, call suspend() first to force reset the AudioContext internal state, then trigger resume() via user gesture to ensure audio recovers correctly.

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
No

Other information:
This is a known WebKit bug where AudioContext may enter a state where state appears normal but currentTime stops incrementing after returning from background. Calling suspend() first forces a clean internal state reset, which is a common workaround adopted by other audio libraries (PlayCanvas, Tone.js, etc.).

Related: https://bugs.webkit.org/show_bug.cgi?id=263627

Summary by CodeRabbit

  • Bug Fixes
    • Fixed audio playback issues on iOS WebKit browsers when resuming from suspended state

@coderabbitai
Copy link

coderabbitai bot commented Feb 3, 2026

Walkthrough

A bug fix for AudioManager that adds a call to suspend() within the visibility change handler on iOS WKWebView. When the document becomes visible with audio playing but the context not running, suspend is invoked to reset internal state before potential user gesture-triggered resume.

Changes

Cohort / File(s) Summary
AudioManager Bug Fix
packages/core/src/audio/AudioManager.ts
Added conditional call to suspend() inside _onVisibilityChange to work around iOS WKWebView WebKit bug, resetting internal state when visibility changes and audio is active but context is inactive.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A hop through WebKit's tangled code,
When visibility shifts down the road,
Suspend and reset, state made clean,
iOS bugs now caught in between,
Audio flows like carrots so fine! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly describes the main change: fixing a WKWebView AudioContext 'zombie' state issue during visibility changes, which matches the changeset's addition of suspend() call in _onVisibilityChange.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@GuoLei1990 GuoLei1990 requested a review from luzhuang February 3, 2026 07:04
@GuoLei1990 GuoLei1990 added Audio bug Something isn't working labels Feb 3, 2026
@GuoLei1990 GuoLei1990 self-assigned this Feb 3, 2026
@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.21%. Comparing base (d68166b) to head (63e709a).

Files with missing lines Patch % Lines
packages/core/src/audio/AudioManager.ts 0.00% 5 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           dev/2.0    #2888      +/-   ##
===========================================
+ Coverage    83.03%   83.21%   +0.17%     
===========================================
  Files          796      796              
  Lines        90449    90454       +5     
  Branches      9503     9497       -6     
===========================================
+ Hits         75107    75271     +164     
+ Misses       15260    15101     -159     
  Partials        82       82              
Flag Coverage Δ
unittests 83.21% <0.00%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GuoLei1990 GuoLei1990 changed the title Fix handle iOS Safari AudioContext "zombie" state in visibility change Fix WKWebviw Safari AudioContext "zombie" state in visibility change Feb 3, 2026
@GuoLei1990 GuoLei1990 changed the title Fix WKWebviw Safari AudioContext "zombie" state in visibility change Fix WKWebview AudioContext "zombie" state in visibility change Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Audio bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant