docs.rodeo

MDN Web Docs mirror

Screen Capture API

{{DefaultAPISidebar("Screen Capture API")}} 

The Screen Capture API introduces additions to the existing Media Capture and Streams API to let the user select a screen or portion of a screen (such as a window) to capture as a media stream. This stream can then be recorded or shared with others over the network.

Screen Capture API concepts and usage

The Screen Capture API is relatively simple to use. Its sole method is {{domxref("MediaDevices.getDisplayMedia()")}} , whose job is to ask the user to select a screen or portion of a screen to capture in the form of a {{domxref("MediaStream")}} .

To start capturing video from the screen, you call getDisplayMedia() on navigator.mediaDevices:

captureStream =
  await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);

The {{jsxref("Promise")}}  returned by getDisplayMedia() resolves to a {{domxref("MediaStream")}}  which streams the captured media.

See the article Using the Screen Capture API for a more in-depth look at how to use the API to capture screen contents as a stream.

The Screen Capture API also has features that limit the part of the screen captured in the stream:

See Using the Element Capture and Region Capture APIs to learn more.

Interfaces

Additions to the MediaDevices interface

Additions to existing dictionaries

The Screen Capture API adds properties to the following dictionaries defined by other specifications.

MediaTrackConstraints

MediaTrackSettings

MediaTrackSupportedConstraints

Permissions Policy validation

{{Glossary("User agent", "User agents")}}  that support Permissions Policy (either using the HTTP {{HTTPHeader("Permissions-Policy")}}  header or the {{HTMLElement("iframe")}}  attribute allow) can specify a desire to use the Screen Capture API using the directive display-capture:

<iframe allow="display-capture" src="/some-other-document.html"></iframe>

The default allowlist is self, which lets any content within the same origin use Screen Capture.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN