Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda