Skip to content

Instantly share code, notes, and snippets.

@phaseOne
Last active March 23, 2026 00:25
Show Gist options
  • Select an option

  • Save phaseOne/039feb9757477cd1ed3c5b90a7251fd6 to your computer and use it in GitHub Desktop.

Select an option

Save phaseOne/039feb9757477cd1ed3c5b90a7251fd6 to your computer and use it in GitHub Desktop.
Download the currently displayed frame of a YouTube or Vimeo video as a PNG
const saveBlob = (blob, fileName) => {
const a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
};
const platformConfigs = {
"vimeo.com": { "selector": ".player .vp-video-wrapper video" },
"youtube.com": { "selector": "#movie_player > div.html5-video-container > video" }
};
const supportedPlatforms = Object.keys(platformConfigs);
const platform = supportedPlatforms.find( platform => window.location.hostname.includes(platform) );
if (platform === undefined) { throw new Error("unable to identify video platform") }
else { console.debug("Platform:", platform); }
(function () {
const videoEl = document.querySelector(platformConfigs[platform].selector);
const canvas = new OffscreenCanvas(videoEl.videoWidth, videoEl.videoHeight);
canvas.getContext('2d', { alpha: false }).drawImage(videoEl, 0, 0, canvas.width, canvas.height);
canvas.convertToBlob({ options: { type: 'image/png' } }).then( blob => saveBlob(blob, 'frame.png') );
}());
@phaseOne

phaseOne commented Jun 6, 2022

Copy link
Copy Markdown
Author

Usage: Chrome

Simply paste this into the DevTools console, and a file named frame.png will download. Note: the resolution of the still frame is dependent upon the current video resolution. If the playback resolution is set to Auto, then the image may not be the highest resolution available due to buffering. If you want the highest resolution, manually set the resolution to the highest, and then run the script.

@phaseOne

phaseOne commented Mar 23, 2026

Copy link
Copy Markdown
Author

Usage: Safari

Convert to bookmarklet with Bookmarkleter and add to bookmarks.

Options for Bookmarkleter

  • URL-encode reserved characters: [space], %, ", <, >, #, @, &, ?
  • Wrap in an IIFE (anonymizing function).
  • Mangle variables and remove dead code to reduce size.
  • Transpile for browsers using Babel.
  • Make sure a modern version (≥ 1.7) of jQuery is available for your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment