Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ilyasKerbal/1def083082e5530d949b134adfa72e35 to your computer and use it in GitHub Desktop.
Save ilyasKerbal/1def083082e5530d949b134adfa72e35 to your computer and use it in GitHub Desktop.
Request picture in picture on first found video that is playing #bookmarklet
javascript: void ((function() {
/** @type {NodeListOf<HTMLIFrameElement>} */
const iFrames = window.document.querySelectorAll('iframe');
/** @type {Document[]} */
const allDocuments = [
window.document,
...Array.from(iFrames)
.map(i => i.contentDocument)
/**
* some iFrames have `null` contentDocument
* one reason for this is because of not Same-Origin policy
*/
.filter(Boolean)
];
/** @type {HTMLVideoElement[]} */
const allVideos = allDocuments.flatMap(d => Array.from(d.querySelectorAll('video')));
/** @type {HTMLVideoElement} */
const playingVideo = allVideos.find(v => !v.paused);
if (playingVideo) {
playingVideo.requestPictureInPicture();
}
})());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment