CaptureController: setFocusBehavior() method
The CaptureController interface's setFocusBehavior() method controls whether the captured tab or window will be focused when an associated MediaDevices.getDisplayMedia() Promise fulfills, or whether the focus will remain with the tab containing the capturing app.
You can set this behavior multiple times before the MediaDevices.getDisplayMedia() call, or once immediately after its Promise resolves. After that, the focus behavior is said to be finalized, and can't be changed.
Syntax
setFocusBehavior(focusBehavior)
Parameters
-
focusBehavior
-
An enumerated value that describes whether the user agent should transfer focus to the captured display surface, or keep the capturing app focused. Possible values are focus-captured-surface (transfer focus) and no-focus-change (keep focus on the capturing app).
Return value
Exceptions
InvalidStateError DOMException
-
Thrown if:
- The capture stream has been stopped.
- The user chose to share a screen (
displaySurface type monitor) rather than a browser tab or window — you can't focus a monitor. In this case the exception is thrown after the MediaDevices.getDisplayMedia() Promise resolves.
- Enough time has elapsed after the
MediaDevices.getDisplayMedia() Promise fulfills that the focus behavior has been finalized.
Examples
const controller = new CaptureController();
const stream = await navigator.mediaDevices.getDisplayMedia({ controller });
const [track] = stream.getVideoTracks();
const displaySurface = track.getSettings().displaySurface;
if (displaySurface == "browser") {
controller.setFocusBehavior("focus-captured-surface");
} else if (displaySurface == "window") {
controller.setFocusBehavior("no-focus-change");
}
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
setFocusBehavior |
109 |
109 |
No |
No |
95 |
No |
No |
No |
No |
No |
No |
No |
See also