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() .

句法

isDisplaySurfaceSupported = supportedConstraints.displaySurface;
					

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

范例

This method sets up the constraints object specifying the options for the call to getDisplayMedia() . It adds the displaySurface constraint (requesting that only full-screen 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 .

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 */
  }
}
					

规范

规范 状态 注释
Screen Capture
The definition of 'MediaTrackSupportedConstraints.displaySurface' in that specification.
工作草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
displaySurface Chrome No Edge No Firefox No IE No Opera Yes Safari ? WebView Android No Chrome Android No Firefox Android No Opera Android ? Safari iOS ? Samsung Internet Android No

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: