(() => { const format = { ext: "png", mime: "image/png", }; const video = document.querySelector("video"); const width = video.videoWidth; const height = video.videoHeight; const canvas = document.createElement("canvas"); canvas.width = width; canvas.height = height; const ctx = canvas.getContext("2d"); ctx.drawImage(video, 0, 0, width, height); const timestamp = (new Date()).toISOString() .replaceAll(/[t:]/gi, "-") .replaceAll(/\..*$/gi, ""); canvas.toBlob((it) => { const url = URL.createObjectURL(it); const a = document.createElement("a"); a.href = url; a.download = `screenshot-${timestamp}.${format.ext}`; a.click(); URL.revokeObjectURL(url); }, format.mime, 1); })();