वेब प्लैटफ़ॉर्म पर, स्क्रीन कैप्चर एपीआई की मदद से टैब, विंडो, और स्क्रीन शेयर की जा सकती हैं. getDisplayMedia()
तरीके से, उपयोगकर्ता को मीडिया स्ट्रीम के तौर पर कैप्चर करने के लिए स्क्रीन चुनने की अनुमति मिलती है. इसके बाद, इस स्ट्रीम को MediaRecorder API की मदद से रिकॉर्ड किया जा सकता है या नेटवर्क पर दूसरों के साथ शेयर किया जा सकता है. showOpenFilePicker()
तरीके का इस्तेमाल करके, रिकॉर्डिंग को डिवाइस में सेव की गई फ़ाइल में सेव किया जा सकता है.
यहां दिए गए उदाहरण में, WebM फ़ॉर्मैट में उपयोगकर्ता की स्क्रीन रिकॉर्ड करने, उसी पेज पर स्थानीय तौर पर पूर्वावलोकन करने, और रिकॉर्डिंग को उपयोगकर्ता के फ़ाइल सिस्टम में सेव करने का तरीका बताया गया है.
let stream;
let recorder;
shareScreenButton.addEventListener("click", async () => {
// Prompt the user to share their screen.
stream = await navigator.mediaDevices.getDisplayMedia();
recorder = new MediaRecorder(stream);
// Preview the screen locally.
video.srcObject = stream;
});
stopShareScreenButton.addEventListener("click", () => {
// Stop the stream.
stream.getTracks().forEach(track => track.stop());
video.srcObject = null;
});
startRecordButton.addEventListener("click", async () => {
// For the sake of more legible code, this sample only uses the
// `showSaveFilePicker()` method. In production, you need to
// cater for browsers that don't support this method, as
// outlined in https://web.dev/patterns/files/save-a-file/.
// Prompt the user to choose where to save the recording file.
const suggestedName = "screen-recording.webm";
const handle = await window.showSaveFilePicker({ suggestedName });
const writable = await handle.createWritable();
// Start recording.
recorder.start();
recorder.addEventListener("dataavailable", async (event) => {
// Write chunks to the file.
await writable.write(event.data);
if (recorder.state === "inactive") {
// Close the file when the recording stops.
await writable.close();
}
});
});
stopRecordButton.addEventListener("click", () => {
// Stop the recording.
recorder.stop();
});
ब्राउज़र समर्थन
MediaDevices.getDisplayMedia()
MediaRecorder API
File System Access API का showSaveFilePicker()
इस बारे में और पढ़ें
- W3C स्क्रीन कैप्चर की खास बातें
- W3C MediaStream Recording Specification
- WICG फ़ाइल सिस्टम ऐक्सेस स्पेसिफ़िकेशन