record screen video with javascript code example

Example 1: how to make a screen recording software with js

const stream = await navigator. mediaDevices. getDisplayMedia({ video: { mediaSource: "screen" } });
const recorder = new MediaRecorder(stream); const chunks = []; recorder. ondataavailable = e => chunks. push(e. ...
recorder. onstop = e => { const completeBlob = new Blob(chunks, { type: chunks[0]. type }); video.

Example 2: javascript record video in browser

<input type="file" accept="video/*" capture="camera" id="recorder"><video id="player" controls></video><script>  var recorder = document.getElementById('recorder');  var player = document.getElementById('player');  recorder.addEventListener('change', function(e) {    var file = e.target.files[0];    // Do something with the video file.    player.src = URL.createObjectURL(file);  });</script>