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
MediaDevices.getDisplayMedia() (en-US), whose job is to ask the user to select a screen or portion of a screen to capture in the form of a
To start capturing video from the screen, you call
getDisplayMedia() on the instance of
captureStream = await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
Promise returned by
getDisplayMedia() resolves to a
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.
Additions to existing interfaces
The Screen Capture API doesn't have any interfaces of its own; instead, it adds one method to the existing
getDisplayMedia()method is added to the
MediaDevicesinterface. Similar to
getUserMedia(), this method creates a promise that resolves with a
MediaStreamcontaining the display area selected by the user, in a format that matches the specified options.
Additions to existing dictionaries
The Screen Capture API adds properties to the following dictionaries defined by other specifications.
ConstrainDOMString(en-US) indicating whether or not the cursor should be included in the captured display surface's stream, and if it should always be visible or if it should only be visible while the mouse is in motion.
ConstrainDOMString(en-US) indicating what type of display surface is to be captured. The value is one of
Indicates whether or not the video in the stream represents a logical display surface (that is, one which may not be entirely visible onscreen, or may be completely offscreen). A value of
trueindicates a logical display surface is to be captured.
A string which indicates whether or not the display surface currently being captured includes the mouse cursor, and if so, whether it's only visible while the mouse is in motion or if it's always visible. The value is one of
A string indicating what type of display surface is currently being captured. The value is one of
A Boolean value which is
trueif the video being captured doesn't directly correspond to a single onscreen display area.
A Boolean which is
trueif the user agent and device support the
A Boolean which is
trueif the current environment supports the
A Boolean which is
trueif the current environment supports the constraint
The following dictionaries are defined by the Screen Capture API.
An enumerated string type used to provide the value for the
cursorproperty for the settings and constraints. The possible values are
An enumerated string type which is used to identify the kind of display surface to capture. This type is used for the
displaySurfaceproperty in the constraints and settings objects, and has the possible values
Feature Policy validation
User agents that support Feature Policy (either using HTTP's
Feature-Policy (en-US) header or the
<iframe> (en-US) attribute
allow (en-US)) can specify a desire to use the Screen Capture API using the policy control directive
<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.
|Screen Capture||Рабочий черновик||Initial definition|
BCD tables only load in the browser