Use navigator.mediaDevices.getDisplayMedia() to ask the browser user to choose a screen, window, or tab and return a live MediaStream. To make a still screenshot, grab a frame from its video track and export it through a canvas. To share or record a live screen, attach the stream to a video element, a recorder, or a WebRTC connection. Screen capture requires a secure context and a fresh user action for every request.
What the MediaStream screen-capture workflow does
The browser-native screen-capture entry point is navigator.mediaDevices.getDisplayMedia(). It opens a browser-controlled picker so the user can select a display surface, such as a tab, window, or entire display. On approval, its promise resolves to a MediaStream with a video track and, where supported and selected, an audio track. The page does not get to choose a surface silently or reuse a saved grant. MDN’s getDisplayMedia() reference describes the permission and stream behavior.
A still screenshot and a screen share are different outcomes of that permissioned stream. A screenshot is one frame exported as an image; sharing is the ongoing stream, commonly previewed locally, recorded, or sent to another participant with WebRTC. A screen capture does not require camera access. getUserMedia() is the separate API for camera and microphone inputs.
Requirements and user-facing safeguards
- Secure context: Use HTTPS in production. Browsers generally expose the relevant media-device APIs only in secure contexts.
- Transient user activation: Call
getDisplayMedia()directly in response to a clear user action, such as clicking a “Share screen” button. Do not defer the call until after unrelated asynchronous work that may outlast that activation. - Fresh user choice: Each request opens a fresh browser selection flow. The application cannot silently start capturing based on a previous selection.
- Permissions Policy: A page or embedding policy can block screen capture. Embedded use may need the
display-capturefeature delegated by the top-level page. See MDN’s display-capture Permissions Policy reference. - Explain and stop: Tell users which content they are about to share, show an obvious stop control, and handle the browser’s own stop-sharing control. A selected tab or display can expose sensitive material beyond the app.
Request a screen and show a live preview
Put the request inside a click handler. Request audio only if the feature uses it; even then, treat an audio track as optional because browser, operating system, and selected surface determine whether one is available.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- Compatible with Nintendo Switch 2’s new GameChat mode
- Crisp HD 720p/30 fps video calls with diagonal 55° field of view and auto light correction. Compatible with popular platforms including Skype and Zoom.
- The built-in noise-reducing mic makes sure your voice comes across clearly up to 1.5 meters away, even if you’re in busy surroundings.
- C270’s RightLight 2 feature adjusts to lighting conditions, producing brighter, contrasted images to help you look good in all your conference calls.
- The adjustable universal clip lets you attach the camera securely to your screen or laptop, or fold the clip and set the webcam on a shelf. You’re always ready for your next video call.
<button id="share" type="button">Share screen</button>
<button id="stop" type="button" disabled>Stop sharing</button>
<video id="preview" autoplay playsinline muted></video>
<p id="status" role="status"></p>
<script>
const shareButton = document.querySelector('#share');
const stopButton = document.querySelector('#stop');
const preview = document.querySelector('#preview');
const status = document.querySelector('#status');
let screenStream;
shareButton.addEventListener('click', async () => {
status.textContent = '';
try {
// Call immediately from the user gesture. Use audio: true only if needed.
screenStream = await navigator.mediaDevices.getDisplayMedia({
video: true,
audio: false
});
preview.srcObject = screenStream;
shareButton.disabled = true;
stopButton.disabled = false;
const [videoTrack] = screenStream.getVideoTracks();
videoTrack.addEventListener('ended', stopSharing, { once: true });
} catch (error) {
if (error.name === 'NotAllowedError') {
status.textContent = 'Screen sharing was cancelled or blocked.';
} else {
status.textContent = `Could not start screen sharing: ${error.message}`;
}
}
});
function stopSharing() {
if (screenStream) {
screenStream.getTracks().forEach(track => track.stop());
screenStream = undefined;
}
preview.srcObject = null;
shareButton.disabled = false;
stopButton.disabled = true;
}
stopButton.addEventListener('click', stopSharing);
</script>
The preview is muted to avoid feedback if the captured surface includes audio; muting the preview does not alter a separate stream you may send to a recorder or peer. If you request audio: true, check screenStream.getAudioTracks().length rather than assuming a track exists. The browser picker remains responsible for the available sources and user choice.
Capture one still image from the stream
For a still image, use ImageCapture.grabFrame() on the stream’s video track, then draw the returned ImageBitmap to a canvas and export it. This captures a frame from the selected stream; it does not take a screenshot without the user’s consent. The Screen Capture API guide documents the frame-to-canvas pattern along with element and region capture.
async function captureStill(videoTrack, mimeType = 'image/png') {
if (!videoTrack || videoTrack.readyState !== 'live') {
throw new Error('There is no live screen video track.');
}
if (!('ImageCapture' in window)) {
throw new Error('ImageCapture is not available in this browser.');
}
const imageCapture = new ImageCapture(videoTrack);
const bitmap = await imageCapture.grabFrame();
try {
const canvas = document.createElement('canvas');
canvas.width = bitmap.width;
canvas.height = bitmap.height;
const context = canvas.getContext('2d');
if (!context) throw new Error('Could not create a 2D canvas context.');
context.drawImage(bitmap, 0, 0);
const blob = await new Promise((resolve, reject) => {
canvas.toBlob(result => {
if (result) resolve(result);
else reject(new Error('The browser could not encode the image.'));
}, mimeType);
});
return blob;
} finally {
bitmap.close();
}
}
document.querySelector('#capture').addEventListener('click', async () => {
try {
const blob = await captureStill(screenStream?.getVideoTracks()[0]);
const imageUrl = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = imageUrl;
link.download = 'screen.png';
link.click();
// Keep the URL alive long enough for the browser to start the download.
setTimeout(() => URL.revokeObjectURL(imageUrl), 1000);
} catch (error) {
status.textContent = error.message;
}
});
Add a button with id="capture" to the earlier markup. The example exports PNG; passing image/jpeg or image/webp to captureStill() requests another format, subject to browser encoding support. For JPEG, the canvas’s transparent pixels are flattened by the encoder, so draw a background first if the result needs a particular color.
Rank #2
- Compatible with Nintendo Switch 2’s new GameChat mode
- Auto-Light Balance: RightLight boosts brightness by up to 50%, reducing shadows so you look your best—compared to previous-generation Logitech webcams (1)
- Privacy with a Slide: The integrated webcam cover makes it easy to get total, reliable privacy when you're not on a video call
- Built-In Mic: The built-in microphone lets others hear you clearly during video calls
- Easy Plug-And-Play: The Brio 101 works with most video calling platforms, including Microsoft Teams, Zoom and Google Meet—no hassle; it just works
Canvas alternative when ImageCapture is unavailable
If the browser does not expose ImageCapture, you can draw the current preview frame to a canvas after its video metadata has loaded. Ensure the video has a current frame and nonzero dimensions before exporting.
Recommended Free Tools
function frameFromVideo(video) {
if (video.readyState < HTMLMediaElement.HAVE_CURRENT_DATA ||
!video.videoWidth || !video.videoHeight) {
throw new Error('The screen preview has no frame yet.');
}
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext('2d').drawImage(video, 0, 0);
return new Promise((resolve, reject) => {
canvas.toBlob(blob => blob ? resolve(blob) : reject(new Error('Image export failed.')), 'image/png');
});
}
Use the live stream for recording or a call
Record locally with MediaRecorder
Construct a recorder from the returned stream, collect its data chunks, and stop it when sharing ends. Recording format support varies, so test MediaRecorder.isTypeSupported() before choosing an explicit MIME type. The MediaStream Recording API guide covers the browser recording model.
const preferredType = 'video/webm;codecs=vp9';
const options = MediaRecorder.isTypeSupported(preferredType)
? { mimeType: preferredType }
: {};
const recorder = new MediaRecorder(screenStream, options);
const chunks = [];
recorder.addEventListener('dataavailable', event => {
if (event.data.size) chunks.push(event.data);
});
recorder.addEventListener('stop', () => {
const blob = new Blob(chunks, { type: recorder.mimeType || 'video/webm' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'screen-recording.webm';
link.click();
setTimeout(() => URL.revokeObjectURL(url), 1000);
});
recorder.start();
// Later, when the user stops recording:
recorder.stop();
For a real recording interface, wire stop handling to your UI and the video track’s ended event, and avoid calling stop() twice on an inactive recorder. Large or long recordings consume memory if all chunks are retained in the page until the end; consider a design that handles chunks incrementally when your application needs longer sessions.
Rank #3
- 1080P HD Webcam: This HD webcam delivers crisp 1080p video quality, ideal for PCs, desktops, and laptops. Perfect for video calls, online classes, meetings, live streaming, gaming, and everyday recording. It provides clear, sharp images and smooth video at up to 30 frames per second. This live streaming webcam works with platforms such as Zoom, Teams, FaceTime, Google Meet, and YouTube.
- USB Plug and Play Webcam: Designed for PCs, this webcam is easy to use. No drivers or software are required; simply connect the webcam to your computer and start using it immediately. Operation is smooth and convenient. XWEIRYN webcams are compatible with multiple operating systems, including Mac/Windows XP/7/8/10/11/PC/Laptops.
- Widely Compatible Webcam: This versatile webcam is compatible with most operating systems and major video platforms. As a reliable computer webcam, it supports video conferencing, remote learning, live streaming, and gaming, meeting your various needs for daily work and entertainment.
- Smooth and Stable Performance: This webcam uses a stable transmission chip to ensure smooth, lag-free video streaming, synchronized audio and video, and no dropped frames. Even after prolonged use, this durable webcam maintains stable performance. It performs excellently even in low-light environments. It automatically adjusts to adapt to low-light conditions, reducing noise and restoring vibrant colors, ensuring clear and sharp images even without additional studio lighting.
- Compact and Adjustable Design: This lightweight and portable webcam saves space and comes with an adjustable clip. Our USB webcam uses a reliable USB 2.0/3.0 connection and comes with an upgraded 1.5-meter (5-foot) braided cable. It is compatible with Desktop most monitors and Laptop. Its portable design makes it easy to place and carry, ideal for home, office, or travel use.
Send the stream through WebRTC
After consent, add the captured tracks to a peer connection. The code below shows only the media attachment; a working call also needs signaling to exchange offers, answers, and ICE candidates, plus receiver-side rendering.
const peerConnection = new RTCPeerConnection();
for (const track of screenStream.getTracks()) {
peerConnection.addTrack(track, screenStream);
}
Share only tracks the user expects to send. If a user stops sharing from the browser’s own UI, the track ends; notify the peer and update your call state accordingly. WebRTC connection setup is distinct from screen permission: obtaining a stream does not itself connect to another person.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Choose the right capture surface and API
- Full display, window, or tab:
getDisplayMedia()invokes the browser picker; the user decides which offered surface to share. - Camera or microphone: use
getUserMedia(), notgetDisplayMedia(). The latter is for display capture and does not require a camera. - Canvas contents:
HTMLCanvasElement.captureStream()creates a live stream from pixels your app has drawn to a canvas. It works in the opposite direction from display capture and does not open the screen picker. - One still image: use a captured video track with
ImageCapture.grabFrame(), or draw a ready video frame to canvas and export it. - Only a page element or region: Element Capture and Region Capture extend the screen-capture model to constrain what portion of a tab is captured in supported environments. Check support and layout behavior before making either an application requirement.
Browser support, performance, and reliability
Support is not uniform across browsers, operating systems, and capture surfaces. MDN marks getDisplayMedia() as having limited availability, and audio behavior is especially dependent on browser and selected source. Review the current compatibility data for your actual target browsers before promising a particular source or audio track; consult MDN’s compatibility information and test on the devices you support.
Rank #4
- 1080P Webcam with Cover for Video Calls - EMEET computer webcam provides design and Optimization for professional video streaming. Realistic 1920 x 1080p video, 5-layer anti-glare lens, providing smooth video. C960 computer camera delivers 1920x1080 video with fixed focus (11.8–118.1 inches), so as to provide a clearer image. C960 USB webcam has a cover and can be removed automatically to meet your needs for privacy. For optimal image performance, use the webcam in a well-lit environment.
- Built-in 2 Omnidirectional Mics - EMEET webcam with microphone for desktop features 2 built-in omnidirectional microphones, picking up your voice to create clear audio for communication. When installing the webcam, select EMEET C960 as the default microphone input device in your computer and video applications and select C960 as the default device in Zoom/Teams and ensure microphone permissions are enabled for proper use. Please note that C960 does not include built-in speakers.
- Automatic Light Adjustment - Automatic exposure adjustment is applied in EMEET HD webcam 1080p so that the streaming webcam can deliver stable image performance. EMEET C960 camera for computer also features color adjustment and exposure optimization to help you look your best. For optimal video quality, it is recommended to use the webcam in normal or well-lit environments and select suitable video settings in your application. Proper lighting helps achieve a clearer and more balanced image.
- Plug-and-Play & Upgraded USB Connectivity - New C960 webcam features both USB Type-A & A-to-C adapter connections for wider compatibility. For stable performance, connect the webcam directly to the computer's main USB port and ensure the device is recognized correctly. If a hub or docking station is used, please ensure it provides sufficient power and stable data transmission, as limited ports may affect performance. 90° wide-angle lens captures more participants without frequent adjustments.
- High Compatibility & Multi Application - C960 webcam for laptop is compatible with Windows 10/11, macOS 10.14+, and Android TV 7.0+. Not supported: Windows Hello, TVs, tablets, or game consoles. It works with Zoom, Teams, Facetime, Google Meet, YouTube and more. Please select C960 webcam as the default camera and microphone device in your application and ensure camera/microphone permissions are enabled, especially on macOS. (Tips: Incompatible with Windows Hello)
For a still screenshot, the bitmap and canvas may be large at high display resolutions. Release the ImageBitmap with close(), avoid creating unnecessary full-size copies, and revoke object URLs after use. For video, retaining every recording chunk in memory can grow expensive over time. A screen-share feature should treat permission denial, unavailable APIs, stopped tracks, and absent audio as ordinary runtime outcomes rather than exceptional impossibilities.
Troubleshooting common failures
navigator.mediaDevicesorgetDisplayMediais undefined: Check that the page is served from a secure context and that the browser supports screen capture. Test against the browser/version matrix you intend to support.- The call throws
NotAllowedError: The user may have cancelled or denied the picker, or policy may block capture. Present a non-alarming status and allow them to try again with a new button click. - The call fails with
InvalidStateError: The request may not have been made during transient user activation. Invoke it directly in the click or key action rather than after a timer or an awaited setup step. - An iframe cannot start capture: Inspect the top-level page’s Permissions Policy and delegate
display-capturewhere appropriate. Also check any restrictive response headers. - Audio is missing: A requested audio track is not guaranteed. Check available tracks and design the feature to continue with video alone.
- The still image is blank or too small: Wait for a live video frame or use
grabFrame()on a live video track. With the video-to-canvas method, wait for loaded data and usevideoWidth/videoHeight, not CSS display dimensions. - Recording construction fails: Avoid assuming one MIME type is supported. Test
MediaRecorder.isTypeSupported()and let the browser select a default when the preferred type is unsupported. - Capture continues after the UI says it stopped: Stop every stream track, clear the preview’s
srcObject, and listen for the track’sendedevent so browser-initiated stopping updates the application.
Or skip the browser setup
If your goal is a screenshot of a public webpage rather than a user-selected screen, use ScreenshotNeo’s website screenshot API instead of asking the visitor to grant display capture. One GET request returns an image or PDF; the following cURL example saves a WebP screenshot. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchSign up for 1,000 free screenshots a month—no card required.
Best Value
Frequently Asked Questions
Can a website capture a visitor’s screen without asking?
No. The browser’s display-capture picker requires a fresh user choice for each request; a site cannot silently reuse a prior screen-capture grant.
Does getDisplayMedia capture a camera?
No. It requests a user-selected display surface. Camera and microphone capture use the separate getUserMedia() API.
Does requesting audio guarantee screen audio?
No. Whether audio is available depends on browser, operating system, and selected surface, so check the returned stream’s audio tracks.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




