DocumentPictureInPicture: window 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

DocumentPictureInPicture 接口的只读属性 window 返回一个 Window 实例,该实例代表画中画窗口内部的浏览上下文。

如果已使用 DocumentPictureInPicture.requestWindow() 打开了画中画窗口,则返回一个 Window 对象实例,否则返回 null

示例

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

// …

await window.documentPictureInPicture.requestWindow({
  width: videoPlayer.clientWidth,
  height: videoPlayer.clientHeight,
});

// …

const pipWindow = window.documentPictureInPicture.window;
if (pipWindow) {
  // Mute video playing in the Picture-in-Picture window.
  const pipVideo = pipWindow.document.querySelector("#video");
  pipVideo.muted = true;
}

规范

规范
文档画中画规范
# dom-documentpictureinpicture-window

浏览器兼容性

另见