To navigate a navigable navigable to a
URL url using an optional Document-or-null sourceDocument (default null), with an optional POST
resource, string, or null documentResource (default null), an optional response-or-null response (default null), an optional boolean exceptionsEnabled (default false), an optional
NavigationHistoryBehavior historyHandling (default "auto"), an optional serialized
state-or-null navigationAPIState (default null), an optional entry list or
null formDataEntryList (default null), an optional referrer policy
referrerPolicy (default the empty
string), an optional user navigation involvement userInvolvement (default "none"), an optional Element sourceElement (default null), an optional
boolean initialInsertion (default false), and an
optional navigation API method tracker-or-null apiMethodTracker (default null):
Let cspNavigationType be "form-submission" if
formDataEntryList is non-null; otherwise "other".
Let sourceSnapshotParams be the result of snapshotting source snapshot params given sourceDocument.
Let initiatorOriginSnapshot be a new opaque origin.
Let initiatorBaseURLSnapshot be about:blank.
If sourceDocument is null:
Assert: userInvolvement is
"browser UI".
If url's scheme is "javascript", then set initiatorOriginSnapshot to
navigable's active document's origin.
Otherwise:
Assert: userInvolvement is not "browser UI".
If sourceDocument's node navigable is not allowed by sandboxing to navigate navigable given sourceSnapshotParams:
If exceptionsEnabled is true, then throw a
"SecurityError" DOMException.
Return.
Set initiatorOriginSnapshot to sourceDocument's origin.
Set initiatorBaseURLSnapshot to sourceDocument's document base URL.
Let navigationId be the result of generating a random UUID. [WEBCRYPTO]
If the surrounding agent is equal to navigable's active document's relevant agent, then continue these steps. Otherwise, queue a global task on the navigation and traversal task source given navigable's active window to continue these steps.
We do this because we are about to look at a lot of properties of navigable's active document, which are in theory only accessible over in the appropriate event loop. (But, we do not want to unconditionally queue a task, since — for example — same-event-loop fragment navigations need to take effect synchronously.)
Another implementation strategy would be to replicate the relevant information across event loops, or into a canonical "browser process", so that it can be consulted without queueing a task. This could give different results than what we specify here in edge cases, where the relevant properties have changed over in the target event loop but not yet been replicated. Further testing is needed to determine which of these strategies best matches browser behavior, in such racy edge cases.
If navigable's active document's
unload counter is greater than 0, then invoke WebDriver BiDi navigation
failed with navigable and a WebDriver BiDi navigation status whose
id is navigationId, status is "canceled", and url is url, and return.
Let container be navigable's container.
If container is an iframe element and will lazy load
element steps given container returns true, then stop
intersection-observing a lazy loading element container and set
container's lazy load resumption steps to null.
If navigable's allowed to perform a navigation or history update
returns blocked, then invoke WebDriver BiDi navigation failed with
navigable and a WebDriver BiDi navigation status whose id is navigationId, status is "canceled", and url is url, and return.
If historyHandling is "auto":
If url equals navigable's
active document's URL, and either userInvolvement is "browser UI" or initiatorOriginSnapshot is same
origin with navigable's active document's
origin, then set historyHandling to
"replace".
Otherwise, set historyHandling to "push".
If the navigation must be a replace given url and
navigable's active document, then set
historyHandling to "replace".
If all of the following are true:
documentResource is null;
response is null;
url equals navigable's active session history entry's URL with exclude fragments set to true; and
url's fragment is non-null,
then:
Navigate to a fragment given navigable, url, historyHandling, userInvolvement, sourceElement, navigationAPIState, and navigationId.
Return.
If navigable's parent is non-null, then set
navigable's is delaying load events to
true.
Let targetSnapshotParams be the result of snapshotting target snapshot params given navigable.
Invoke WebDriver BiDi navigation started with navigable and a new
WebDriver BiDi navigation status whose id
is navigationId, status is "pending", and url is url.
If navigable's ongoing navigation is "traversal":
Invoke WebDriver BiDi navigation failed with navigable and a new
WebDriver BiDi navigation status whose id is navigationId, status is "canceled", and url is url.
Return.
Any attempts to navigate a navigable that is currently traversing are ignored.
Set the ongoing navigation for navigable to navigationId.
This will have the effect of aborting other ongoing navigations of navigable, since at certain points during navigation changes to the ongoing navigation will cause further work to be abandoned.
If url's scheme is "javascript":
Queue a global task on the navigation and traversal task
source given navigable's active window to
navigate to a javascript: URL given navigable,
url, historyHandling, sourceSnapshotParams,
initiatorOriginSnapshot, userInvolvement,
cspNavigationType, initialInsertion, and
navigationId.
Return.
If all of the following are true:
userInvolvement is not "browser
UI";
navigable's active document's origin is same origin-domain with sourceDocument's origin;
navigable's active document's is
initial about:blank is false; and
url's scheme is a fetch scheme,
then:
Let navigation be navigable's active window's navigation API.
Let entryListForFiring be formDataEntryList if documentResource is a POST resource; otherwise, null.
Let navigationAPIStateForFiring be navigationAPIState if navigationAPIState is not null; otherwise, StructuredSerializeForStorage(undefined).
Let continue be the result of firing a push/replace/reload navigate
event at navigation with navigationType set to historyHandling,
isSameDocument set to false, userInvolvement set to
userInvolvement, sourceElement set
to sourceElement, formDataEntryList set to
entryListForFiring, destinationURL
set to url, navigationAPIState
set to navigationAPIStateForFiring, and apiMethodTracker set to
apiMethodTracker.
If continue is false, then return.
It is possible for navigations with userInvolvement of "browser UI" or initiated by a cross origin-domain sourceDocument to fire navigate events, if they go through the earlier navigate to a fragment path.
If sourceDocument is navigable's container document, then reserve deferred fetch quota for navigable's container given url's origin.
In parallel, run these steps:
Let unloadPromptCanceled be the result of checking if unloading is canceled for navigable's active document's inclusive descendant navigables.
If unloadPromptCanceled is not "continue", or
navigable's ongoing navigation is no longer
navigationId:
Invoke WebDriver BiDi navigation failed with navigable and a
new WebDriver BiDi navigation status whose id is navigationId, status is "canceled", and url is url.
Abort these steps.
Queue a global task on the navigation and traversal task source given navigable's active window to abort a document and its descendants given navigable's active document.
Let documentState be a new document state with
The navigable target name can get cleared under various conditions later in the navigation process, before the document state is finalized.
If url matches about:blank or
is about:srcdoc:
Set documentState's origin to initiatorOriginSnapshot.
Set documentState's about base URL to initiatorBaseURLSnapshot.
Let historyEntry be a new session history entry, with its URL set to url and its document state set to documentState.
Let navigationParams be null.
If response is non-null:
Let sourcePolicyContainer be a clone of the sourceDocument's policy container, if sourceDocument is not null; otherwise null.
Let policyContainer be the result of determining navigation params policy container given response's URL, null, sourcePolicyContainer, navigable's container document's policy container, and null.
Let finalSandboxFlags be the union of targetSnapshotParams's sandboxing flags and policyContainer's CSP list's CSP-derived sandboxing flags.
Let responseOrigin be the result of determining the origin given response's URL, finalSandboxFlags, and documentState's initiator origin.
Let coop be a new opener policy.
Let coopEnforcementResult be a new opener policy enforcement result with
Set navigationParams to a new navigation params, with
iframe element referrer policyiframe element referrer
policynavigate"Attempt to populate the history entry's document for historyEntry,
given navigable, "navigate", sourceSnapshotParams,
targetSnapshotParams, userInvolvement, navigationId,
navigationParams, cspNavigationType, with allowPOST set to true and completionSteps set to the following
step:
Append session history traversal steps to navigable's traversable navigable to finalize a cross-document navigation given navigable, historyHandling, userInvolvement, and historyEntry.