Skip to content

Navigation API: nullify ongoing navigate event on successful cross-document navigation#12024

Open
noamr wants to merge 2 commits intowhatwg:mainfrom
noamr:nullify-ongoing-event
Open

Navigation API: nullify ongoing navigate event on successful cross-document navigation#12024
noamr wants to merge 2 commits intowhatwg:mainfrom
noamr:nullify-ongoing-event

Conversation

@noamr
Copy link
Copy Markdown
Collaborator

@noamr noamr commented Dec 16, 2025

Currently per spec, setting the ongoing navigation to "traversal" would abort the navigate event and fire navigateerror (and abort the event's signal).

However, tests like this one say otherwise, and this is not implemented anywhere.

In current implementations, the ongoing navigate event stays dangling, which creates unexpected results when the page is restored from BFCache - the abort signal and navigateerror events fired as a result of the next same-document navigation after being restored from BFCache.

This change makes it so that a succesful "traversal" (cross-document navigation) nullifies the ongoing event and API method tracker, without "aborting" it, making it so that the navigation neither signals success or failure.

Closes #11860

(See WHATWG Working Mode: Changes for more details.)


/browsing-the-web.html ( diff )

@noamr
Copy link
Copy Markdown
Collaborator Author

noamr commented Dec 16, 2025

@farre @jnjaeschke @nt1m

@farre
Copy link
Copy Markdown
Contributor

farre commented Dec 18, 2025

This is a small change and would be fairly easy to implement, and it's intention is correct. I'm not sure that it's correct as it is in spec though. We queue a task on the navigation and traversal task source, which is the same queue that we a bit later in the same algorithm queue other things on. Are we sure that clearing the ongoing navigate event before those steps are OK? Or should this be moved to after those? Or should the clearing itself be moved to step 12? In effect what we're saying is that the only thing that's allowed to abort a traverse navigate event is anything that's synchronously reachable from #apply-the-history-step. And maybe that's OK, but it's not at all clear to me that this is the case. Is the test you mention the only indication, or do we have more?

I haven't traced this fully, and I have very limited time before the holiday. Its intent does indeed sound reasonable, but if you want me to look deeper it will have to wait to January. I'll ask around to see if anyone else wants to take a stab at it from the Gecko side.

@noamr
Copy link
Copy Markdown
Collaborator Author

noamr commented Dec 18, 2025

This is a small change and would be fairly easy to implement, and it's intention is correct. I'm not sure that it's correct as it is in spec though. We queue a task on the navigation and traversal task source, which is the same queue that we a bit later in the same algorithm queue other things on. Are we sure that clearing the ongoing navigate event before those steps are OK? Or should this be moved to after those?

The thing is that "set the ongoing navigation" also queues the "aborting" on the same task source, so we have to do this before that's done. The next things queued on that task source is firing pagehide etc.

If we spec things this way, we have to test that e.g. calling pushState in pagehide doesn't cause navigateerror.

Or should the clearing itself be moved to step 12? In effect what we're saying is that the only thing that's allowed to abort a traverse navigate event is anything that's synchronously reachable from #apply-the-history-step.

apply the history step runs on the session history traversal queue, which is parallel from the document's task queue (effectively the "browser process" in chromium). So aborting and setting the ongoing navigate event has to be done in a task.

And maybe that's OK, but it's not at all clear to me that this is the case. Is the test you mention the only indication, or do we have more?

I am not sure, but that test is a pretty clear indication that current browsers don't call navigateerror before pagehide.
I think that calling navigateerror before pagehide would:

  • be unexpected as there is no error
  • delay cross-document navigations as more script now runs on unload.

An alternative to the proposed spec is to avoid aborting specifically when deactivating the document or beginning the traverse state, and then clearing the ongoing navigate event when restoring.
This would make pushState inside pagehide invoke navigateerror.

Let's continue this in 2026!

@nt1m
Copy link
Copy Markdown
Member

nt1m commented Dec 18, 2025

@basuke @RupinMittal

@noamr
Copy link
Copy Markdown
Collaborator Author

noamr commented Jan 6, 2026

@farre : early 2026 ping to look at this :)

@farre
Copy link
Copy Markdown
Contributor

farre commented Feb 27, 2026

@noamr: sorry for the time this has taken, but this:

This change makes it so that a succesful "traversal" (cross-document navigation) nullifies the ongoing event, without "aborting" it, making it so that the navigation neither signals success or failure.

makes so much sense. We should definitely make this be the way things are.

@noamr
Copy link
Copy Markdown
Collaborator Author

