Bug 306802

Summary: NavigateEvent#navigationType should be "replace" when navigating to a URL that matches the active document's URL
Product: WebKit Reporter: Dom Christie <christiedom>
Component: DOMAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: ahmad.saleem792, basuke, cdumez, karlcow, rbuis, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 26   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
rendering in safari, firefox, chrome
none
testcase none

Dom Christie
Reported 2026-02-02 13:59:18 PST
In section 7.4.2.2, the [spec](https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate-convert-to-replace) states: > If url equals navigable's active document's URL, and initiatorOriginSnapshot is same origin with navigable's active document's origin, then set historyHandling to "replace". When tapping a link to a url that matches the current location, the NavigateEvent#navigationType property is "push" rather than "replace". This differs to the Chrome and Firefox implementation, which returns "replace".
Attachments
rendering in safari, firefox, chrome (269.21 KB, image/png)
2026-02-02 19:40 PST, Karl Dubost
no flags
testcase (2.70 KB, text/html)
2026-02-02 19:41 PST, Karl Dubost
no flags
Karl Dubost
Comment 1 2026-02-02 19:40:37 PST
Created attachment 478220 [details] rendering in safari, firefox, chrome Confirmed.
Karl Dubost
Comment 2 2026-02-02 19:41:22 PST
Created attachment 478221 [details] testcase PASS Firefox/Chrome FAIL Safari (STP235)
Karl Dubost
Comment 3 2026-02-02 22:27:58 PST
The spec says: https://url.spec.whatwg.org/#concept-url-equals ============= 4.6. URL equivalence To determine whether a URL A equals URL B, with an optional boolean exclude fragments (default false), run these steps: 1. Let serializedA be the result of serializing A, with exclude fragment set to exclude fragments. 2. Let serializedB be the result of serializing B, with exclude fragment set to exclude fragments. 3. Return true if serializedA is serializedB; otherwise false. ============= which means that foo.html#blah should be equivalent to foo.html and vice versa. So when we go back to the spec, it says: https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate-convert-to-replace ============== 12. If historyHandling is "auto", then: 1. If url equals navigable's active document's URL, and initiatorOriginSnapshot is same origin with navigable's active document's origin, then set historyHandling to "replace". 2. Otherwise, set historyHandling to "push". ============== The current code is: https://searchfox.org/wubkat/rev/efbda44f77fdac3adc639a9427ab93943f2b17b9/Source/WebCore/loader/FrameLoader.cpp#1613-1623 ```cpp bool isSameOrigin = frameLoadRequest.protectedRequesterSecurityOrigin()->isSameOriginDomain(document->protectedSecurityOrigin().get()); if (!isReload(newLoadType)) { if (historyHandling == NavigationHistoryBehavior::Auto) { if ((document->url() == newURL || document->readyState() != Document::ReadyState::Complete) && isSameOrigin) historyHandling = NavigationHistoryBehavior::Replace; else historyHandling = NavigationHistoryBehavior::Push; } if (newURL.protocolIsJavaScript() || (documentLoader() && documentLoader()->isInitialAboutBlank())) historyHandling = NavigationHistoryBehavior::Replace; } ``` are document->url() and newURL comparing the same URLs? For example, this should be equal? document.url() "https://example.com/page#section1" newURL "https://example.com/page" What about the opposite? This is covered by https://wpt.fyi/results/navigation-api/navigate-event/navigate-anchor-same-url.html
Karl Dubost
Comment 4 2026-02-02 22:29:32 PST
Radar WebKit Bug Importer
Comment 5 2026-02-09 14:00:13 PST
Chris Dumez
Comment 6 2026-03-23 22:10:52 PDT
EWS
Comment 7 2026-03-24 15:51:35 PDT
Committed 309871@main (d56ef888827c): <https://commits.webkit.org/309871@main> Reviewed commits have been landed. Closing PR #61221 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.