Skip to content
AnswerWell geo Documentation

Research · 9 min read · Answerwell

Navigation API, Session History, and Navigate Event Intercept

How the Navigation API manages same-origin history, navigate events, intercept(), and how that differs from the classic History API.

This page summarizes the WHATWG HTML Living Standard definitions of the Navigation API (window.navigation), session history, and navigables, together with practical guidance from Google Chrome’s Navigation API documentation. The Navigation API is the spec’s application-oriented way to observe and control navigations within a single navigable (typically a tab or an iframe), as a successor to the classic location and history APIs.

Section titled “Navigation API: what window.navigation does”

The global navigation property exposes methods and events to manage navigations and NavigationHistoryEntry objects for the current navigable.

The navigation API, provided by the global navigation property, provides a modern and web application-focused way of managing navigations and history entries. It is a successor to the classic location and history APIs.

— WHATWG HTML, APIs related to navigation and session history

Compared with location.assign() and related APIs, navigation.navigate() is only reachable from code that has direct synchronous access to window.navigation on that window—it does not cross same origin-domain boundaries the way some location operations can. See Navigation and session history APIs for the full interface.

The API is disabled when the document is not fully active, on the initial about:blank document, or when the document has an opaque origin (empty entry list, null currentEntry).

Google Chrome describes the API as a full redesign of client-side routing rather than a small patch on the History API:

The Navigation API is a proposed API that completely overhauls this space, rather than trying to simply patch History API’s rough edges.

— Google, Modern client-side routing: the Navigation API

Section titled “Navigables, session history, and why Back moves more than one URL”

Navigables are the user-facing notion of a sequence of documents (tabs, windows, iframes). A traversable navigable (a top-level tab or window) owns one combined session history for itself and its child navigables (for example nested iframes), because the user has only one back/forward control per tab.

Navigables are a user-facing representation of a sequence of documents… Typical examples are tabs or windows… or iframes.
Traversable navigables… control the session history of themselves and of their descendant navigables…
Browsing contexts are a developer-facing representation… correspond 1:1 with WindowProxy objects.

— WHATWG HTML, Infrastructure for sequences of documents

those navigations need to be linearized into a single session history list since the user only has a single back/forward interface for the entire traversable navigable

— WHATWG HTML, Navigation and session history

A fully active document is the active document of its navigable and, if it lives in a child navigable, its container document is also fully active. If a parent iframe navigates away, a child document may remain “active” on its navigable but is not fully active, so user interaction and many APIs (including a working Navigation API on that child) must not behave as if the user could still use that frame normally.

Section titled “navigation.entries() and cross-origin history limits”

navigation.entries() returns NavigationHistoryEntry items for the current navigable only—not parent history, and not “internal” iframe history when you call the API from the top-level page.

Additionally, it only contains NavigationHistoryEntry objects representing same-origin session history entries

— WHATWG HTML, APIs related to navigation and session history

Implications:

Behavior Meaning for developers
navigation.canGoBack / canGoForward false when the adjacent raw history step is another origin (no matching entry object).
NavigationHistoryEntry.url May be null on a cross-document entry if the other document was fetched with no-referrer or origin referrer policy.
key vs id key is stable across replace navigations and across reload/session restore; id is unique per entry and is not reused. Use traverseTo(key) to return to a slot.

Serialized state on an entry comes from getState() on the Navigation API channel. It is not the same object as classic history.state (though both may be populated from related storage in the session history entry internally). Repeated getState() calls may deserialize fresh objects that are not ===.

The navigate event: preventDefault(), intercept(), and limits

Section titled “The navigate event: preventDefault(), intercept(), and limits”

For almost any navigation or history traversal in the current navigable, the user agent fires a navigate event on navigation. That centralizes clicks, form submissions, history.pushState, navigation.navigate(), back/forward, and reload in one listener (Chrome’s recommended SPA pattern).

Situation preventDefault() intercept()
Same-origin, cancelable navigation (many in-app navigations) Often allowed when event.cancelable is true Allowed when canIntercept is true
Cross-origin navigation Per event cancelable Not allowed — canIntercept is false
Hash-only (hashChange) Varies Not via intercept() (use normal fragment handling)
Download (downloadRequest) — Not interceptable
User Back/Forward (navigationType: "traverse") Often not cancelable (Chrome: you can’t cancel back/forward with preventDefault()) Cross-origin traverse: not interceptable
Location bar navigation to a new document — Event does not fire
Navigation from another window to a new document here — Event does not fire

(The event will not fire for location bar-initiated navigations, or navigations initiated from other windows, when the destination of the navigation is a new document.)

— WHATWG HTML, APIs related to navigation and session history

You can’t handle navigations via intercept() if the navigation is a cross-origin navigation.

— Google, Modern client-side routing: the Navigation API

you can’t cancel a navigation via preventDefault() if the user is pressing the Back or Forward buttons

— Google, Modern client-side routing: the Navigation API

intercept() must be called synchronously during event dispatch; calling it later throws. It requires a trusted event. Pass event.signal (AbortSignal) into fetch() so Stop or a superseding navigation aborts in-flight work—the same pattern Chrome documents for loading UI.

intercept({ handler, precommitHandler, scroll, focusReset })

Section titled “intercept({ handler, precommitHandler, scroll, focusReset })”