noamr commented Feb 27, 2026

@noamr: sorry for the time this has taken, but this:

This change makes it so that a succesful "traversal" (cross-document navigation) nullifies the ongoing event, without "aborting" it, making it so that the navigation neither signals success or failure.

makes so much sense. We should definitely make this be the way things are.

Thanks! Can I mark gecko as interested? I will proceed with WPTs etc

@nt1m
Copy link
Copy Markdown
Member

nt1m commented Feb 27, 2026

cc @annevk for WebKit too

@farre
Copy link
Copy Markdown
Contributor

farre commented Feb 28, 2026

@noamr: I've been looking into if this is something we should do for non-intercepted synchronous (same document) navigations. That would mean that if you don't intercept a non-asynchronous navigation that succeeds, navigatesuccess would always fire, which isn't the case today.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Mar 10, 2026
This prevents the cross-document navigation from being "aborted"
if a new same-origin nav is initiated after BFCache restore.

See spec conversation: whatwg/html#12024
Behind a flag until spec PR is merged etc.

Bug: 491363838
Change-Id: I17f76804226e422e72dc8dcaeb2bf29871c0cedd
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Mar 10, 2026
This prevents the cross-document navigation from being "aborted"
if a new same-origin nav is initiated after BFCache restore.

See spec conversation: whatwg/html#12024
Behind a flag until spec PR is merged etc.

Bug: 491363838
Change-Id: I17f76804226e422e72dc8dcaeb2bf29871c0cedd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7653517
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1597283}
brave-builds pushed a commit to brave/chromium that referenced this pull request Mar 10, 2026
This prevents the cross-document navigation from being "aborted"
if a new same-origin nav is initiated after BFCache restore.

See spec conversation: whatwg/html#12024
Behind a flag until spec PR is merged etc.

Bug: 491363838
Change-Id: I17f76804226e422e72dc8dcaeb2bf29871c0cedd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7653517
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1597283}
noamr added 2 commits March 12, 2026 10:16
…cument navigation

Currently per spec, setting the ongoing navigation to "traversal" would abort the `navigate` event
and fire `navigateerror` (and abort the event's signal).

However, tests like [this one](https://github.com/web-platform-tests/wpt/blob/156bb7cbb8483f6ffd4b275a1ed0b628fd0582cc/navigation-api/ordering-and-transition/transition-cross-document.html#L25) say otherwise,
and this is not implemented.

In current implementations, the `ongoing navigate event` stays dangling, which creates unexpected results
when the page is restored from BFCache - the abort signal and `navigateerror` events fired as a result of
the next same-document navigation after being restored from BFCache.

This change makes it so that a succesful "traversal" (cross-document navigation) nullifies the ongoing
event, without "aborting" it, making it so that the navigation neither signals success or failure.

Closes whatwg#11860
@noamr noamr force-pushed the nullify-ongoing-event branch from 399603d to 936ce85 Compare March 12, 2026 10:21
jcscottiii pushed a commit to web-platform-tests/wpt that referenced this pull request Mar 18, 2026
This prevents the cross-document navigation from being "aborted"
if a new same-origin nav is initiated after BFCache restore.

See spec conversation: whatwg/html#12024
Behind a flag until spec PR is merged etc.

Bug: 491363838
Change-Id: I17f76804226e422e72dc8dcaeb2bf29871c0cedd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7653517
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1597283}

Co-authored-by: Noam Rosenthal <nrosenthal@chromium.org>
noamr added a commit to web-platform-tests/wpt that referenced this pull request Mar 18, 2026
…o dangling-navigate-event-after-bfcache-restore.html

To be merged together with whatwg/html#12024
@noamr noamr requested a review from zcorpan March 19, 2026 07:59
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Mar 30, 2026
…cument navigation, a=testonly

Automatic update from web-platform-tests
Clear ongoing navigate event on cross document navigation (#58410)

This prevents the cross-document navigation from being "aborted"
if a new same-origin nav is initiated after BFCache restore.

See spec conversation: whatwg/html#12024
Behind a flag until spec PR is merged etc.

Bug: 491363838
Change-Id: I17f76804226e422e72dc8dcaeb2bf29871c0cedd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7653517
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Cr-Commit-Position: refs/heads/main@{#1597283}

Co-authored-by: Noam Rosenthal <nrosenthal@chromium.org>
--

wpt-commits: 0132f767da8dc1e1979b8def92a715919dcbc56c
wpt-pr: 58410
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Navigation API: Dangling ongoing navigate event causes inconsistent behavior in tests

3 participants