Is it possible to tell the browser not to focus (bring to front) the selected window from `getDisplayMedia`?
Asked Answered
R

2

6

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.)

Rosario answered 11/2, 2020 at 16:0 Comment(2)
I read the entire documentation for the MediaDevices.getDisplayMedia and the MediaStreamContraints. I see nothing about stopping the window from focusing on top. Looks like this is probably a feature request to add this to the constraints.Horripilate
Also there doesnt seem to be anything in the list of all supported contraintsHorripilate
A
2

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:

Arsenical answered 16/5, 2023 at 15:16 Comment(0)
D
2

No, it is generally not possible to change this behavior, since it is intentional.

While this behavior is not mandated by any specification, most browsers today will push a just-shared window to front.

The rationale is the typical use case is someone presenting a document in a web conference call. In that context, the assumption is that since this is a user-initiated action (it requires a user gesture), the user intends to interact with the surface that they just shared.

In the past, browsers used to not do this, and users got confused about what was happening and about which window was being shared.

If you have a compelling use case where this is problematic, consider describing it in a new issue on the specification.

Daciadacie answered 22/4, 2020 at 19:10 Comment(0)
A
2

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:

Arsenical answered 16/5, 2023 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.