Screen Capture API
The Screen Capture API, as the name suggests, allows you to capture the contents of a screen, making the process of building a screen recorder a piece of cake.
You need a video element to display the captured screen. The start button will start the screen capture.
<video id="preview" autoplay> Your browser doesn't support HTML5. </video> <button id="start" class="btn">Start</button>
const previewElem = document.getElementById("preview"); const startBtn = document.getElementById("start"); async function startRecording() { previewElem.srcObject = await navigator.mediaDevices.getDisplayMedia({ video: true, audio: true, }); } startBtn.addEventListener("click", startRecording);