-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: add warning when media.play() fails in bind:paused #17656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add warning when media.play() fails in bind:paused #17656
Conversation
🦋 Changeset detectedLatest commit: 6acbd90 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| media.play().catch(() => { | ||
| set((paused = true)); | ||
|
|
||
| if (DEV) { | ||
| w.media_play_failed(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we just did this instead? It saves us guessing about the cause and delegates to the browser
| media.play().catch(() => { | |
| set((paused = true)); | |
| if (DEV) { | |
| w.media_play_failed(); | |
| } | |
| media.play().catch((error) => { | |
| set((paused = true)); | |
| throw error; |
| 'svelte': patch | ||
| --- | ||
|
|
||
| ired changeset? (Y/n) · y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😁
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:. (Title:feat: add warning when media.play() is blocked by autoplay)packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lintDescription
This PR addresses the issue of silent failures when browser autoplay policies block media playback triggered via
bind:paused.Problems Solved:
When a developer uses
bind:paused={false}to programmatically start a video or audio element, modern browsers often block this request if it doesn't follow a user interaction or includes sound. Currently, Svelte catches the error and resets the state topaused = true, but it does so silently. This makes it difficult for developers to debug why their media isn't playing.Changes:
media_play_failedto the client-side warning system.bind_pausedlogic inmedia.jsto catch theplay()rejection and emit a descriptive warning in Development Mode.patchchangeset for thesveltepackage.Verification:
pnpm buildinpackages/svelteto ensurewarnings.jsand documentation are correctly regenerated.DEVmode to avoid production overhead.pnpm lintto ensure no formatting or import issues were introduced.