Skip to content

Instantly share code, notes, and snippets.

@thangman22
Created December 28, 2024 15:24
Show Gist options
  • Save thangman22/85ae30b09892939e1ccf3ab42e9c7127 to your computer and use it in GitHub Desktop.
Save thangman22/85ae30b09892939e1ccf3ab42e9c7127 to your computer and use it in GitHub Desktop.
pipButton.addEventListener("click", async () => {
const chatScreen = document.querySelector("#chat-screen");
// Open a Picture-in-Picture window.
const pipWindow = await documentPictureInPicture.requestWindow();
// Copy style sheets over from the initial document
// so that the player looks the same.
[...document.styleSheets].forEach((styleSheet) => {
try {
const cssRules = [...styleSheet.cssRules].map((rule) => rule.cssText).join('');
const style = document.createElement('style');
style.textContent = cssRules;
pipWindow.document.head.appendChild(style);
} catch (e) {
const link = 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(chatScreen);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment