Skip to content

Preserve History State after Cross-Document Navigation #1441

Open

Description

@sunhaitao

Description

Currently, Blink and WebKit discard the developer-supplied history entry state after a cross-document navigation, but retain the state during a same-document navigation.

This behavior is inconsistent and makes passing data to a navigation target highly complex.

The current behavior of Gecko is more consistent, as the state is always preserved after any navigation.

The ability to seamlessly pass state across documents is critical for web apps that aren't strictly single-page. Resolving this cross-browser discrepancy will significantly lower friction for modern web state handling and allow developers to drop hacky storage-based fallbacks.

Specification

https://html.spec.whatwg.org/multipage/nav-history-apis.html

web-feature

web-features: navigation

Test Links

a.html
b.html

Additional Signals

No response

Activity

  1. github-actions commented on Sep 22, 2026

    @github-actions

    This comment was automatically generated based on the information you provided. Please don't edit it.

    Below is additional information about the web feature (from the web-features project) which is referenced in your proposal.
    If this doesn't accurately correspond to your proposal, please update your initial comment to include web-features: <feature-id>.
    To find feature IDs, use the web-features explorer.

    Feature Navigation API

  2. domenic commented on Oct 9, 2026

    @domenic
    Member

    I ranked this highly on Mozilla's survey of which features to include, but that was not necessarily a vote for the behavior the OP proposes. It's a vote for fixing any interop issue here according to the most reasonable interpretation of the spec, because the brand-new navigation API having interop issues is very sad.

    (I cannot quite tell what the OP is suggesting, but if it's that updateCurrentEntry() should somehow also cause future entries to update, that seems unlikely to be correct.)

  3. sunhaitao commented on Oct 9, 2026

    @sunhaitao
    Author

    I suggest all engines align with Gecko's current behavior here. This means that after clicking the "NEXT" button in a.html, the browser should navigate to b.html, and calling both navigation.currentEntry.getState() and navigation.activation.entry.getState() should return ["XYZ"].

    The call to navigation.updateCurrentEntry in a.html was simply my attempt to leave a marker for easier inspection later; in hindsight, it is not truly necessary.

  4. jgraham commented on Oct 21, 2026

    @jgraham
    Contributor

    Are there bugs filed against Chromium or WebKit for this?

  5. zcorpan commented on Oct 21, 2026

    @zcorpan
    Member

    I used AI to check what the spec requires. It says Chromium and WebKit follow the current spec in this case:

    The spec requires undefined here. The navigate() method says state "will be ignored for navigations that end up cross-document." The navigate algorithm matches: it passes navigationAPIState only to the navigate event's destination, then creates the new session history entry without it. That entry keeps the initial navigation API state, StructuredSerializeForStorage(undefined). Cross-document reload({state}) works the same way: reload exposes the new state on event.destination and never writes it to the entry. Chrome Canary and Safari TP return undefined from currentEntry.getState() and activation.entry.getState() on b.html. Firefox Nightly returns ["XYZ"].

    Using the web-archeologist skill to find out about the rationale:

    Dropping state on cross-document navigations was intentional. Domenic raised it in WICG/navigation-api#98 (2021). His concern: "giving a new way to pass state across documents seems a bit fraught. At the very least it'd have to be origin-constrained." He closed it as "let's leave this as no". In WICG/navigation-api#100, a web developer reported that automatically carrying state forward led to it being misused as a sessionStorage substitute. Gecko's behavior seems to come from https://bugzilla.mozilla.org/show_bug.cgi?id=1966674, which was about plumbing state into NavigateEvent.destination. Part 6 of that bug also copies the state into the new session history entry, with no rationale given, so I think it's a Gecko bug. I couldn't find a wpt test for this case, which may be why nobody noticed.

  6. zcorpan commented on Oct 21, 2026

    @zcorpan
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    focus-area-proposal

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions