Skip to content

Conversation

@MOHITKOURAV01
Copy link
Contributor

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:. (Title: feat: add warning when media.play() is blocked by autoplay)
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it. (Verified via internal build and message processing)
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Description

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 to paused = true, but it does so silently. This makes it difficult for developers to debug why their media isn't playing.

Changes:

  • New Warning: Added media_play_failed to the client-side warning system.
  • Improved Feedback: Updated the bind_paused logic in media.js to catch the play() rejection and emit a descriptive warning in Development Mode.
  • Documentation: Automatically updated the generated client-warnings reference documentation.
  • Changeset: Included a patch changeset for the svelte package.

Verification:

  • Ran pnpm build in packages/svelte to ensure warnings.js and documentation are correctly regenerated.
  • Verified that the logic only triggers in DEV mode to avoid production overhead.
  • Ran pnpm lint to ensure no formatting or import issues were introduced.

@changeset-bot
Copy link

changeset-bot bot commented Feb 8, 2026

🦋 Changeset detected

Latest commit: 6acbd90

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

@MOHITKOURAV01 MOHITKOURAV01 requested a deployment to Publish pkg.pr.new (external contributors) February 8, 2026 10:11 — with GitHub Actions Waiting
@svelte-docs-bot
Copy link

@MOHITKOURAV01 MOHITKOURAV01 requested a deployment to Publish pkg.pr.new (external contributors) February 8, 2026 10:15 — with GitHub Actions Waiting
Comment on lines 180 to +185
media.play().catch(() => {
set((paused = true));

if (DEV) {
w.media_play_failed();
}
Copy link
Member

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

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁

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.

2 participants