Skip to content

Instantly share code, notes, and snippets.

@ricardoboss
Last active November 21, 2022 10:14
Show Gist options
  • Save ricardoboss/7ddda411314965132c6d4ec4f6fb21f1 to your computer and use it in GitHub Desktop.
Save ricardoboss/7ddda411314965132c6d4ec4f6fb21f1 to your computer and use it in GitHub Desktop.
Watch any video in picture-in-picture mode

The link below can be added as a bookmark to your favourite browser. Whenever you are browsing Twitch, YouTube, Netflix, Disney+, Amazon Prime and possibly more (not tested), you can click the bookmark and pop-out the video into it's own, resizable window.

I always did this manually (optionally removing layers above the video to directly right click the video element), but it has become quite cumbersome (especially with twitch). Another thought I had was to write an extension which shows a button, but this bookmark is way simpler.

It works like this:

  1. Find video elements
  2. Filter them by which element is currently playing and has no errors
  3. Enable picture-in-picture (by removing the disablePictureInPicture attribute)
  4. Request picture-in-picture from the user agent

Hopefully, some will find this useful.

javascript:window.vid = [...document.getElementsByTagName('video')].filter(v => v.currentTime > 0 && !v.paused && !v.ended && v.readyState > 2).pop(); window.vid.requestPictureInPicture().catch((e) => { window.vid.disablePictureInPicture = undefined; window.vid.requestPictureInPicture(); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment