Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Last active October 28, 2021 16:15
Show Gist options
  • Select an option

  • Save GaetanoPiazzolla/4475410d720faf115829550f7fc7b5fa to your computer and use it in GitHub Desktop.

Select an option

Save GaetanoPiazzolla/4475410d720faf115829550f7fc7b5fa to your computer and use it in GitHub Desktop.
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