fix(audio): handle Howler race condition and add debug mode#276
Merged
fix(audio): handle Howler race condition and add debug mode#276
Conversation
- Wrap Howler calls in try-catch to handle race conditions - Add URL debug mode (?debug=media) for prod troubleshooting - Enhance Media Session logging for position updates - Fix: seek bar stuck at end on Android lock screen Closes #275
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition in Howler.js that caused Android lock screen seek bars to display incorrect positions, and adds a production-friendly URL-based debug mode for troubleshooting.
Key Changes:
- Wrapped Howler API calls in try-catch to handle race conditions during track switching
- Implemented URL parameter debug mode (?debug=media, ?debug=audio, etc.) with sessionStorage persistence
- Enhanced Media Session logging with detailed position updates for debugging
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
frontend/src/lib/logger-client.ts |
Added URL-based debug mode with filter support and sessionStorage persistence for production debugging |
frontend/src/lib/audio/player.ts |
Added try-catch around Howler calls, eliminated double duration() call, added isFinite() validation, graceful fallback on errors |
frontend/src/lib/audio/media-session.ts |
Enhanced position state logging with percentage display, added invalid input logging, upgraded error logs to warn level |
…performance (avoid repeated sessionStorage access) - Use pendingSeek as currentTime fallback in catch block - Simplify null/all filter logic in debug mode - Update media-session comment about sessionStorage persistence - Add debug mode tests
- Check isDev first before getDebugMode() to avoid unnecessary calls - Add isLoading/isPlaying explicit fallbacks in catch block - Use raw numbers instead of toFixed() in logging (avoid string alloc) - Document cache invalidation behavior in code comments
…ry-catch - Extract IIFE pattern into shouldShowInConsole() helper function - Reduce code duplication across 4 debug/info methods - Wrap howl.state() in try-catch to prevent logging from failing - Update comments for accuracy (cache behavior, SPA context)
- Move window undefined check before cache check to avoid SSR cache pollution - Move howl.state() call inside try block and reuse result for isLoading
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix Android lock screen seek bar stuck at end position, and add URL-based debug mode for production troubleshooting.
Closes #275
Changes
1. Fix Howler.js race condition (
player.ts)getState()with try-catchhowl.duration()only once and reuse result (avoid double-call race)isFinite()validation for all returned valuesisLoading/isPlayingfallbacks in catch block2. Add URL debug mode (
logger-client.ts)Enable verbose logging in production without redeploying:
?debug=1?debug=media[MediaSession]logs?debug=audio[Audio]logs?debug=0Settings persist in
sessionStoragefor current tab session. Result is cached once per page load for performance.3. Enhance Media Session logging (
media-session.ts)Root Cause
The
syncInterval(500ms) callsaudioPlayer.getState(), which accesseshowl.duration(id). During track switching, Howler's internal_soundsarray may be empty, causing the error.Testing
npm test- all 414 tests passhttps://m3w.test3207.fun/?debug=mediaChecklist