browsingContext.navigationStarted event
The browsingContext.navigationStarted event of the browsingContext module fires when a cross-document navigation begins in a context.
Description
The navigation to a different page can be triggered by the browsingContext.navigate or browsingContext.reload command, by user interaction with elements on the page, or by JavaScript running in the page's context.
For cross-document navigations, this is the first in the sequence of navigation events and fires when the browser begins fetching the URL.
If the navigation succeeds, browsingContext.navigationCommitted fires next, when the browser has accepted the response and begun loading the new page.
After that, browsingContext.domContentLoaded fires when the HTML has been parsed, and browsingContext.load fires last when the document and all its subresources have finished loading.
If the navigation fails, browsingContext.navigationFailed fires instead.
Note:
This event is not emitted when the initial about:blank page is loaded for a new top-level browsing context.
This event does not fire for same-document navigations.
For navigations to a URL fragment, see browsingContext.fragmentNavigated.
For URL changes made through the History API without a full navigation, see browsingContext.historyUpdated.
Event data
The params field in the event notification is a navigation object with the following fields:
context-
A string that contains the ID of the context in which the navigation is starting.
-
A string that contains the UUID that uniquely identifies this navigation. This ID matches the
navigationvalue in the response of thebrowsingContext.navigateandbrowsingContext.reloadcommands. timestamp-
A non-negative integer that represents the time in UTC when the event was fired, as milliseconds elapsed since the epoch.
url-
A string that contains the URL being loaded.
userContextOptional-
A string that contains the ID of the user context in which the navigation is starting.
Examples
>Receiving an event when a cross-document navigation starts
Assume you have a WebDriver BiDi connection and an active session with a subscription to browsingContext.navigationStarted.
Suppose you use browsingContext.navigate to load https://example.com, passing the context ID you obtained from browsingContext.getTree.
The browser sends the following notification, where the context value matches the context ID you passed to browsingContext.navigate:
{
"type": "event",
"method": "browsingContext.navigationStarted",
"params": {
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
"navigation": "a1b2c3d4-5678-90ab-cdef-1234567890ab",
"timestamp": 1781646423959,
"url": "https://example.com"
}
}
Specifications
| Specification |
|---|
| WebDriver BiDi> # event-browsingContext-navigationStarted> |