pipButton.addEventListener('click',async()=>{constplayer=document.querySelector("#player");// Open a Picture-in-Picture window.constpipWindow=awaitdocumentPictureInPicture.requestWindow();// Move the player to the Picture-in-Picture window.pipWindow.document.body.append(player);
pipButton.addEventListener("click",async()=>{constplayer=document.querySelector("#player");// Open a Picture-in-Picture window whose size is// the same as the player's.constpipWindow=awaitdocumentPictureInPicture.requestWindow({width:player.clientWidth,height:player.clientHeight,// Move the player to the Picture-in-Picture window.pipWindow.document.body.append(player);
pipButton.addEventListener("click",async()=>{// Open a Picture-in-Picture window which hides the "back to tab" button.constpipWindow=awaitdocumentPictureInPicture.requestWindow({disallowReturnToOpener:true,
pipButton.addEventListener("click",async()=>{// Open a Picture-in-Picture window in its default position / size.constpipWindow=awaitdocumentPictureInPicture.requestWindow({preferInitialWindowPlacement:true,
pipButton.addEventListener("click",async()=>{constplayer=document.querySelector("#player");// Open a Picture-in-Picture window.constpipWindow=awaitdocumentPictureInPicture.requestWindow();// Copy style sheets over from the initial document
// so that the player looks the same.[...document.styleSheets].forEach((styleSheet)=>{try{constcssRules=[...styleSheet.cssRules].map((rule)=>rule.cssText).join('');conststyle=document.createElement('style');style.textContent=cssRules;pipWindow.document.head.appendChild(style);}catch(e){constlink=document.createElement('link');link.rel='stylesheet';link.type=styleSheet.type;link.media=styleSheet.media;link.href=styleSheet.href;pipWindow.document.head.appendChild(link);// Move the player to the Picture-in-Picture window.pipWindow.document.body.append(player);
pipButton.addEventListener("click",async()=>{constplayer=document.querySelector("#player");// Open a Picture-in-Picture window.constpipWindow=awaitdocumentPictureInPicture.requestWindow();// Move the player to the Picture-in-Picture window.pipWindow.document.body.append(player);// Move the player back when the Picture-in-Picture window closes.pipWindow.addEventListener("pagehide",(event)=>{constplayerContainer=document.querySelector("#playerContainer");constpipPlayer=event.target.querySelector("#player");playerContainer.append(pipPlayer);
constpipWindow=documentPictureInPicture.window;if(pipWindow){// Mute video playing in the Picture-in-Picture window.constpipVideo=pipWindow.document.querySelector("#video");pipVideo.muted=true;
// Add a "mute" button to the Picture-in-Picture window.constpipMuteButton=pipWindow.document.createElement("button");pipMuteButton.textContent="Mute";pipMuteButton.addEventListener("click",()=>{constpipVideo=pipWindow.document.querySelector("#video");pipVideo.muted=true;pipWindow.document.body.append(pipMuteButton);
constresizeButton=pipWindow.document.createElement('button');resizeButton.textContent='Resize';resizeButton.addEventListener('click',()=>{// Expand the Picture-in-Picture window's width by 20px and height by 30px.pipWindow.resizeBy(20,30);pipWindow.document.body.append(resizeButton);
constreturnToTabButton=pipWindow.document.createElement("button");returnToTabButton.textContent="Return to opener tab";returnToTabButton.addEventListener("click",()=>{window.focus();pipWindow.document.body.append(returnToTabButton);