MediaDevices: getDisplayMedia() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The getDisplayMedia() method of the MediaDevices interface prompts the user to select and grant permission to capture the contents of a display or portion thereof (such as a window) as a MediaStream.

The resulting stream can then be recorded using the MediaStream Recording API or transmitted as part of a WebRTC session.

See Using the Screen Capture API for more details and an example.

Syntax

js
getDisplayMedia()
getDisplayMedia(options)

Parameters

options Optional

An object specifying requirements for the returned MediaStream. The options for getDisplayMedia() work in the same as the constraints for the MediaDevices.getUserMedia() method, although in that case only audio and video can be specified. The list of possible option properties for getDisplayMedia() is as follows:

video Optional

A boolean or a MediaTrackConstraints instance; the default value is true. If this option is omitted or set to true, the returned MediaStream will contain a video track. Since getDisplayMedia() requires a video track, if this option is set to false the promise will reject with a TypeError.

audio Optional

A boolean or a MediaTrackConstraints instance; the default value is false. A value of true indicates that the returned MediaStream will contain an audio track, if audio is supported and available for the display surface chosen by the user.

controller Optional

A CaptureController object instance containing methods that can be used to further manipulate the capture session if included.

monitorTypeSurfaces Optional

An enumerated value specifying whether the browser should offer entire screens in the screen capture options presented to the user alongside tab and window options. This option is intended to protect companies from leakage of private information through employee error when using video conferencing apps. Possible values are:

  • include: Hints that the browser should include screen options.
  • exclude: Hints that screen options should be excluded.

Note: You cannot set monitorTypeSurfaces: "exclude" at the same time as displaySurface: "monitor" as the two settings are contradictory. Trying to do so will result in the getDisplayMedia() call failing with a TypeError.

preferCurrentTab Optional

A boolean; a value of true instructs the browser to offer the current tab as the most prominent capture source, that is, as a separate "This Tab" option in the "Choose what to share" options presented to the user. This is useful as many app types generally just want to share the current tab. For example, a slide deck app might want to let the user stream the current tab containing the presentation to a virtual conference.

selfBrowserSurface Optional

An enumerated value specifying whether the browser should allow the user to select the current tab for capture. This helps to avoid the "infinite hall of mirrors" effect experienced when a video conferencing app inadvertently shares its own display. Possible values are:

  • include: Hints that the browser should include the current tab in the choices offered for capture.
  • exclude: Hints that the current tab should be excluded from the choices.
surfaceSwitching Optional

An enumerated value specifying whether the browser should display a control to allow the user to dynamically switch the shared tab during screen-sharing. This is more convenient than having to go through the whole sharing process again each time a user wants to switch the shared tab. Possible values are:

  • include: Hints that the browser should include the control.
  • exclude: Hints that the control should not be shown.
systemAudio Optional

An enumerated value specifying whether the browser should include the system audio among the possible audio sources offered to the user. Possible values are:

  • include: Hints that the browser should include the system audio in the list of choices.
  • exclude: Hints that system audio should be excluded from the choices shown.
windowAudio Optional

An enumerated value that hints to the browser what audio sharing option the user should be presented with alongside window sharing options. Possible values are:

  • exclude: Hints that audio should not be shareable when a window sharing option is chosen.
  • window: Hints that when a window sharing option is chosen, only audio originating from that window should be shared.
  • system: Hints that when a window sharing option is chosen, all system audio should be shared.

Note: For most of these options, a default value is not mandated by the spec. For standalone options, where a default is not mentioned, see the Browser compatibility section for browser-specific defaults.

Note: See the article Capabilities, constraints, and settings for a lot more detail on how these options work.

Return value

A Promise that resolves to a MediaStream containing a video track whose contents come from a user-selected screen area, as well as an optional audio track.

Note: Browser support for audio tracks varies, both in terms of whether or not they're supported at all by the media recorder and in terms of the audio sources supported. Check the compatibility table for details for each browser.

Exceptions

AbortError DOMException

Thrown if an error or failure does not match any of the other exceptions listed here.

InvalidStateError DOMException

