--- title: Screen Capture API slug: Web/API/Screen_Capture_API tags: - API - Capture - Conference - Media - MediaDevices - MediaStream - NeedsTranslation - Overview - Screen Capture - Screen Capture API - Screen Sharing - Sharing - TopicStub - Video - Window - display - getDisplayMedia - screen translation_of: Web/API/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 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 the instance of Media 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 doesn't have any interfaces of its own; instead, it adds one method to the existing {{domxref("MediaDevices")}} interface.
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.
application, browser, monitor, or window.true indicates a logical display surface is to be captured.always, motion, or never.application, browser, monitor, or window.true if the video being captured doesn't directly correspond to a single onscreen display area.true if the user agent and device support the {{domxref("MediaTrackConstraints.cursor")}} constraint.true if the current environment supports the {{domxref("MediaTrackConstraints.displaySurface")}} constraint.true if the current environment supports the constraint {{domxref("MediaTrackConstraints.logicalSurface")}}.The following dictionaries are defined by the Screen Capture API.
CursorCaptureConstraintcursor property for the settings and constraints. The possible values are always, motion, and never.DisplayCaptureSurfaceTypedisplaySurface property in the constraints and settings objects, and has the possible values application, browser, monitor, and window.{{Glossary("User agent", "User agents")}} that support Feature Policy (either using HTTP's {{HTTPHeader("Feature-Policy")}} header or the {{HTMLElement("iframe")}} attribute {{htmlattrxref("allow", "iframe")}}) can specify a desire to use the Screen Capture API using the policy control directive display-capture:
<iframe allow="display-capture" src="/some-other-document.html">
The default allow list is self, which lets the any content within the document use Screen Capture.
See Using Feature Policy for a more in-depth explanation of how Feature Policy is used.
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('Screen Capture')}} | {{Spec2('Screen Capture')}} | Initial definition |
{{Compat("api.MediaDevices.getDisplayMedia")}}