Skip to content

Navigation incorrectly defaults to history pushing in most cases #39818

@jdm

Description

@jdm

// Step 11. If historyHandling is "auto", then:
let resolved_history_handling = if history_handling == NavigationHistoryBehavior::Auto {
// Step 11.1. If url equals navigable's active document's URL, and
// initiatorOriginSnapshot is same origin with targetNavigable's active document's
// origin, then set historyHandling to "replace".
// Note: `targetNavigable` is not actually defined in the spec, "active document" is
// assumed to be the correct reference based on WPT results
if let LoadOrigin::Script(initiator_origin) = initiator_origin_snapshot {
if load_data.url == doc.url() && initiator_origin.same_origin(doc.origin()) {
NavigationHistoryBehavior::Replace
} else {
NavigationHistoryBehavior::Push
}
} else {
// Step 11.2. Otherwise, set historyHandling to "push".
NavigationHistoryBehavior::Push
}
// Step 12. If the navigation must be a replace given url and navigable's active
// document, then set historyHandling to "replace".
} else if load_data.url.scheme() == "javascript" || doc.is_initial_about_blank() {
NavigationHistoryBehavior::Replace
} else {
NavigationHistoryBehavior::Push
};

Step 12 of https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate doesn't agree with the logic implemented there. This makes code like location.replace(..) use push instead of replace, which looks like it makes /html/browsers/browsing-the-web/history-traversal/document-state.https.html behave incorrectly in #39545.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions