Skip to content

Instantly share code, notes, and snippets.

@Arcitec
Last active January 29, 2021 19:27
Show Gist options
  • Save Arcitec/e9a4020fa6a647b9c532f134e2d75b20 to your computer and use it in GitHub Desktop.
Save Arcitec/e9a4020fa6a647b9c532f134e2d75b20 to your computer and use it in GitHub Desktop.
Save as a bookmarklet to have an easy, 1-click button for opening HTML5 videos in PiP mode.
javascript:if("pictureInPictureEnabled"in document&&"querySelectorAll"in document){(async function(){const a=document.querySelectorAll("video");if(0===a.length)window.alert("Sorry, no videos on the page.");else if(0<a.length){const b=a[0];try{b===document.pictureInPictureElement?await document.exitPictureInPicture():await b.requestPictureInPicture()}catch(a){console.error(a)}}})()}else"pictureInPictureEnabled"in document?document.pictureInPictureEnabled||window.alert("Picture-in-Picture not available."):window.alert("Picture-in-Picture is disabled.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment