Created
October 2, 2024 19:05
-
-
Save danthemango/e24460d87a6c281eaf5ba59aba8c5c12 to your computer and use it in GitHub Desktop.
Create a screenshot of a video using devtools
This file contains hidden or 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
javascript: function captureVideoScreenshot() { const video = document.querySelector('video'); if (!video) { console.error('No video element found.'); return; } const canvas = document.createElement('canvas'); canvas.width = video.videoWidth; canvas.height = video.videoHeight; const ctx = canvas.getContext('2d'); ctx.drawImage(video, 0, 0, canvas.width, canvas.height); const link = document.createElement('a'); link.href = canvas.toDataURL('image/png'); link.download = 'screenshot.png'; link.click();}captureVideoScreenshot(); |
This file contains hidden or 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
// this assumes there's only one video on the page | |
function captureVideoScreenshot() { | |
const video = document.querySelector('video'); | |
if (!video) { | |
console.error('No video element found.'); | |
return; | |
} | |
const canvas = document.createElement('canvas'); | |
canvas.width = video.videoWidth; | |
canvas.height = video.videoHeight; | |
const ctx = canvas.getContext('2d'); | |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height); | |
const link = document.createElement('a'); | |
link.href = canvas.toDataURL('image/png'); | |
link.download = 'screenshot.png'; | |
link.click(); | |
} | |
// Call the function to capture the screenshot | |
captureVideoScreenshot(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment