| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-CN/docs/Web/API/Screen_Capture_API | [Back] [Original] |
Get to know MDN better
API MediaDevices.getDisplayMedia()MediaStream
getDisplayMedia() 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.
API MediaDevices
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.
The Screen Capture API adds properties to the following dictionaries defined by other specifications.
MediaTrackConstraints.cursorA 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.displaySurfaceA ConstrainDOMString indicating what type of display surface is to be captured. The value is one of application, browser, monitor, or window.
MediaTrackConstraints.logicalSurfaceIndicates 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.cursorA 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.displaySurfaceA string indicating what type of display surface is currently being captured. The value is one of application, browser, monitor, or window.
MediaTrackSettings.logicalSurfaceA Boolean value which is true if the video being captured doesn't directly correspond to a single onscreen display area.
MediaTrackSupportedConstraints.cursorA Boolean which is true if the user agent and device support the MediaTrackConstraints.cursor constraint.
MediaTrackSupportedConstraints.displaySurfaceA Boolean which is true if the current environment supports the MediaTrackConstraints.displaySurface constraint.
MediaTrackSupportedConstraints.logicalSurfaceA Boolean which is true if the current environment supports the constraint MediaTrackConstraints.logicalSurface.
The following dictionaries are defined by the Screen Capture API.
CursorCaptureConstraintAn 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.
DisplayCaptureSurfaceTypeAn 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.
User agents that support Feature Policy (either using HTTP's Permissions-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"></iframe>
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 |
| Element Capture |
| Region Capture |
| Captured Surface Control |
MediaTrackConstraints.displaySurfaceMediaTrackConstraints.logicalSurfaceMediaTrackConstraints.suppressLocalAudioPlaybackMediaTrackSettings.cursorMediaTrackSettings.displaySurfaceMediaTrackSettings.logicalSurfaceMediaTrackSettings.suppressLocalAudioPlaybackMediaTrackSupportedConstraints.displaySurfaceMediaTrackSupportedConstraints.logicalSurfaceMediaTrackSupportedConstraints.suppressLocalAudioPlayback| Web Proxy Viewer | New URL | Original Page |