v156 · dom · feature removal

Removal event recorder

A same-origin srcdoc iframe gets pagehide, visibilitychange and unload listeners. Then the parent takes it out of the DOM one of five ways. The recorder logs every event, whether it ran inside the removal call, and whether the iframe was still connected when the handler ran.

Flag: the new behaviour needs Chrome 156+ launched with --enable-blink-features=OmitSubframeDetachmentEventsOnRemoval (or --enable-features=OmitSubframeDetachmentEventsOnRemoval). No chrome://flags entry exists and --enable-experimental-web-platform-features does not enable it (flag status "test"). Without it you will see the legacy result: all three events, synchronously.

Remove a subframe

how the parent removes the iframe

The probe iframe appears here while it loads, then is removed.

Not run yet.

Choose a method and run it.
Events observed per removal method
methodpagehidevisibilitychangeunloadran inside call?
No runs yet.

the code

const iframe = document.createElement("iframe");
iframe.srcdoc = "<p>subframe</p>";          // same origin = same agent
await new Promise(r => { iframe.onload = r; wrapper.append(iframe); });

const fired = [];
let insideRemoval = false;
iframe.contentWindow.addEventListener("pagehide", () => fired.push(["pagehide", insideRemoval]));
iframe.contentDocument.addEventListener("visibilitychange", () => fired.push(["visibilitychange", insideRemoval]));
iframe.contentWindow.addEventListener("unload", () => fired.push(["unload", insideRemoval]));

insideRemoval = true;
iframe.remove();            // or removeChild / wrapper.remove() / innerHTML = "" / replaceChildren()
insideRemoval = false;

// legacy:   [["pagehide",true],["visibilitychange",true],["unload",true]]
// flag on:  []   — "destroy a child navigable" does not unload the document

Ground truth recorded while building this page (Chrome for Testing 153, headless, where the flag does not exist yet): all five methods fired all three events synchronously, with visibilityState already "hidden" inside the visibilitychange handler and iframe.isConnected still true — the handler runs before the node leaves the tree.

see also