document.onclick = (event) => {
if (document.pictureInPictureElement) {
document
.exitPictureInPicture()
.then(() => console.log("Document Exited from Picture-in-Picture mode"))
.catch((err) => console.error(err));
} else {
video.requestPictureInPicture();
}
};Document: exitPictureInPicture() method / notebook
Document: exitPictureInPicture() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.