v159 · dom · media session
Detached-document rejection
Step 1 of the spec’s update capture state algorithm: “If document is not fully active, return a promise rejected with InvalidStateError.” A document stops being fully active when its iframe is removed or it is navigated away while script still holds its mediaSession. Chromium implements that check in media_session.cc (“The document is not fully active.”); before 159 the same call returned undefined and nothing told you it had done nothing.
-
1. Create a same-origin iframe and keep its
navigator.mediaSessionNo iframe yet.
-
2. Call its methods while the document is fully active
Create the iframe first.
-
3. Remove the iframe (its document is no longer fully active)
Create the iframe first.
-
4. Call the retained session again
Remove the iframe first.
the probe, verbatim
const frame = document.body.appendChild(document.createElement("iframe"));
const session = frame.contentWindow.navigator.mediaSession;
frame.remove(); // document no longer fully active
const r = session.setMicrophoneActive(true);
// The promise comes from the IFRAME's realm, so `r instanceof Promise` is false
// in the parent even on Chrome 159. Check the brand instead:
Object.prototype.toString.call(r) // "[object Promise]" (159+) | "[object Undefined]" (≤158)
r.catch(e => e.name) // "InvalidStateError"
Ground truth for the legacy side (Chrome 153 headless): the detached call returned undefined and raised nothing. The page also notes a gotcha this exposes: the rejected promise belongs to the detached iframe’s realm, so cross-realm code must not rely on instanceof Promise.