revision:
The Document method exitPictureInPicture() requests that a video contained in this document, which is currently floating, be taken out of picture-in-picture mode, restoring the previous state of the screen. This usually reverses the effects of a previous call to HTMLVideoElement.requestPictureInPicture().
exitPictureInPicture()
Parameters: none
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(); } };
example: use on video element