13

Adding displaySurface does not provoke option restriction for the user before sharing his own screen. I am trying to limit those options to only let the user select anything except browser tabs.ss

I tried setting displaySurface explicitly to 'monitor' and still all options being showed up.

async startCaptureMD() {
  let captureStream = null;
  var screen_constraints = {
     video: {
        cursor: "always",
        displaySurface: "monitor"
     }
  };
  try{
     captureStream = await 
     navigator.mediaDevices.getDisplayMedia(screen_constraints);
  }catch(err){
    console.log(err.message, err.code);
  }
  return captureStream;
},

The expected result is to show 'Your Entire Screen' or 'Application Window' and not 'Chrome Tab'.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
mohamed tebry
  • 161
  • 2
  • 11

1 Answers1

11

You can't. The MDN docs explain that it is for security:

Constraints never cause changes to the list of sources available for capture by the Screen Sharing API. This ensures that web applications can't force the user to share specific content by restricting the source list until only one item is left.

The spec says:

The user agent MUST let the end-user choose which display surface to share out of all available choices every time, and MUST NOT use constraints to limit that choice.

So the browser is doing the right thing. It seems displaySurface is an output value only. If you already have a MediaStreamTrack to call getSettings() on, then you can read displaySurface.

I also was confused, so I fixed the MDN docs. The MDN docs need updating to not list displaySurface as "A string (or array of strings) indicating what type or types of screen surface to allow the user to select".

Graham King
  • 5,710
  • 3
  • 25
  • 23
  • 3
    Very weird, why would someone would use/read such output value ? otherwise we want to restrict some screens before end-user tries to select since for example when you try to open a terminal/cmd instance with multiple tabs and you choose a single tab for your share screen viewer and you try to switch between tabs the screen goes black. So i would preferably choose to eliminate such behavior by restricting some choices instead. Anyway thanks for pointing that out ! – mohamed tebry Aug 24 '19 at 00:53
  • 10
    How does Google Meet do this then? (meet.google.com) – Yousef Amar Aug 24 '20 at 22:48
  • 6
    @YousefAmar Google Chrome is shipped with a hidden extension named "Google Hangouts" which only works on Google domains. Google Meet uses that extension. The extension itself uses this to achieve that: https://developer.chrome.com/extensions/desktopCapture#method-chooseDesktopMedia – AlicanC Oct 01 '20 at 07:54
  • 4
    @AlicanC Thanks, I found that out [here](https://stackoverflow.com/q/63658198/1477456). Isn't this incredibly anti-competitive though? How is Google getting away with it? Doesn't seem like anyone's saying anything about it – Yousef Amar Oct 02 '20 at 08:26
  • 3
    @YousefAmar it is. I actually brought this up, but didn't get an answer: https://twitter.com/AlicanC/status/1314280197546545154 – AlicanC Oct 10 '20 at 12:27
  • 2
    Is there a way to change what is shown at default then? Still allowing the user to have choice? – Charles Harring Nov 06 '20 at 04:06
  • 2
    Would like to know too – eroy4u May 31 '21 at 08:18