docs.rodeo

MDN Web Docs mirror

DocumentPictureInPicture: requestWindow() method

{{APIRef("Document Picture-in-Picture API")}} {{SeeCompatTable}} {{SecureContext_Header}} 

The requestWindow() method of the {{domxref("DocumentPictureInPicture")}}  interface opens the Picture-in-Picture window for the current main browsing context. It returns a {{jsxref("Promise")}}  that fulfills with a {{domxref("Window")}}  instance representing the browsing context inside the Picture-in-Picture window.

The requestWindow() method requires transient activation, i.e. it must be invoked in response to a user action such as a mouse click or button press.

Syntax

requestWindow()
requestWindow(options)

Parameters

[!NOTE] If one of height or width is specified, the other one must be too, otherwise an error is thrown. If both values are not specified, specified as 0, or set too large, the browser will clamp or ignore the values as appropriate to provide a reasonable user experience. The clamped size will vary depending on implementation, display size, and other factors.

Return value

A {{jsxref("Promise")}}  that fulfills with a {{domxref("Window")}}  object instance representing the browsing context inside the Picture-in-Picture window.

Exceptions

Examples

const videoPlayer = document.getElementById("player");

// ...

// Open a Picture-in-Picture window with all options set
const pipWindow = await window.documentPictureInPicture.requestWindow({
  width: videoPlayer.clientWidth,
  height: videoPlayer.clientHeight,
  disallowReturnToOpener: true,
  preferInitialWindowPlacement: true,
});

// ...

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN