I am working on an application using getDisplayMedia
. When the browser prompts me to share my screen/a window and I select a specific window to share, that window is now suddenly focused and in front of my other windows (in particular, in front of the browser window!). I tested this with Firefox and Chrome, each on Ubuntu and Windows 10. I used this page to test.
I personally find this behavior kind of unexpected and annoying. I also fear that the technically less-inclined users of my application get very confused by this. So I'd like the browser to stay focused even after selecting a window. Is it possible to change that behavior? I checked the MDN docs on getDisplayMedia
but did not find anything regarding this. I also did not find any information about this elsewhere.
If it's not possible to adjust that behavior, I'd like to know: why? Is it a technical limitation? Is it a privacy/security feature to make it more clear to the user that this window is shared now? (Personally I don't really think it helps the user but OK.)
It is now possible to do this using the CaptureController API when sharing tab content or application windows.
As of now I was not able to prevent losing focus when sharing 'monitor' in Chrome. In this case the Focus will shift to the "... is sharing your Screen [Stop sharing] Hide" modal.
const controller = new CaptureController();
controller.setFocusBehavior("no-focus-change");
const mediaStreamOptions: DisplayMediaStreamOptions = {
// ...
controller
};
navigator.mediaDevices.getDisplayMedia(mediaStreamOptions)
.then(videoStream => {
const newVideoTrack = videoStream.getVideoTracks()[0];
setVideoTrack(newVideoTrack);
}).catch(console.error);
More information about the API and its usage can be found here: