w3c / picture-in-picture

Picture-in-Picture (PiP)
https://w3c.github.io/picture-in-picture
Other
311 stars 39 forks source link

Should PiP video removed from the DOM leave PiP? #99

Open beaufortfrancois opened 5 years ago

beaufortfrancois commented 5 years ago

In Chrome and Safari, a video element not attached to the DOM can start playing and enter Picture-in-Picture. When video is attached to the DOM while playing in Picture-in-Picture, browser implementations differ though when video is removed from the DOM:

It looks like Safari takes a hint from the Fullscreen API:

Whenever the removing steps run with a removedNode, run these steps:

  1. Let document be removedNode’s node document.
  2. Let nodes be removedNode’s shadow-including inclusive descendants that have their fullscreen flag set, in shadow-including tree order.
  3. For each node in nodes:
    1. If node is document’s fullscreen element, exit fullscreen document.
    2. Otherwise, unfullscreen node.
    3. If document’s top layer contains node, remove node from document’s top layer.

Note that the Fullscreen API doesn't allow an element not atttached to the DOM to enter fullscreen unlike Picture-in-Picture that does not prevent it.

beaufortfrancois commented 4 years ago

It would be great if spec could document the intended behavior for this.

@jernoble @mounirlamouri Let me know what you think and I'll update the spec.

mounirlamouri commented 4 years ago

Given that you can send a video not in the document in PIP, I see no reason why leaving the document should exit Picture-in-Picture. I don't have a strong opinion because it's probably an edge case anyway. Is there a specific reason why Safari did this?

jernoble commented 4 years ago

We're debating this internally. We think it was just a side effect of our original conflation of "fullscreen presentation modes" and "picture-in-picture", and not intended as an explicit policy.

WebKit has always supported entering video fullscreen from a non-DOM

mounirlamouri commented 4 years ago

@beaufortfrancois should we close?

beaufortfrancois commented 4 years ago

Sure. Let's close.

beaufortfrancois commented 3 years ago

It looks like Safari updated their behaviour:

When a video is playing in the picture-in-picture mode, do not pause it or exit the
picture-in-picture mode when detaching the video element from the DOM.

Source: https://trac.webkit.org/changeset/265904/webkit/

@mounirlamouri Shall we update Chrome and not pause as well for consistency?

mounirlamouri commented 3 years ago

The issue with not pausing is that it goes against the HTML specification requirements (see just above https://html.spec.whatwg.org/multipage/media.html#seeking).

That means the WebKit change is against spec. I would rather not have the Picture-in-Picture specification changes the behaviour of the HTML specification. We could obviously ask for the HTML specification to update this section if we believe it's worth it.

beaufortfrancois commented 3 years ago

@pliu6 @jernoble Do you have plans to update the HTML spec?

beaufortfrancois commented 3 years ago

@jernoble (gentle ping)

beaufortfrancois commented 3 years ago

@pliu6 (gentle ping)

jernoble commented 3 years ago

Raised an issue against HTML: https://github.com/whatwg/html/issues/6271

beaufortfrancois commented 3 years ago

I've just updated Chromium to make sure video do not pause when playing in Picture-in-Picture and subsequently removed from the Document. See CL at https://chromium-review.googlesource.com/c/chromium/src/+/2627311

I've also added some web platform tests at https://github.com/web-platform-tests/wpt/pull/27185 and make sure both Chrome and Safari browsers pass them.

mounirlamouri commented 3 years ago

Removing agenda label as it sounds that this is reaching a conclusion.