Bug Report: Unhandled audio.play() Promise Rejection Causes Silent Playback Failure
Description
The music player JavaScript calls audio.play() to start playback. In all
modern browsers, audio.play() returns a Promise that is rejected when the
browser's autoplay policy blocks playback (which happens for any page loaded
without prior user interaction). Without a .catch() handler, the rejection
becomes an unhandled promise rejection, and the user sees no error message,
spinner state, or indication that playback failed.
Steps to Reproduce
- Open
http://localhost:8000/ in Chrome or Firefox without any prior interaction.
- Click the play button.
- If autoplay is blocked, the play button appears to "work" but no audio plays.
- Check the browser console:
Uncaught (in promise) DOMException: play() failed.
Root Cause
audio.play(); // Missing .catch()
audio.play() returns a Promise. Without .catch(), any rejection
(autoplay policy, unsupported codec, network error) is swallowed silently.
Impact
Users on browsers with strict autoplay policies (all major browsers by default)
receive no feedback when playback fails, making the app appear broken.
Proposed Fix
Handle the rejection and show user feedback:
const playPromise = audio.play();
if (playPromise !== undefined) {
playPromise
.then(() => { updatePlayButton(true); })
.catch(err => {
console.warn("Playback failed:", err.message);
updatePlayButton(false);
showToast("Click anywhere on the page to enable audio playback.");
});
}
Bug Report: Unhandled audio.play() Promise Rejection Causes Silent Playback Failure
Description
The music player JavaScript calls
audio.play()to start playback. In allmodern browsers,
audio.play()returns a Promise that is rejected when thebrowser's autoplay policy blocks playback (which happens for any page loaded
without prior user interaction). Without a
.catch()handler, the rejectionbecomes an unhandled promise rejection, and the user sees no error message,
spinner state, or indication that playback failed.
Steps to Reproduce
http://localhost:8000/in Chrome or Firefox without any prior interaction.Uncaught (in promise) DOMException: play() failed.Root Cause
audio.play()returns a Promise. Without.catch(), any rejection(autoplay policy, unsupported codec, network error) is swallowed silently.
Impact
Users on browsers with strict autoplay policies (all major browsers by default)
receive no feedback when playback fails, making the app appear broken.
Proposed Fix
Handle the rejection and show user feedback: