Skip to content

Instantly share code, notes, and snippets.

@valtusovs
Created August 22, 2023 15:36
Show Gist options
  • Save valtusovs/b69e2ac39697f73821156c2e71d434c5 to your computer and use it in GitHub Desktop.
Save valtusovs/b69e2ac39697f73821156c2e71d434c5 to your computer and use it in GitHub Desktop.
Copies frame from video in current tab, check that only one video object is present. Click on the button and open the copied URL in new tab.
// based on https://stackoverflow.com/questions/13760805/how-to-take-a-snapshot-of-html5-javascript-based-video-player
var canvas = document.createElement('canvas');
canvas.width = 1920;
canvas.height = 1080;
var ctx = canvas.getContext('2d');
ctx.drawImage(document.getElementsByTagName("video")[0], 0, 0, canvas.width, canvas.height);
var dataURI = canvas.toDataURL('image/jpeg'); // can also use 'image/png'
var b = document.createElement("button");
b.onclick = () => {navigator.clipboard.writeText(dataURI)};
b.style = 'z-index:999999;position: fixed;top: 5px;';
document.appendChild(b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment