Skip to content

Instantly share code, notes, and snippets.

@danthemango
Created October 2, 2024 19:05
Show Gist options
  • Save danthemango/e24460d87a6c281eaf5ba59aba8c5c12 to your computer and use it in GitHub Desktop.
Save danthemango/e24460d87a6c281eaf5ba59aba8c5c12 to your computer and use it in GitHub Desktop.
Create a screenshot of a video using devtools
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 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