intercept() turns the navigation into a same-document navigation to the destination URL: the URL updates before the async handler runs, so Chrome recommends showing a placeholder so relative URLs and DOM do not disagree with the address bar.

  • precommitHandler runs before currentEntry updates (only when the event is cancelable).
  • handler runs after commit; its promise drives loading indication and navigatesuccess / navigateerror.
  • Default scroll restoration and focus reset (first autofocus or body) run when handler promises settle unless you set scroll: "manual" or focusReset: "manual".

navigation.navigate(url, { state, history: "replace", info }) serializes state for same-document completions; state is ignored for cross-document end states. Use navigation.updateCurrentEntry({ state }) to persist metadata without navigating (fires currententrychange with navigationType null).

navigation.navigate(), reload(), back(), forward(), and traverseTo(key) return { committed, finished }.

Outcome committed finished
Aborted (including via signal) Rejects AbortError Rejects AbortError
Same-document, intercepted Fulfills after commit Fulfills/rejects with handler promise
Same-document fragment, not intercepted Fulfills immediately Fulfills immediately
Cross-document full navigation Never settles Never settles
204, 205, or attachment that does not document-navigate Never settles Never settles
traverseTo invalid key — InvalidStateError

While a navigation is in progress, navigation.transition is non-null until navigatesuccess or navigateerror. navigation.activation describes the last cross-document activation of this Document and stays constant across same-document updates until the document is reactivated from history.

Section titled “Navigation API vs classic history and fragment URLs”

The classic History API and fragment navigations follow different event rules:

this means that popstate events fire for fragment navigations, but not for history.pushState() calls.

— WHATWG HTML, Navigation and session history

history.pushState / replaceState do not fire hashchange. Fragment navigations do fire popstate when the user traverses history. The Navigation API navigate event still fires for many programmatic paths, including history.pushState and location.assign (Chrome notes those APIs remain and also emit navigate).

javascript: URLs always use replace history handling and are never stored in session history, so they cannot be restored with back/forward:

This means javascript: URLs are never stored in session history, and so can never be traversed to.

— WHATWG HTML, Navigation and session history

The spec is explicit that navigation and session history are intricate:

Welcome to the dragon’s maw. Navigation, session history, and the traversal through that session history are some of the most complex parts of this standard.

— WHATWG HTML, Navigation and session history

When history traverses instead of destroying a Document, the user agent may keep it in a back-forward cache (bfcache):

If the Document is not destroyed, then during history traversal, it can be reactivated. The cache in which browsers store such Documents is often called a back-forward cache, or bfcache

— WHATWG HTML, Navigation and session history

If restoration fails, the NotRestoredReasons interface (on a top-level traversable) exposes reason strings such as fetch, parser-aborted, websocket, unload-listener, response-cache-control-no-store, and many UA-specific cases. Cross-origin iframe details may be sanitized or masked on the parent. Blocking reasons during load tie to document lifecycle: aborting fetch or the parser sets unsalvageable with reasons like fetch or parser-aborted per Document lifecycle.

Browser UI, stop loading, and history trapping

Section titled “Browser UI, stop loading, and history trapping”

User agents should offer navigate, reload, stop, and history traverse on top-level traversables (Speculative loading and browser UI). UI-driven reload may require confirmation when the current entry is a POST resource. The spec suggests allowing history deltas greater than one so pages cannot trap users with endless pushState or fragment churn:

It is suggested that such user agents allow traversal by deltas greater than one, to avoid letting a page “trap” the user by stuffing the session history with spurious entries.

— WHATWG HTML, Speculative loading

window.stop() and “stop loading a navigable” abort in-flight document navigations (cancel fetch, abort parser). UI stop may also cancel traversals; window.stop() does not stop an ongoing traversal navigation (Document lifecycle — abort and stop).

  • Treating navigation.entries().length like history.length—entries are same-origin contiguous slices only.
  • Awaiting navigation.navigate().finished after a normal cross-origin link or full document load.
  • Calling intercept() in a setTimeout or microtask after the navigate handler returns.
  • Assuming getState() equals history.state or is stable by reference across calls.
  • Using preventDefault() on browser Back/Forward and expecting SPA-only routing to block traversal.
  • Ignoring canIntercept on hashChange or download navigations and always calling intercept().
  • Expecting navigate on the first load of a document (Chrome: no event on initial navigation—SSR-only sites may be unaffected).
  • Forgetting that the API is single-frame (top-level or one iframe navigable), not a merge of all iframe histories.
  1. In the browser console on your app origin, log navigation.entries(), navigation.currentEntry?.url, and navigation.currentEntry?.getState() after a few in-app navigations; compare with history.length and history.state to see the same-origin-only entry list described in APIs related to navigation and session history.
  2. Add navigation.addEventListener('navigate', (e) => console.log({ canIntercept: e.canIntercept, navigationType: e.navigationType, hashChange: e.hashChange, downloadRequest: e.downloadRequest })) and trigger link clicks, form posts, history.pushState, and navigation.navigate(); confirm cross-origin and hash-only cases match the limits in Modern client-side routing: the Navigation API.
  3. Test Back and Forward: verify whether preventDefault() is ignored for navigationType === 'traverse', and whether intercept() is unavailable on cross-origin traversals.
  4. For an SPA using intercept(), confirm navigatesuccess / navigateerror and that aborting via Stop rejects fetches tied to event.signal.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will correct or clarify it.