无法将值转换为 MediaStream

Failed to convert value to MediaStream

我正在尝试实现屏幕捕获 API https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API/Using_Screen_Capture#capturing_screen_contents

我正在 React JS 中构建相同的代码,

当我放置以下代码时出现错误 “无法在 'HTMLMediaElement' 上设置 'srcObject' 属性:无法将值转换为 'MediaStream'."

<video id="video"></video>
video = document.getElementById("video");
video.srcObject = navigator.mediaDevices.getDisplayMedia(displayMediaOptions);```


Please someone help in resolving this issue

HTML

<video id="video"></video>

JS

video = document.getElementById("video");
 
async function startCapture() {
  

  try {
    video.srcObject = await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
  } catch(err) {
    console.error("Error: " + err);
  }
  return captureStream;
}
startCapture()