Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to narrow screen sharing options like Google Meet does?

I'm using MediaDevices.getDisplayMedia() to record user's screen.

In theory, I can't narrow the choices from JS ...

The specified constraints can't be used to limit the options available to the user. Instead, they must be applied after the user chooses a source, in order to generate output that matches the constraints.

but, somehow Google Meet does it (Windows + Chrome)? But how?

enter image description here

I've tried

{
  video: {
    displaySurface: 'application' | 'browser' | 'monitor' | 'window'
  }
}

but I always get the dialog window with all the options.

I would like to have it working at least on Chrome.

like image 334
paq85 Avatar asked Oct 15 '25 16:10

paq85


1 Answers

Actually the menu you see in your post was solved by having a Chrome Extension baked right into the Chrome browser that was specifically for Google Meet (Actually it was also shipped in Edge which was quite funny). The browser getDisplayMedia API didn't allow to define constraints to the selectable sources.

However recently Chromium based browsers have introduced a new feature: You can now set the new constraint: monitorTypeSurfaces to exclude in getDisplayMedia() to disable sharing the whole screen.

const stream = await navigator.mediaDevices.getDisplayMedia({
  video: true,
  // Remove the "Entire Screen" pane in the media picker.
  monitorTypeSurfaces: "exclude",
});

You can find more details under: Chrome Blog and MDN getDisplayMedia docs

like image 51
david Avatar answered Oct 18 '25 06:10

david



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!