v156 · dom · feature removal

Re-entrancy hazard

Why the events are going: they let a child’s script run inside the parent’s DOM mutation. Three same-origin card iframes sit in a list; the parent clears the list with an ordinary loop. Card 0 has a perfectly reasonable-looking pagehide handler that tidies its neighbour away. On legacy Chrome that handler runs in the middle of the parent’s remove() call and edits the list the parent is iterating.

Flag: run Chrome 156+ with --enable-blink-features=OmitSubframeDetachmentEventsOnRemoval to see the trace collapse to the parent’s own steps. Red-ruled lines are child script running during a parent call; blue-ruled lines are the parent’s MutationObserver, which always runs afterwards, as a microtask.

Clear the card list

    Loading cards…

      the code

      // parent
      for (const li of [...cards.children]) li.remove();   // looks atomic per step
      
      // inside card 0 (same origin, so it can reach the parent's DOM)
      addEventListener("pagehide", () => {
        const next = parent.document.querySelector("#cards li:nth-child(2)");
        next?.remove();      // legacy Chrome: runs INSIDE the parent's li.remove()
      });
      
      // Legacy trace:   parent remove #0 → card 0 pagehide → card 1 pagehide (nested)
      //                 → parent remove #1 on an already-detached node → …
      // 156 (flag on):  parent remove #0 → parent remove #1 → parent remove #2

      This is benign here, but the same shape is what Blink kept fixing: a handler that inserts a frame into the subtree being removed, navigates, re-parents the iframe, or calls document.open(), all while the parent’s removal algorithm is half-finished. The compat study found a real instance in Google Publisher Tags’ friendly-iframe pagehide handler, which mutates ad-slot state when a host clears an ad container with innerHTML = "".

      see also