WICG / document-picture-in-picture

https://wicg.github.io/document-picture-in-picture/
Other
58 stars 9 forks source link

Considering 3rd party libraries implementation on modifying window.focus API #118

Open tmpmachine opened 8 months ago

tmpmachine commented 8 months ago

Wouldn't it be better if document PiP has it's own implementation of refocusing on main window instead of modifying window.focus() directly?

I believe some 3rd party libraries out there use window.focus on at least one of their components that hooks on common event listeners such as mouse click or keydown. Modifying window.focus would cause unwanted behaviour on these 3rd party libraries when used in PiP window, i.e. bringing the main window to focus unintendedly when they just want to use it to take notes on some videos online.

It can often be useful for the picture-in-picture window to be able to re-focus its opener tab, e.g. when the smaller form-factor of the window doesn't fit the experience the user needs. We modify the {{Window/focus()}} API to allow it to take system-level focus when a picture-in-picture window is focusing its opener.

https://github.com/WICG/document-picture-in-picture/blob/24f7754496d6a8083e97a437e83da34dfce93c16/spec.bs#L445

On the implementation side, I've issued a crbug and added a code snippet in the comment to handle this specific use case: https://issues.chromium.org/issues/330589220.