Skip to content

Conversation

chrisdavidmills
Copy link
Contributor

Description

Chromium 141 adds support for the precommitHandler option of the NavigateEvent.intercept() method. See https://chromestatus.com/feature/5134734612496384.

This PR adds documentation for it.

It also overhauls the intercept() method page in general, adding a bunch of details in a large "Description" section that was missing before. I think more work needs to be done here, but it is out of the scope of this PR for me to try to fix everything. For now, I've added a bit more information about how the intercept() features work so that the page is a bit more informative.

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner October 14, 2025 08:48
@chrisdavidmills chrisdavidmills requested review from sideshowbarker and removed request for a team October 14, 2025 08:48
@github-actions github-actions bot added the Content:WebAPI Web API docs label Oct 14, 2025
@chrisdavidmills chrisdavidmills changed the title Add precommitHandler() and other info to Navigation API docs Technical review: Add precommitHandler() and other info to Navigation API docs Oct 14, 2025
@github-actions github-actions bot added the size/m [PR only] 51-500 LoC changed label Oct 14, 2025
Copy link
Contributor

github-actions bot commented Oct 14, 2025

Preview URLs

(comment last updated: 2025-10-20 09:52:19)

Copy link
Contributor

@noamr noamr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, see comments

@chrisdavidmills chrisdavidmills requested a review from noamr October 14, 2025 15:37

## Description

The `intercept()` method is used to implement custom SPA navigation behavior when a navigation occurs, for example when a link is clicked, a form is submitted, or a programmatic navigation is initiated (using {{domxref("History.pushState()")}}, {{domxref("Window.location")}}, etc.).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "SPA navigation behavior" is a bit of an awkward wording, but I'll leave that to the editorial review.

Copy link
Contributor Author

@chrisdavidmills chrisdavidmills Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to "...implement same-document (SPA) navigation behavior..." for now, but we can iterate on it further if required.

- `history` {{optional_inline}}
- : An enumerated value that specifies how this redirect should be added to the navigation history. It can take one of the following values:
- `auto`
- : The default value, which lets the browser decide how to handle it. Usually the value used is `push`, but it will become `replace` if the redirect points to the same URL as the pre-navigation URL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can also be whatever was passed to navigate(). The main point of auto is that the redirect call doesn't change history handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think I know what you mean here. Is the following correct? (ignore the formatting)


  • auto
    • : The default value, which lets the browser decide how to handle it:
      • If the original navigation occurred as a result of a {{domxref("Navigation.navigate()")}} call, the value will be whatever was specified in the navigate() call's history option.
      • Otherwise, the value used is usually push, but it will become replace if the redirect points to the same URL as the pre-navigation URL.


- `state` {{optional_inline}}
- : Contains any state information you want to pass along with the navigation, for example, for logging or tracking purposes. The state for the navigation can subsequently be retrieved via {{domxref("NavigationHistoryEntry.getState()")}}.
- `history` {{optional_inline}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something about this: redirect can change the behavior between auto/push/replace, but it cannot turn a traverse navigation to a push/replace navigation or vice versa.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool; I've added this info as a note at the bottom of the bit about replace():

Note

The redirect() method can can convert the history behavior between auto, push, and replace, but it cannot turn a traverse navigation into a push/replace navigation and vice versa.

@chrisdavidmills
Copy link
Contributor Author

@noamr thanks for the reviews. This one looks about ready to go on to the editorial review stage now, but feel free to add more comments if you think anything else still needs attention.

@chrisdavidmills chrisdavidmills changed the title Technical review: Add precommitHandler() and other info to Navigation API docs Editorial review: Add precommitHandler() and other info to Navigation API docs Oct 20, 2025
@noamr
Copy link
Contributor

noamr commented Oct 20, 2025

@noamr thanks for the reviews. This one looks about ready to go on to the editorial review stage now, but feel free to add more comments if you think anything else still needs attention.

Yes, technical LGTM from me!

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

Labels

Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants