Skip to content

Fix tasks for enterPictureInPicture and exitPictureInPicture.#233

Closed
markafoltz wants to merge 1 commit into
mainfrom
issue-230-tasks
Closed

Fix tasks for enterPictureInPicture and exitPictureInPicture.#233
markafoltz wants to merge 1 commit into
mainfrom
issue-230-tasks

Conversation

@markafoltz

@markafoltz markafoltz commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

Closes #230: ensures that Promises returned by these methods use the media element task source.

Also fixes several ambiguous cross references.


Preview | Diff

@markafoltz

Copy link
Copy Markdown
Contributor Author

Should also close #225

@markafoltz markafoltz self-assigned this Sep 27, 2024
@beaufortfrancois

Copy link
Copy Markdown
Collaborator

@markafoltz From what I can see in https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/document_picture_in_picture/picture_in_picture_controller_impl.cc;l=158?q=kMediaElementEvent%20f:picture&ss=chromium%2Fchromium%2Fsrc, Chromium's implementation will no longer comply with the spec. I may be wrong about this but is this what we want ?

Note that this PR is related to #229

@markafoltz

Copy link
Copy Markdown
Contributor Author

It should be impossible to fire events or resolve promises off of the main thread in Blink, so where do you see Chrome not complying? (Sorry I don't know the PiP code.)

@markafoltz

Copy link
Copy Markdown
Contributor Author

Thanks for the pointer as well, this should also close #229

@beaufortfrancois

Copy link
Copy Markdown
Collaborator

It should be impossible to fire events or resolve promises off of the main thread in Blink, so where do you see Chrome not complying? (Sorry I don't know the PiP code.)

Like I said, I may be wrong, but https://source.chromium.org/search?q=kMediaElementEvent%20f:picture&sq=&ss=chromium%2Fchromium%2Fsrc returns results where we specifically use the media element task source in Picture-in-Picture, and I'm not sure it covers all the cases you've updated in this PR.

An example would be the user agent MUST <a>queue a picture-in-picture task</a> to <a>fire an event</a> named {{resize}} at {{pictureInPictureElement}}. at https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/picture_in_picture/picture_in_picture_window.cc;l=30;drc=f522344e45882da4c7f7cb1b3a0a7bd747d654bb
I believe we should be using something like EnqueueEvent(*Event::Create(event_type_names::kResize), TaskType::kMediaElementEvent); instead of synchronously dispatching the event with DispatchEvent(*Event::Create(event_type_names::kResize)); like we do today.

Comment thread index.bs
The <a>task source</a> for all the tasks queued in this specification is the
<a>media element event task source</a> of the video element in question.

When an algorithm <dfn lt="queue a picture-in-picture task">queues a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we should just reuse [[queue a media element task]] instead:
https://html.spec.whatwg.org/multipage/media.html#queue-a-media-element-task

That takes a media element instead it seems... that might make more sense?

@marcoscaceres marcoscaceres added the TPAC2025 Agenda topic for TPAC 2025 label Oct 16, 2025
Comment thread index.bs
Comment on lines +360 to +361
4. [=Queue a picture-in-picture task=] to [=/resolve=] |promise| with the
<a>Picture-in-Picture window</a> associated with {{pictureInPictureElement}}.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
4. [=Queue a picture-in-picture task=] to [=/resolve=] |promise| with the
<a>Picture-in-Picture window</a> associated with {{pictureInPictureElement}}.
4. [=Queue a picture-in-picture task=] to [=/resolve=] |promise| with the
{{pictureInPictureElement}}'s [=picture-in-Picture window=].

Comment thread index.bs
2. If the previous step threw an exception, reject |promise| with that
2. If the previous step threw an exception,
[=queue a picture-in-picture task=] to reject |promise| with that
exception and abort these steps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
exception and abort these steps.
[=exception=] and abort these steps.

Comment thread index.bs

1. Run the <a>exit Picture-in-Picture algorithm</a>.
2. If the previous step threw an exception, reject |promise| with that
2. If the previous step threw an exception,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
2. If the previous step threw an exception,
2. If the previous step threw an [=exception=],

Comment thread index.bs
Comment on lines +437 to +439
{{pictureInPictureElement}} changes, the user agent MUST
<a>queue a picture-in-picture task</a> to <a>fire an event</a> named
{{resize}} at {{pictureInPictureElement}}.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
{{pictureInPictureElement}} changes, the user agent MUST
<a>queue a picture-in-picture task</a> to <a>fire an event</a> named
{{resize}} at {{pictureInPictureElement}}.
{{pictureInPictureElement}} changes, the user agent MUST
<a>queue a picture-in-picture task</a> to [=/fire an event=] named
"{{resize}}" at {{pictureInPictureElement}}.

@chrisn chrisn removed the TPAC2025 Agenda topic for TPAC 2025 label Dec 4, 2025
@theIDinside

theIDinside commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

I want to suggest the PR I've written which covers this, for requestPictureInPicture, but also makes sure to address more issues than just firing events and resolving. There are other problems.

It's re-written the requestPictureInPicture to look and behave similar to similar algorithms like the fullscreen algorithm requestFullscreen. I think it's nice to have some consistency between specs, beyond the technical details like correctness.

#245

@marcoscaceres

Copy link
Copy Markdown
Member

Ok, I'm going to say #245 closes #233.

marcoscaceres added a commit that referenced this pull request May 21, 2026
…not possible

Restructures the requestPictureInPicture() algorithm to handle parallel window creation more robustly. The algorithm now creates the Picture-in-Picture window in parallel, then queues subsequent DOM mutations and promise resolutions as a separate task.

Key changes:
- Steps 1-9 run synchronously with validation checks
- Step 10 returns the promise and runs remaining steps in parallel
- Within the parallel section, a global task is queued to handle DOM mutations, fire events, and resolve/reject the promise
- Enforces one Picture-in-Picture element per top-level browsing context
- Mandatorily exits fullscreen when entering PiP
- Exits previous PiP session when a new one is requested

Addresses #244, #233, and #229.

Co-authored-by: Marcos Cáceres <marcos@marcosc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants