files/en-us/web/api/screen_capture_api/index.md
{{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.
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.
The Screen Capture API has additional features that extend its capabilities:
See Using the Element Capture and Region Capture APIs to learn more.
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.
CaptureController object is associated with a captured display surface by passing it into a getDisplayMedia() call as the value of the options object's controller property.getDisplayMedia() method is added to the MediaDevices interface. Similar to {{domxref("MediaDevices.getUserMedia", "getUserMedia()")}}, this method creates a promise that resolves with a {{domxref("MediaStream")}} containing the display area selected by the user, in a format that matches the specified options.The Screen Capture API adds properties to the following dictionaries defined by other specifications.
ConstrainDOMString indicating what type of display surface is to be captured. The value is one of browser, monitor, or window.true indicates a logical display surface is to be captured.true indicates that it will be suppressed.always, motion, or never.browser, monitor, or window.true if the video being captured doesn't directly correspond to a single onscreen display area.true if the audio being captured is not played out of the user's local speakers.true if the current environment supports the {{domxref("MediaTrackConstraints.displaySurface")}} constraint.true if the current environment supports the constraint {{domxref("MediaTrackConstraints.logicalSurface")}}.true if the current environment supports the constraint {{domxref("MediaTrackConstraints.suppressLocalAudioPlayback")}}.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}}
{{Compat}}