Skip to content

Inserting an iframe into a non-fully active document creates a child navigable #13085

Open

Description

@zcorpan

Comment by Claude:

The iframe HTML element post-connection steps only bail out when the node document has no browsing context:

  1. If insertedNode's node document's browsing context is null, then return.
  2. ...
  3. Create a new child navigable for insertedNode.

A non-fully active document that hasn't been destroyed still has a browsing context. For example, an iframe's previous document after a same-origin navigation isn't destroyed if the user agent intends to keep it in bfcache. Appending an iframe to it then creates a child navigable. (Firefox Nightly, Chrome Canary, and Safari TP don't keep it, so in them the appended iframe's contentWindow is null.)

(Found in #13067, which removed an assert this path would hit. Crashtest: web-platform-tests/wpt#63761.)

Maybe these steps could return early if the node document is not fully active. The frame post-connection steps have the same check.

Activity

  1. zcorpan commented on Oct 16, 2026

    @zcorpan
    MemberAuthor
  2. shannonbooth commented on Oct 16, 2026

    @shannonbooth
    Member

    https://github.com/LadybirdBrowser/ladybird/blob/2347e56772355691ec1ba1487d06120f3d4a2176/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp#L108 not that it matters too much for webcompat purposes, but we actually have the exact workaround suggested here, but I hadn't gotten around to filing spec issue / fixing yet since there are some other workarounds I hadn't investigated fully yet

  3. zcorpan commented on Oct 19, 2026

    @zcorpan
    MemberAuthor

    Thanks @shannonbooth, good to know!

    I asked Claude to look into what Gecko, Chromium, and WebKit do here, and what the options for a spec fix are:

    In the crashtest's case, Gecko, Chromium, and WebKit bail out because the old document lost its window/frame when the iframe navigated:

    All three only put top-level pages in bfcache (Gecko, Chromium, WebKit), so an iframe's own navigation destroys its previous document. The spec allows that, since intendToKeepInBfcache in unload a document is up to the user agent. So this is reachable in a user agent that keeps such documents, or for a document in a bfcached page that script can still reach (e.g., from an opener).

    Options:

    1. Return early from the iframe and frame post-connection steps if the node document isn't fully active. object already checks this when determining what it represents, and so does embed's "potentially active". This matches Ladybird and Gecko's IsActive() check.
    2. Require intendToKeepInBfcache to be false for child navigables' documents, to match browsers. Then traversing back within an iframe repopulates the entry instead of reusing the document, since destroying it sets the entry's document to null. That doesn't cover documents in a bfcached page, so 1 seems needed either way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions