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.
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.
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.