Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Media Capture API in Microsoft Edge: Screen Recording

· 6 min read · Home Tech

In this article
  1. Background: How Screen Capture Came to the Browser
  2. How the Media Capture API Works in Edge
  3. Practical Uses: Recording and Streaming
  4. Choosing the Right Capture Options
  5. Common Problems and How to Fix Them
  6. Security and Privacy Considerations
  7. Alternatives to the Media Capture API
  8. Frequently Asked Questions

The Media Capture API in Microsoft Edge lets you record your screen, a specific window, or a browser tab directly from a web page, without installing separate software. You use the getDisplayMedia() method in JavaScript to prompt the user to choose what to share, and then capture the resulting video stream for recording or streaming. This article explains how this works, what you can do with it, and what limitations you should know about.

Background: How Screen Capture Came to the Browser

For years, recording your screen meant installing a desktop application like OBS Studio or using a built-in tool like the Xbox Game Bar. But web developers wanted the same capability inside the browser, especially for video conferencing, remote collaboration, and interactive tutorials. The Screen Capture specification (part of the broader Media Capture and Streams API) was developed by the W3C and implemented in all major browsers, including Microsoft Edge. The core method is getDisplayMedia(), which returns a promise that resolves to a MediaStream containing the screen video and optionally audio.

Edge, being built on the Chromium engine, supports this API alongside Chrome, Firefox, and Safari (with some differences). The API is designed to be secure: it only works on HTTPS pages (or localhost) and always requires the user to explicitly grant permission by selecting what to share. This is a privacy safeguard, so a website cannot silently record your screen.

How the Media Capture API Works in Edge

To capture the screen, you call navigator.mediaDevices.getDisplayMedia(). Here is a minimal example:

async function startCapture() {
  const stream = await navigator.mediaDevices.getDisplayMedia({
    video: true,
    audio: true
  });
  // Use the stream, e.g., attach to a video element
  const video = document.querySelector('video');
  video.srcObject = stream;
}

When this code runs, Edge shows a permission prompt where the user picks one of the following sources:

  • The entire screen (all displays)
  • A single window (e.g., another browser window or an application)
  • A browser tab (only in Chrome and Edge, not in Firefox or Safari)

The user can also choose to share audio (e.g., system sound) and, in some cases, a separate microphone. Once the user selects a source, the promise resolves with a MediaStream that can be:

  • Displayed in a <video> element for preview
  • Recorded using the MediaRecorder API to produce a video file (e.g., WebM)
  • Sent to a remote peer via WebRTC for video conferencing

To stop capturing, you call stream.getTracks().forEach(track => track.stop()) or the user clicks the “Stop sharing” button that appears in the browser UI.

Practical Uses: Recording and Streaming

The most common use is to record a screen for a tutorial or demo. You can combine getDisplayMedia() with the MediaRecorder API to save the stream to a file. Here is a simple recording snippet:

const recorder = new MediaRecorder(stream);
const chunks = [];
recorder.ondataavailable = e => chunks.push(e.data);
recorder.onstop = () => {
  const blob = new Blob(chunks, { type: 'video/webm' });
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = 'recording.webm';
  a.click();
};
recorder.start();
// Later...
recorder.stop();

This creates a WebM video file. For video conferencing, you can add the screen stream to an RTCPeerConnection to share your screen with others, as done in platforms like Google Meet or Microsoft Teams (though those use their own implementations).

Choosing the Right Capture Options

When calling getDisplayMedia(), you can pass a constraints object to control the capture:

  • video: true or { displaySurface: 'window' } to prefer a window over the whole screen.
  • audio: true to request system audio (if supported).
  • preferCurrentTab (in Chrome/Edge) to hint that the current tab should be the default selection.

You cannot force the user to choose a specific source—the browser always shows a prompt. However, you can use the displaySurface hint to influence which tab is highlighted. For example, { video: { displaySurface: 'tab' } } makes the tab option the default. The user still has the final say.

Common Problems and How to Fix Them

Several issues can arise when using the Media Capture API in Edge:

  • Permission denied: If the user clicks “Cancel” or selects “Share” but then denies, the promise rejects with a NotAllowedError. Handle this with a try/catch and show a message like “Screen capture was cancelled.”
  • No audio: System audio capture is not supported on all platforms. In Edge on Windows, it works, but on Linux or macOS, it may be unavailable. Check stream.getAudioTracks().length and inform the user if no audio is captured.
  • Black screen: Some content (e.g., DRM-protected video) may appear black in the capture. This is intentional to protect copyrighted material. You cannot work around it.
  • Capture stops unexpectedly: The user can stop sharing from the browser UI. Listen for the track.onended event to detect this and update your UI accordingly.

If the promise never resolves, check that the page is served over HTTPS (or localhost) and that the browser is up-to-date.

Security and Privacy Considerations

The Media Capture API is designed with privacy in mind. The user must always give explicit consent via the prompt; there is no way for a website to bypass it. Additionally, the browser shows a clear indicator (a red “recording” badge) while the screen is being captured. As a developer, you should:

  • Only request capture when the user initiates an action (e.g., clicking a “Start recording” button).
  • Stop the capture immediately when the user leaves the page or cancels.
  • Never store or transmit the captured stream without the user’s knowledge.

Also, note that the API cannot capture the screen of another tab without the user’s explicit selection—the browser prevents cross-tab capture without consent.

Alternatives to the Media Capture API

If you need more advanced features (e.g., editing, overlays, or multi-track recording), you might consider:

  • Desktop apps: OBS Studio, Camtasia, or Screen Recorder for Windows offer more control and are not limited to a browser tab.
  • Browser extensions: Some extensions use the same API but provide a UI and additional features. However, they still rely on getDisplayMedia().
  • WebRTC for streaming: If you want to broadcast your screen live, you can use WebRTC to send the stream to a server or peer, rather than recording locally.

For simple use cases, the built-in browser API is sufficient and lightweight, requiring no external dependencies.

Frequently Asked Questions

Can I capture a specific tab without the user choosing it?

No. For security, the user must always select the tab from the prompt. You can use the preferCurrentTab hint to make the current tab the default, but the user can still change it.

Why is the captured video black when I record Netflix or Hulu?

DRM-protected content (like most streaming services) is blocked from screen capture to prevent piracy. The browser intentionally leaves the video track black or empty. There is no legitimate workaround.

Does the Media Capture API work on mobile Edge?

On Android, getDisplayMedia() is supported in Chrome and Edge, but the user experience may differ. On iOS, Safari does not support it, and Edge on iOS uses WebKit, so it also lacks support. For mobile, consider using native APIs or a different approach.

Can I record the screen and microphone at the same time?

Yes. You can combine the screen stream with a microphone stream using MediaStream.addTrack() or by using getUserMedia() for the mic and then mixing the tracks before recording. The MediaRecorder can handle multiple tracks.

What file format does the MediaRecorder produce?

In Edge, the default is WebM (VP8/VP9 video with Opus audio). You can specify a different MIME type if supported, such as video/mp4, but support varies. You may need to convert the file after recording for broader compatibility.

Is there a way to capture the screen without a user prompt?

No. The prompt is mandatory by design. If you need to capture the screen automatically (e.g., for a kiosk app), you would need to build a native application or use a browser extension with elevated privileges, which is not possible with standard web APIs.