Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
Is creating a video element in js and playing it without appending it to document allowed?

According to the HTML spec section on media elements:

Media elements that are potentially playing while not in a document must not play any video, but should play any audio component. Media elements must not stop playing just because all references to them have been removed; only once a media element is in a state where no further audio could ever be played by that element may the element be garbage collected.

However, I have tested creating video elements in js and playing them in Chrome, Safari, and Firefox and they have all worked without them being appended to the document. Are these browsers not following the spec? Or am I interpreting the spec wrong?

I ask because I want to extract frames from a video by seeking through it and painting the frames to a canvas. Ideally, this would all be done in js without having to append the video to the DOM. However, I do not want to do this if it is against the spec, as it might change in the future and my implementation might break.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I agree that this wording is a bit unclear, and the whole section seems a bit outdated anyway, but after further inspection that doesn't seem to cause a bug.

While the term "play" is not precisely defined, this part actually doesn't really matter. Consumers will define their own way of grabbing the video data, for instance the mediacapture-from-element specs do specify that

Whether a media element is actively rendering content (e.g., to a screen or audio device) has no effect on the content of captured streams.

In fact, implementations hook to the VideoTracks before it reaches the <video> element's renderer.

Similarly, for when the <video> is being used as a CanvasImageSource, the specs ask that

When a CanvasImageSource object represents an HTMLVideoElement, then the frame at the current playback position when the method with the argument is invoked must be used as the source image when rendering the image for CanvasRenderingContext2D APIs

So once again, what is rendered by the <video> element doesn't matter, what matters here is its current playback position, which doesn't stop being incremented when the element is disconnected.

So yes, you are safe to use disconnected <video> elements to grab frames from it, most Web Platform Tests that do draw a <video> do expect this behavior (e.g), so it can be considered as "standard".

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!