I want to start a screen share in my main tab by calling getDisplayMedia
, and then clone it to another popup window which I open from my app (using window.open
), effectively showing the screen capture twice, in parallel.
According to this thread, this snippet should work - but it doesn't:
async function startCapture() {
return await navigator.mediaDevices.getDisplayMedia();
}
function openPopup() {
startCapture().then((stream) => {
let video = document.getElementById("source");
video.srcObject = stream;
let popUpWindow = window.open("", "_blank", "x=y");
let videoElem = document.createElement("video");
videoElem.autoplay = true;
let remoteVideo = popUpWindow.document.body.appendChild(videoElem);
remoteVideo.srcObject = stream;
});
}
What am I missing?