Screen Capture API - Web APIs 编辑

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(), whose job is to ask the user to select a screen or portion of a screen to capture in the form of a 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 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 MediaDevices interface.

MediaDevices interface

MediaDevices.getDisplayMedia()
The getDisplayMedia() method is added to the MediaDevices interface. Similar to getUserMedia(), this method creates a promise that resolves with a MediaStream containing 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.

MediaTrackConstraints

MediaTrackConstraints.cursor
A ConstrainDOMString 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.
MediaTrackConstraints.displaySurface
A ConstrainDOMString indicating what type of display surface is to be captured. The value is one of application, browser, monitor, or window.
MediaTrackConstraints.logicalSurface
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 true indicates a logical display surface is to be captured.

MediaTrackSettings

MediaTrackSettings.cursor
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 always, motion, or never.
MediaTrackSettings.displaySurface
A string indicating what type of display surface is currently being captured. The value is one of application, browser, monitor, or window.
MediaTrackSettings.logicalSurface
A Boolean value which is true if the video being captured doesn't directly correspond to a single onscreen display area.

MediaTrackSupportedConstraints

MediaTrackSupportedConstraints.cursor
A Boolean which is true if the user agent and device support the MediaTrackConstraints.cursor constraint.
MediaTrackSupportedConstraints.displaySurface
A Boolean which is true if the current environment supports the MediaTrackConstraints.displaySurface constraint.
MediaTrackSupportedConstraints.logicalSurface
A Boolean which is true if the current environment supports the constraint MediaTrackConstraints.logicalSurface.

Dictionaries

The following dictionaries are defined by the Screen Capture API.

CursorCaptureConstraint
An enumerated string type used to provide the value for the cursor property for the settings and constraints. The possible values are always, motion, and never.
DisplayCaptureSurfaceType
An enumerated string type which is used to identify the kind of display surface to capture. This type is used for the displaySurface property in the constraints and settings objects, and has the possible values application, browser, monitor, and window.

Feature Policy validation

User agents that support Feature Policy (either using HTTP's Feature-Policy header or the <iframe> attribute allow) 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.

Specifications

SpecificationStatusComment
Screen CaptureWorking DraftInitial definition

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:87 次

字数:9885

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文