Thrown if the call to getDisplayMedia() was not made from code running due to a transient activation, such as an event handler. Or if the browser context is not fully active or does not focused. Or if the controller options has been already used in creating another MediaStream.

NotAllowedError DOMException

Thrown if the permission to access a screen area was denied by the user, or the current browsing instance is not permitted access to screen sharing (for example by a Permissions Policy).

NotFoundError DOMException

Thrown if no sources of screen video are available for capture.

NotReadableError DOMException

Thrown if the user selected a screen, window, tab, or another source of screen data, but a hardware or operating system level error or lockout occurred, preventing the sharing of the selected source.

OverconstrainedError DOMException

Thrown if, after creating the stream, applying any specified constraints fails because no compatible stream could be generated.

TypeError

Thrown if the specified options include values that are not permitted when calling getDisplayMedia(), for example a video property set to false, or if any specified MediaTrackConstraints are not permitted. min and exact values are not permitted in constraints used in getDisplayMedia() calls.

Security

Because getDisplayMedia() could be used in nefarious ways, it can be a source of significant privacy and security concerns. For that reason, the specification details measures browsers are required to take in order to fully support getDisplayMedia().

  • The specified options can't be used to limit the choices available to the user. Instead, they must be applied after the user chooses a source, in order to generate output that matches the options.
  • The go-ahead permission to use getDisplayMedia() cannot be persisted for reuse. The user must be prompted for permission every time.
  • Transient user activation is required. The user has to interact with the page or a UI element in order for this feature to work.
  • Browsers are encouraged to provide a warning to users about sharing displays or windows that contain browsers, and to keep a close eye on what other content might be getting captured and shown to other users.

Examples

In the example below a startCapture() method is created, which initiates screen capture given a set of options specified by the displayMediaOptions parameter.

js
const displayMediaOptions = {
  video: {
    displaySurface: "browser",
  },
  audio: {
    suppressLocalAudioPlayback: false,
  },
  preferCurrentTab: false,
  selfBrowserSurface: "exclude",
  systemAudio: "include",
  surfaceSwitching: "include",
  monitorTypeSurfaces: "include",
};

async function startCapture(displayMediaOptions) {
  let captureStream;

  try {
    captureStream =
      await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
  } catch (err) {
    console.error(`Error: ${err}`);
  }
  return captureStream;
}

This uses await to asynchronously wait for getDisplayMedia() to resolve with a MediaStream which contains the display contents as requested by the specified options. The stream is then returned to the caller for use, perhaps for adding to a WebRTC call using RTCPeerConnection.addTrack() to add the video track from the stream.

Note: The Screen sharing controls demo provides a complete implementation that allows you to create a screen capture with your choice of getDisplayMedia() constraints and options.

Specifications

