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.
Navigation API: what window.navigation does
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.
Navigables, session history, and why Back moves more than one URL
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.
navigation.entries() and cross-origin history limits
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).
When you can cancel or intercept
Section titled “When you can cancel or intercept”| 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.
you can’t cancel a navigation via preventDefault() if the user is pressing the Back or Forward buttons
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.
precommitHandlerruns beforecurrentEntryupdates (only when the event is cancelable).handlerruns after commit; its promise drives loading indication andnavigatesuccess/navigateerror.- Default scroll restoration and focus reset (first
autofocusorbody) run when handler promises settle unless you setscroll: "manual"orfocusReset: "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).
committed and finished promises
Section titled “committed and finished promises”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.
Navigation API vs classic history and fragment URLs
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
Back-forward cache and NotRestoredReasons
Section titled “Back-forward cache and NotRestoredReasons”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).
Common mistakes
Section titled “Common mistakes”- Treating
navigation.entries().lengthlikehistory.length—entries are same-origin contiguous slices only. - Awaiting
navigation.navigate().finishedafter a normal cross-origin link or full document load. - Calling
intercept()in asetTimeoutor microtask after thenavigatehandler returns. - Assuming
getState()equalshistory.stateor is stable by reference across calls. - Using
preventDefault()on browser Back/Forward and expecting SPA-only routing to block traversal. - Ignoring
canInterceptonhashChangeor download navigations and always callingintercept(). - Expecting
navigateon 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.
How to check this on your site
Section titled “How to check this on your site”- In the browser console on your app origin, log
navigation.entries(),navigation.currentEntry?.url, andnavigation.currentEntry?.getState()after a few in-app navigations; compare withhistory.lengthandhistory.stateto see the same-origin-only entry list described in APIs related to navigation and session history. - 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, andnavigation.navigate(); confirm cross-origin and hash-only cases match the limits in Modern client-side routing: the Navigation API. - Test Back and Forward: verify whether
preventDefault()is ignored fornavigationType === 'traverse', and whetherintercept()is unavailable on cross-origin traversals. - For an SPA using
intercept(), confirmnavigatesuccess/navigateerrorand that aborting via Stop rejects fetches tied toevent.signal. - You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”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.