Last active
October 28, 2021 16:15
-
-
Save GaetanoPiazzolla/4475410d720faf115829550f7fc7b5fa to your computer and use it in GitHub Desktop.
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
| let btn = document.querySelector("#record-button") | |
| btn.addEventListener("click", async function () { | |
| let stream = await navigator.mediaDevices.getDisplayMedia({ | |
| video: true | |
| }) | |
| let mediaRecorder = new MediaRecorder(stream, { | |
| mimeType: "video/webm" | |
| }) | |
| let chunks = [] | |
| mediaRecorder.addEventListener('dataavailable', function(e) { | |
| chunks.push(e.data) | |
| }) | |
| mediaRecorder.addEventListener('stop', function(){ | |
| let video = document.querySelector("video") | |
| video.src = URL.createObjectURL(new Blob(chunks, { | |
| type: chunks[0].type | |
| })) | |
| let a = document.createElement('a') | |
| a.href = video.src | |
| a.download = 'screen-video.webm' | |
| a.click() | |
| }) | |
| mediaRecorder.start() | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment