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 main 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 display surface.

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.

Screen capture extensions

The Screen Capture API has additional features that extend its capabilities:

Limiting the screen area captured in the stream

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

Controlling the captured screen area

The Captured Surface Control API allows the capturing application to provide limited control over the captured display surface, for example zooming and scrolling its contents.

See Using the Captured Surface Control API 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

Security considerations

Websites 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 {{HTTPHeader("Permissions-Policy/display-capture", "display-capture")}} :

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

A site can also specify a desire to use the Captured Surface Control API via the {{HTTPHeader("Permissions-Policy/captured-surface-control", "captured-surface-control")}}  directive. Specifically, the {{domxref("CaptureController.forwardWheel", "forwardWheel()")}} , {{domxref("CaptureController.increaseZoomLevel", "increaseZoomLevel()")}} , {{domxref("CaptureController.decreaseZoomLevel", "decreaseZoomLevel()")}} , and {{domxref("CaptureController.resetZoomLevel", "resetZoomLevel()")}}  methods are controlled by this directive.

The default allowlist for both directives is self, which permits any content within the same origin use Screen Capture.

These methods are considered powerful features, which means that even if permission is allowed via a Permissions-Policy, the user will still be prompted for permission to use them. The Permissions API can be used to query the aggregate permission (from both the website and the user) for using the listed features.

In addition, the specification requires that a user has recently interacted with the page to use these features — this means that transient activation is required. See the individual method pages for more details.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN