Created
August 22, 2023 15:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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