Specification
Screen Capture
# dom-mediadevices-getdisplaymedia

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
getDisplayMedia()
Chrome – Full support
Chrome 72 (Release date: 2019-01-29)
footnote Full support
Edge – Partial support
Edge 17 – 18 (Release date: 2018-04-30)
footnote Partial support
footnote Available as a member of Navigator instead of MediaDevices.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox 33 – 65 (Release date: 2014-10-14)
footnote Since Firefox 33 you can capture screen data using getUserMedia(), with a video constraint called mediaSource. Before 52 it relied on a client-configurable list of allowed sites.
Firefox – Full support
Firefox 66 (Release date: 2019-03-19)
footnote Full support
Opera – Full support
Opera 60 (Release date: 2019-04-09)
footnote Full support
Safari – Full support
Safari 13 (Release date: 2019-09-19)
footnote Full support
Chrome Android – No support
Chrome Android
footnote
footnote From Chrome Android 72 to 88, this method was exposed, but always failed with NotAllowedError. See bug 40418135.
Firefox for Android – No support
Firefox for Android
footnote
footnote From Firefox Android 66 to 79, this method was exposed, but always failed with NotAllowedError.
Opera Android – No support
Opera Android
footnote
footnote From Opera Android 51 to 88, this method was exposed, but always failed with NotAllowedError. See bug 40418135.
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote
footnote From Samsung Internet 11.0 to 88, this method was exposed, but always failed with NotAllowedError. See bug 40418135.
WebView Android – No support
WebView Android
footnote
footnote From WebView Android 72 to 88, this method was exposed, but always failed with NotAllowedError. See bug 40418135.
WebView on iOS – No support
WebView on iOS
footnote No support
Audio capture support
Chrome – Full support
Chrome 74 (Release date: 2019-04-23)
footnote
footnote On Windows and ChromeOS, the entire system audio can be captured when sharing an entire screen. On Linux and macOS, only the audio of a tab can be captured.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote On Windows and ChromeOS, the entire system audio can be captured when sharing an entire screen. On Linux and macOS, only the audio of a tab can be captured.
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 62 (Release date: 2019-06-27)
footnote
footnote On Windows and ChromeOS, the entire system audio can be captured when sharing an entire screen. On Linux and macOS, only the audio of a tab can be captured.
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
controller option
Experimental
Chrome – Full support
Chrome 109 (Release date: 2023-01-10)
footnote Full support
Edge – Full support
Edge 109 (Release date: 2023-01-12)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 95 (Release date: 2023-02-01)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
monitorTypeSurfaces option
Experimental
Chrome – Full support
Chrome 119 (Release date: 2023-10-31)
footnote
footnote Default value = include
Edge – Full support
Edge 119 (Release date: 2023-11-02)
footnote
footnote Default value = include
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 105 (Release date: 2023-11-14)
footnote
footnote Default value = include
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
preferCurrentTab option
Experimental Non-standard
Chrome – Full support
Chrome 94 (Release date: 2021-09-21)
footnote
footnote Default value = false
Edge – Full support
Edge 94 (Release date: 2021-09-24)
footnote
footnote Default value = false
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 80 (Release date: 2021-10-05)
footnote
footnote Default value = false
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
selfBrowserSurface option
Experimental
Chrome – No support
Chrome 107 – 110 (Release date: 2022-10-25)
footnote Removed in 111 and later
footnote Default value = include
Chrome – Full support
Chrome 112 (Release date: 2023-04-04)
footnote
footnote Default value = exclude
Edge – No support
Edge 107 – 110 (Release date: 2022-10-27)
footnote Removed in 111 and later
footnote Default value = include
Edge – Full support
Edge 112 (Release date: 2023-04-06)
footnote
footnote Default value = exclude
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera 93 – 96 (Release date: 2022-11-17)
footnote Removed in 97 and later
footnote Default value = include
Opera – Full support
Opera 98 (Release date: 2023-04-20)
footnote
footnote Default value = exclude
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
surfaceSwitching option
Experimental
Chrome – Full support
Chrome 107 (Release date: 2022-10-25)
footnote
footnote Default value = exclude
Edge – Full support
Edge 107 (Release date: 2022-10-27)
footnote
footnote Default value = exclude
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 93 (Release date: 2022-11-17)
footnote
footnote Default value = exclude
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
systemAudio option
Experimental
Chrome – Full support
Chrome 105 (Release date: 2022-09-02)
footnote
footnote Default value = include
Edge – Full support
Edge 105 (Release date: 2022-09-01)
footnote
footnote Default value = include
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 91 (Release date: 2022-09-14)
footnote
footnote Default value = include
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
windowAudio option
Experimental
Chrome – Partial support
Chrome 141 (Release date: 2025-09-30)
footnote Partial support
footnote Defaults to "system".
footnote Only supports values "exclude" and "system", not "window".
Edge – Partial support
Edge 141 – 142 (Release date: 2025-10-03)
footnote Removed in 143 and later
footnote Partial support
footnote Defaults to "system". Before Edge 142, it defaulted to "exclude".
footnote Only supports values "exclude" and "system", not "window".
Firefox – No support
Firefox
footnote No support
Opera – Partial support
Opera 125 (Release date: 2025-12-04)
footnote Partial support
footnote Defaults to "system".
footnote Only supports values "exclude" and "system", not "window".
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
See implementation notes.
Has more compatibility info.

See also