Skip to content

Instantly share code, notes, and snippets.

@DIYgod
Last active February 10, 2020 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DIYgod/2bf31edb4c834129ca2ef8f53894c96d to your computer and use it in GitHub Desktop.
Save DIYgod/2bf31edb4c834129ca2ef8f53894c96d to your computer and use it in GitHub Desktop.
HTML5 video screenshot
canvas = document.createElement('canvas');
video = document.querySelector('video');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
canvas.toBlob((blob) => {
dataURL = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = dataURL;
link.download = 'screenshot.png';
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(dataURL);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment