When an application calls getDisplayMedia(), and the user chooses to capture a tab, Chrome displays an tab-capture infobar right below the omnibar. When a tab other than the capturing/captured tab is focused, the only button in this infobar is [Stop sharing].
If using the Extension API for screen-sharing, another button is exposed - [Share this tab instead].
Pressing this button changes the target of the tab-capture to the other tab.
We now expose this functionality to the Web at large. Web applications can control whether this button is shown by specifying a value to DisplayMediaStreamConstraints.surfaceSwitching
.
The [Share this tab instead] button allows users to seamlessly switch which tab they’re sharing, without having to select the video-conferencing tab again (1), click a button to initiate getDisplayMedia() again (2), and selecting a new tab out of a long list of tabs again (3).
This behavior is exposed conditionally because not all Web applications are able to handle this behavior. Most notably, applications centered around self-capture and cropping might have trouble. For a more elaborate discussion, see this GitHub thread.
const stream = await navigator.mediaDevices.getDisplayMedia({
video: true,
surfaceSwitching: "include" // Or exclude.
});
Chrome will try to guess what’s best for your application. This guess may change between milestones. Initially:
- If the user chooses the current tab, the [Share this tab instead] button will not be exposed.
- If the user chooses any other tab, the [Share this tab instead] button will be exposed.
At the moment, Chrome only supports fast-switching between shared tabs. In the future, hopefully more.