When getDisplayMedia()
is called, the browser offers the user a choice of display surfaces: tabs, windows, or monitors (entire screens). Using the monitorTypeSurfaces
option, the web application may now hint to the browser if it prefers to include display surfaces whose type is monitor among the choices offered to the user. The browser may still ignore this hint. Web applications are therefore encouraged to still check the displaySurface setting of the tracks they receive.
- Protect the user from the pitfall of choosing a source which the app will reject eventually.
- Protect companies from leakage of private information through employee-error.
// Hint the browser to exclude monitors (entire screens) from the choices offered to the user.
const stream = await navigator.mediaDevices.getDisplayMedia({
monitorTypeSurfaces: "exclude",
});
// We still need to check though...
const { displaySurface } = stream.getTracks()[0].getSettings();
if (displaySurface == "monitor") {
throw new Error('User has picked a monitor.');
}