<meta name="viewport" content="width=device-width, initial-scale=1.0" />
const button = document.querySelector("button");
button.addEventListener("click", async () => {
const stream = await navigator.mediaDevices.getDisplayMedia({
const mime = MediaRecorder.isTypeSupported("video/webm;codecs=h264")
? "video/webm;codecs=h264"
const mediaRecorder = new MediaRecorder(stream, { mimeType: mime });
mediaRecorder.addEventListener("dataavailable", function (e) {
mediaRecorder.addEventListener("stop", () => {
const blob = new Blob(chunks, { type: chunks[0].type });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.download = "video.webm";