Skip to content

Update HTMLMediaElement abort event description and example (#44222)#44280

Closed
vamshikrishnaramasamy wants to merge 1 commit into
mdn:mainfrom
vamshikrishnaramasamy:fix/issue-44222-abort-event-example
Closed

Update HTMLMediaElement abort event description and example (#44222)#44280
vamshikrishnaramasamy wants to merge 1 commit into
mdn:mainfrom
vamshikrishnaramasamy:fix/issue-44222-abort-event-example

Conversation

@vamshikrishnaramasamy
Copy link
Copy Markdown
Contributor

The existing example on HTMLMediaElement: abort_event appends a <source> element to a <video>, which does not fire the abort event. Per @hamishwillee on #44222, abort is fired for user-intended cancellation of a media load — typically the browser's stop button, or changing/clearing src mid-load.

Changes:

  • Description now states when the event fires, with the common triggers.
  • Example replaced with one that actually fires abort: start loading a video, then change src to a different resource. Comment notes that clearing src or the browser's stop button have the same effect.

Closes #44222.

@vamshikrishnaramasamy vamshikrishnaramasamy requested a review from a team as a code owner May 28, 2026 01:11
@vamshikrishnaramasamy vamshikrishnaramasamy requested review from chrisdavidmills and removed request for a team May 28, 2026 01:11
@github-actions github-actions Bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels May 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Preview URLs (1 page)

Copy link
Copy Markdown
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

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

@vamshikrishnaramasamy thanks for your contribution!

I tested this locally (in Chrome), and the code, as written, doesn't fire the abort event. It looks like the src replacement takes effect immediately, so it isn't seen as replacing the original src setting.

I did manage to get the event to fire with code like this:

const video = document.querySelector("video");

video.addEventListener("abort", () => {
  console.log("Video loading was aborted.");
});

video.setAttribute("src", "assets/bigbuckbunny.mp4");

setTimeout(() => {
  video.setAttribute("src", "");
}, 3000);

By the time the timeout ran, the video had completely loaded. This leads me to two bits of feedback concerning your work:

  1. Test it more thoroughly, and make sure your code fires the event as advertised.
  2. Think about your claim of "The abort event is fired when the loading of a media resource is canceled before it completes". Is it more generally when it is cancelled, but not as the result of an error?

@hamishwillee
Copy link
Copy Markdown
Collaborator

Is it more generally when it is cancelled, but not as the result of an error?

I seem to recall that is what the spec says - it should be " loading of a media resource is canceled by the user before it completes"

@hamishwillee
Copy link
Copy Markdown
Collaborator

hamishwillee commented May 29, 2026

@vamshikrishnaramasamy This issue was already taken by #44227 - you can see in the issue that they have a linked PR.

That issue was started first, so IMO the other one should continue and this should be closed
I've asked them to make sure that it is tested properly - learning from your work.

@vamshikrishnaramasamy
Copy link
Copy Markdown
Contributor Author

Right on both counts. I didn't catch that setting src swaps in before abort can fire, and I missed that #44227 was already open against the same issue. Closing so the other PR can land. Thanks for testing it properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTMLMediaElement abort event: unclear example

4 participants