Limited availability
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The Document Picture-in-Picture API makes it possible to open an always-on-top window that can be populated with arbitrary HTML content â for example a video with custom controls or a set of streams showing the participants of a video conference call. It extends the earlier Picture-in-Picture API for <video>
, which specifically enables an HTML <video>
element to be put into an always-on-top window.
It is often helpful to have a different window available to a web app in addition to the main window in which the app is running. You might want to browse other windows while keeping specific app content in view, or you might want to give that content its own space while keeping the main app window freed up to display other content. You could handle this by just opening a regular new browser window, but this has two major issues:
To solve these problems, web browsers have introduced APIs allowing apps to spawn an always-on-top window that is part of the same session. The first recognized use case was keeping video content playing in a separate window so that the user can continue to consume it while looking at other content. This is handled using the Picture-in-Picture API for <video>
, which is directly used on a <video>
element to place it into the separate window.
However, this API has been found to be somewhat limiting â you can only put a single <video>
element into the always-on-top window, with minimal browser-generated controls. To provide more flexibility, the Document Picture-in-Picture API has been introduced. This allows any content to be placed in the always-on-top window for a wide range of use cases, including:
A new DocumentPictureInPicture
object instance representing the always-on-top Picture-in-Picture window for the current document context is available via Window.documentPictureInPicture
. The Picture-in-Picture window is opened by calling the DocumentPictureInPicture.requestWindow()
method, which returns a Promise
that fulfills with the window's own Window
object.
The Picture-in-Picture window is similar to a blank same-origin window opened via Window.open()
, with some differences:
Apart from that, you can manipulate the Picture-in-Picture window's Window
instance however you want, for example appending the content you want to display there onto its DOM, and copying stylesheets to it so that the appended content will be styled the same way as when it is in the main window. You can also close the Picture-in-Picture window (by clicking the browser-provided control, or by running Window.close()
on it), and then react to it closing using the standard pagehide
. When it closes, you'll want to put the content it was showing back into the main app window.
See Using the Document Picture-in-Picture API for a detailed usage guide.
InterfacesDocumentPictureInPicture
The entry point for creating and handling document Picture-in-Picture windows.
DocumentPictureInPictureEvent
Event object for the enter
event, which fires when the Picture-in-Picture window is opened.
Window.documentPictureInPicture
Returns a reference to the DocumentPictureInPicture
object for the current document context.
display-mode
, the picture-in-picture
value
A CSS media feature value that allows developers to apply CSS to a document based on whether it is being displayed in Picture-in-Picture mode.
See Document Picture-in-Picture API Example for a full working demo (see the full source code also).
Specifications Browser compatibilityRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4