MediaTrackSupportedConstraints: displaySurface property

Limited availability

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

The MediaTrackSupportedConstraints dictionary's displaySurface property indicates whether or not the displaySurface constraint is supported by the user agent and the device on which the content is being used.

The supported constraints list is obtained by calling navigator.mediaDevices.getSupportedConstraints().

Value

A Boolean value which is true if the displaySurface constraint is supported by the device and user agent.

Examples

This method sets up the constraints object specifying the options for the call to getDisplayMedia(). It adds the displaySurface constraint (requesting that only fullscreen sharing be allowed) only if it is known to be supported by the browser. Capturing is then started by calling getDisplayMedia() and attaching the returned stream to the video element referenced by the variable videoElem.

js
async function capture() {
  let supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
  let displayMediaOptions = {
    video: {},
    audio: false,
  };

  if (supportedConstraints.displaySurface) {
    displayMediaOptions.video.displaySurface = "monitor";
  }

  try {
    videoElem.srcObject =
      await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
  } catch (err) {
    /* handle the error */
  }
}

Specifications

Specification
Screen Capture
# dom-mediatrackconstraintset-displaysurface

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
displaySurface constraint

Legend

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

Full support
Full support
No support
No support

See also