1

Could I possibly close the native screen picker of getDisplayMedia({video:true}) without selecting an application to share? As far as I know, it automatically closes on track.stop() if a track being shared is stopped. However, there is an instance that I need to close the native screen picker without pressing cancel or selecting an application to share.

Screen Picker Img

jib
  • 34,243
  • 11
  • 80
  • 138
Chowder
  • 41
  • 2
  • 9

1 Answers1

1

Refresh the page:

window.location = window.location.href;

This will tear down this otherwise sticky prompt in all browsers.

In Chrome, the prompt is modal, but this demo using a timeout works for me:

const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

button.onclick = async () => {
  const stream = await Promise.race([
    navigator.mediaDevices.getDisplayMedia({video: true}),
    wait(5000)
  ]);
  if (!stream) {
    window.location = window.location.href;
  }
  video.srcObject = stream;

Of course, this risks tearing away the picker while the user is using it.

jib
  • 34,243
  • 11
  • 80
  • 138
  • This is actually helpful. But sadly in our case, we need to close the picker without having to reload the page. I was thinking if there was an event to be fired for this but I can't find anything on its documentation. – Chowder Nov 16 '19 at 05:44
  • @TheChosenOne Is it an option to put the request in an iframe? Then you'd only need to refresh that iframe, not your whole page. – jib Nov 17 '19 at 14:41