← Chrome 159 reference · All APIs
v159 · media session · enabled by default
MediaSession: Return Promise<undefined> from setMicrophoneActive() and setCameraActive()
Updates navigator.mediaSession.setMicrophoneActive() and navigator.mediaSession.setCameraActive() to return a Promise<undefined> instead of synchronous undefined, matching the W3C Media Session specification. In a fully active document, the promise resolves with undefined; if the associated document is not fully active (such as a detached <iframe>), the promise rejects with an InvalidStateError DOMException.
at a glance
| Shipped in | Chrome 159 (desktop, Android), enabled by default — filed under “Enabled by default” in the milestone=159 listing; Android WebView listed as unconfirmed (null) in the ChromeStatus API record |
|---|---|
| Runtime flag | No dedicated runtime flag or Finch switch (MediaSession is status: "stable" in runtime_enabled_features.json5) |
| Specification | W3C Media Session — setMicrophoneActive(), setCameraActive(), update capture state algorithm |
| Spec PR | w3c/mediasession#312 — change capture-state setters to return Promise<undefined> |
| Intent | blink-dev Intent to Ship |
| Tracking bug | crbug.com/576328036 |
| Web platform tests | mediasession/idlharness.window.html, mediasession/setmicrophoneactive.html, mediasession/setcameraactive.html |
| ChromeStatus | 5188639100370944 — MediaSession: Return Promise<undefined> from setMicrophoneActive() and setCameraActive() |
why it exists
When Chrome 93 originally shipped setMicrophoneActive() and setCameraActive() for video-conferencing Picture-in-Picture and hardware media-key controls, both methods were specified as returning undefined (void). The W3C Media Session Working Group later updated the specification in w3c/mediasession#312 so both methods return Promise<undefined>, allowing user agents that enforce a capture-pause policy (such as Safari) to ask the user or perform asynchronous state transitions before settling. Updating Chromium in Chrome 159 aligns Chrome’s WebIDL contract with Safari 18.4+, fixes four failing subtests in WPT’s mediasession/idlharness.window.html, and lets conferencing apps await both methods uniformly.
Syntax
Updated Blink WebIDL matching the W3C Media Session specification:
// third_party/blink/renderer/modules/mediasession/media_session.idl
[Exposed=Window, RuntimeEnabled=MediaSession]
interface MediaSession {
// ...
Promise<undefined> setMicrophoneActive(boolean active);
Promise<undefined> setCameraActive(boolean active);
};
This reference covers three parts of the contract: MediaSession.setMicrophoneActive(), MediaSession.setCameraActive(), and the shared update capture state algorithm.
MediaSession interface; Blink media_session.idl.
MediaSession.setMicrophoneActive(active)
Inputs. Accepts a single required boolean active argument indicating whether the application considers the microphone active/unmuted (true) or muted/inactive (false). Standard JavaScript boolean coercion applies when a non-boolean argument is supplied; omitting the argument altogether causes WebIDL argument validation to return a rejected promise with TypeError.
Outputs. Returns a Promise<undefined>. In a fully active document in Chromium 159, notifies Chromium’s MediaSessionService with MicrophoneState::kUnmuted (when active is true) or MicrophoneState::kMuted (when active is false) and resolves to undefined. If the associated document is not fully active, returns a promise rejected with DOMException (name === "InvalidStateError").
setMicrophoneActive(); Blink media_session.cc.
MediaSession.setCameraActive(active)
Inputs. Accepts a single required boolean active argument indicating whether the application considers the camera active/on (true) or turned off/inactive (false). Omitting active returns a promise rejected with TypeError.
Outputs. Returns a Promise<undefined>. In a fully active document in Chromium 159, notifies Chromium’s MediaSessionService with CameraState::kTurnedOn (when active is true) or CameraState::kTurnedOff (when active is false) and resolves to undefined. If the associated document is not fully active, returns a promise rejected with DOMException (name === "InvalidStateError").
setCameraActive(); Blink media_session.cc.
Update capture state algorithm (spec vs Chromium 159)
Both methods delegate to the W3C Media Session update capture state algorithm with the receiver’s associated Document, active, and captureKind ("microphone" or "camera"):
| Condition | Chrome 159 result | W3C spec / cross-browser note |
|---|---|---|
| Document is fully active | Updates browser UI state and returns a Promise fulfilled with undefined | User agents with a capture-pause policy (e.g., Safari) may prompt or wait asynchronously before resolving, or reject with NotAllowedError if denied |
Document is not fully active (e.g., detached <iframe>) | Returns a Promise rejected with DOMException("InvalidStateError") ("The document is not fully active.") | Normative step 1: MUST return a promise rejected with InvalidStateError |
active === true while document.visibilityState !== "visible" | Resolves with undefined (Chromium does not reject hidden-tab activation) | Normative step 2: user agent MAY reject with InvalidStateError |
Missing active argument or invalid this receiver | Returns a Promise rejected with TypeError (no synchronous throw) | Per WebIDL promise-returning operation semantics, argument/receiver errors reject the returned promise |
Errors, behavioral changes, and caller migration
InvalidStateError(DOMException, rejected promise): occurs when calling either method on aMediaSessionbelonging to a document that is no longer fully active (such as a removed<iframe>). Always attach.catch()ortry/awaitif calling across frame boundaries or during teardown.TypeError(rejected promise instead of synchronous throw): prior to Chrome 159, callingnavigator.mediaSession.setMicrophoneActive()orsetCameraActive()with no arguments threw a synchronousTypeError. In Chrome 159+, because the WebIDL return type isPromise<undefined>, argument and receiver conversion failures produce a rejected promise.- Fire-and-forget callers stay safe in active documents: existing code that ignores the return value in an active document does not emit unhandled rejections because the returned promise resolves with
undefined. - Cross-version
awaitcompatibility:await navigator.mediaSession.setMicrophoneActive(isActive)works seamlessly in both Chrome < 159 (whereawait undefinedresolves immediately) and Chrome 159+ / Safari 18.4+ (which return aPromise<undefined>). Check"mediaSession" in navigator && typeof navigator.mediaSession.setMicrophoneActive === "function"before calling to guard Firefox.
Context and exposure
MediaSession is exposed only on Window ([Exposed=Window]) via navigator.mediaSession; it is not exposed in Web Workers. Neither setMicrophoneActive() nor setCameraActive() is restricted to [SecureContext] in Blink IDL, though actual microphone/camera capture via navigator.mediaDevices.getUserMedia() requires a secure context and user permission.
Lifecycle and state transitions
Each call updates the document’s desired capture-active hint reported to browser UI surfaces (such as the Picture-in-Picture window mute/camera buttons) and immediately returns a settled Promise<undefined> in Chromium 159. Repeated calls with the same boolean value are idempotent. Once a document stops being fully active (e.g., an <iframe> is disconnected from its parent DOM or navigated away), subsequent calls on its retained MediaSession reference reject with InvalidStateError rather than silently succeeding.
Examples
Awaiting setMicrophoneActive() and setCameraActive() safely across browsers
async function syncCallCaptureIndicators({ micOn, camOn }) {
const session = navigator.mediaSession;
if (!session) return;
try {
// await works in Chrome 159+ & Safari 18.4+ (Promise<undefined>)
// as well as Chrome 93-158 (undefined)
if (typeof session.setMicrophoneActive === "function") {
await session.setMicrophoneActive(micOn);
}
if (typeof session.setCameraActive === "function") {
await session.setCameraActive(camOn);
}
} catch (err) {
if (err instanceof DOMException && err.name === "InvalidStateError") {
// Document was detached or (in Safari) hidden when re-activating capture
console.warn("MediaSession state update skipped:", err.message);
return;
}
throw err;
}
}
Source: W3C Media Session; Blink media_session.cc.
Handling InvalidStateError on a detached document
const iframe = document.createElement("iframe");
document.body.append(iframe);
const detachedSession = iframe.contentWindow.navigator.mediaSession;
iframe.remove(); // Associated document is no longer fully active
// In Chrome 159+, returns a rejected Promise<undefined> (InvalidStateError)
const result = detachedSession.setMicrophoneActive(false);
if (result instanceof Promise) {
await result.catch((err) => {
console.log(err.name); // "InvalidStateError"
console.log(err.message); // "The document is not fully active."
});
}
Source: Blink media_session.cc; Chrome Platform Showcase detached-document-rejection concept.
Browser compatibility
| Browser | Returns Promise<undefined> | Base methods (BCD) | Notes & evidence |
|---|---|---|---|
| Chrome (desktop, Android) | 159 | 93 | Enabled by default in Chrome 159 on desktop and Android per ChromeStatus; Android WebView status is null (unconfirmed) in the API record. Chrome 93–158 returned undefined |
| Edge | Chromium-based (mirror) | 93 (mirror) | Mirrors Chrome in BCD |
| Firefox | No release | No (false) | Mozilla standards position: Positive; not shipped in BCD yet |
| Safari | 18.4 | 18.4 | Shipped returning Promise<undefined> in Safari 18.4 per WebKit Bug 277421 and BCD |
Security and privacy
Changing the return type from undefined to Promise<undefined> does not grant microphone or camera capture access, bypass permissions, or expose new user state. In Chromium 159, these methods only report the page’s self-declared mute/camera state to browser UI (such as Picture-in-Picture controls); rejecting with InvalidStateError when a document is not fully active prevents detached frames from modifying media-session state. In user agents that apply a capture-pause policy, returning a promise also allows user consent prompts before resuming capture. ChromeStatus records no security risks and lists security/privacy reviews as Pending (checked 2026-11-24).
Specifications
see also
- Chrome Platform Showcase — MediaSession Promise<undefined> return (5 interactive concepts)
- MDN —
MediaSession.setMicrophoneActive() - MDN —
MediaSession.setCameraActive() - w3c/mediasession#312 — Spec PR changing return type to
Promise<undefined> - ChromeStatus — MediaSession: Return Promise<undefined> from setMicrophoneActive() and setCameraActive() (5188639100370944)