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

Limited availability — supported in Chrome and Safari; not yet shipped in Firefox

  • Chrome · 159 (Promise<undefined>; base methods in 93)
  • Edge · Chromium-based (BCD mirror)
  • Firefox · Not supported in BCD (Positive position)
  • Safari · 18.4 (returns Promise<undefined>)

The base media-session web-feature is Limited availability per webstatus.dev, and BCD api/MediaSession.json lists setMicrophoneActive and setCameraActive as supported in Chrome 93+ and Safari 18.4+ but unsupported in Firefox (checked 2026-11-24). BCD does not yet have a separate subfeature for Chrome 159’s Promise<undefined> return type change.

at a glance

Shipped inChrome 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 flagNo dedicated runtime flag or Finch switch (MediaSession is status: "stable" in runtime_enabled_features.json5)
SpecificationW3C Media Session — setMicrophoneActive(), setCameraActive(), update capture state algorithm
Spec PRw3c/mediasession#312 — change capture-state setters to return Promise<undefined>
Intentblink-dev Intent to Ship
Tracking bugcrbug.com/576328036
Web platform testsmediasession/idlharness.window.html, mediasession/setmicrophoneactive.html, mediasession/setcameraactive.html
ChromeStatus5188639100370944 — 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.

Source: ChromeStatus motivation (5188639100370944); w3c/mediasession#312.

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.

Source: W3C Media Session 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").

Source: W3C Media Session 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").

Source: W3C Media Session 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"):

Behavior of setMicrophoneActive() and setCameraActive() across call conditions
ConditionChrome 159 resultW3C spec / cross-browser note
Document is fully activeUpdates browser UI state and returns a Promise fulfilled with undefinedUser 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 receiverReturns a Promise rejected with TypeError (no synchronous throw)Per WebIDL promise-returning operation semantics, argument/receiver errors reject the returned promise
Source: W3C Media Session update capture state algorithm; Blink media_session.cc; ChromeStatus interop notes.

Errors, behavioral changes, and caller migration

Source: ChromeStatus interop & compatibility risks; WebIDL Operations (promise rejection conversion).

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.

Source: W3C Media Session; Blink media_session.idl.

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.

Source: Blink media_session.cc; W3C Media Session.

Examples

Live interactive example: Return shape probe (also see Detached document rejection, Caller pattern matrix, IDL contract inspector, and Video call mute controls).Source: Chrome Platform Showcase — MediaSession Promise<undefined> return

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

Support for MediaSession.setMicrophoneActive() and MediaSession.setCameraActive() returning Promise<undefined>, combining BCD api/MediaSession.json with ChromeStatus 5188639100370944 (checked 2026-11-24).
BrowserReturns Promise<undefined>Base methods (BCD)Notes & evidence
Chrome (desktop, Android)15993Enabled 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
EdgeChromium-based (mirror)93 (mirror)Mirrors Chrome in BCD
FirefoxNo releaseNo (false)Mozilla standards position: Positive; not shipped in BCD yet
Safari18.418.4Shipped returning Promise<undefined> in Safari 18.4 per WebKit Bug 277421 and BCD
Source: BCD api/MediaSession.json; ChromeStatus API record; WebKit Bug 277421; webstatus.dev media-session.

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

Source: ChromeStatus record (5188639100370944); W3C Media Session Privacy Considerations.

Specifications

see also