Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda