A URL matches about:blank if its scheme is "about", its path contains a single string "blank", its
username and password are the empty string, and its host is null.
The document base URL of a Document document is the
URL record obtained by running these steps:
If document has no descendant base element that has
an href attribute, then return document's
fallback base URL.
Otherwise, return the frozen base URL of the first base element
in document that has an href attribute, in
tree order.
The fallback base URL of a Document object document is the
URL record obtained by running these steps:
If document is an iframe
srcdoc document:
Assert: document's about base URL is non-null.
Return document's about base URL.
If document's URL matches
about:blank and document's about base URL is non-null, then return
document's about base
URL.
Return document's URL.
The will lazy load element steps, given an element element, are as follows:
If scripting is disabled for element, then return false.
This is an anti-tracking measure, because if a user agent supported lazy loading when scripting is disabled, it would still be possible for a site to track a user's approximate scroll position throughout a session, by strategically placing images in a page's markup such that a server can track how many images are requested and when.
If element's lazy loading attribute is in the Lazy state, then return true.
Return false.
To stop intersection-observing a lazy loading element element, run these steps:
Let doc be element's node document.
Assert: doc's lazy load intersection observer is not null.
Call doc's lazy load intersection observer's unobserve method with element as
the argument.
The intention is to use the original value of the unobserve method. See w3c/IntersectionObserver#464.
[INTERSECTIONOBSERVER]
Return ? StructuredSerializeInternal(value, true).
Each Document has an about base
URL, which is a URL or null, initially null.
The time marches on steps are as follows:
Let current cues be a list of cues, initialized to contain all the cues of all the or showing text tracks of the media element (not the disabled ones) whose start times are less than or equal to the current playback position and whose end times are greater than the current playback position.
Let other cues be a list of cues, initialized to contain all the cues of and showing text tracks of the media element that are not present in current cues.
Let last time be the current playback position at the time this algorithm was last run for this media element, if this is not the first time it has run.
If the current playback position has, since the last time this algorithm was run, only changed through its usual monotonic increase during normal playback, then let missed cues be the list of cues in other cues whose start times are greater than or equal to last time and whose end times are less than or equal to the current playback position. Otherwise, let missed cues be an empty list.
Remove all the cues in missed cues that are also in the media element's list of newly introduced cues, and then empty the element's list of newly introduced cues.
If the time was reached through the usual monotonic increase of the current playback
position during normal playback, and if the user agent has not fired a timeupdate event at the element in the past 15 to 250ms
and is not still running event handlers for such an event, then the user agent must queue a
media element task given the media element to fire an event named timeupdate at the element. (In the other cases, such as
explicit seeks, relevant events get fired as part of the overall process of changing the
current playback position.)
The event thus is not to be fired faster than about 66Hz or slower than 4Hz (assuming the event handlers don't take longer than 250ms to run). User agents are encouraged to vary the frequency of the event based on the system load and the average cost of processing the event each time, so that the UI updates are not any more frequent than the user agent can comfortably handle while decoding the video.
If all of the cues in current cues have their text track cue active flag set, none of the cues in other cues have their text track cue active flag set, and missed cues is empty, then return.
If the time was reached through the usual monotonic increase of the current playback position during normal playback, and there are cues in other cues that have their text track cue pause-on-exit flag set and that either have their text track cue active flag set or are also in missed cues, then immediately pause the media element.
In the other cases, such as explicit seeks, playback is not paused by going past the end time of a cue, even if that cue has its text track cue pause-on-exit flag set.
Let events be a list of tasks, initially empty. Each task in this list will be associated with a text track, a text track cue, and a time, which are used to sort the list before the tasks are queued.
Let affected tracks be a list of text tracks, initially empty.
When the steps below say to prepare an event named event for a text track cue target with a time time, the user agent must run these steps:
Let track be the text track with which the text track cue target is associated.
Create a task to fire an event named event at target.
Add the newly created task to events, associated with the time time, the text track track, and the text track cue target.
Add track to affected tracks.
For each text track cue in missed
cues, prepare an event named enter for the
TextTrackCue object with the text track cue start time.
For each text track cue in other
cues that either has its text track cue active flag set or is in missed cues, prepare an event named exit for the TextTrackCue object with the later of the
text track cue end time and the text track cue start time.
For each text track cue in current
cues that does not have its text track cue active flag set, prepare an
event named enter for the TextTrackCue
object with the text track cue start time.
Sort the tasks in events in ascending time order (tasks with earlier times first).
Further sort tasks in events that have the same time by the relative text track cue order of the text track cues associated with these tasks.
Finally, sort tasks in events that have the
same time and same text track cue order by placing tasks that fire enter
events before those that fire exit events.
Queue a media element task given the media element for each task in events, in list order.
Sort affected tracks in the same order as the text tracks appear in the media element's list of text tracks, and remove duplicates.
For each text track in affected tracks, in the list order,
queue a media element task given the media element to fire an event named cuechange at the TextTrack object, and, if the
text track has a corresponding track element, to then fire an event named cuechange at the track element as well.
Set the text track cue active flag of all the cues in the current cues, and unset the text track cue active flag of all the cues in the other cues.
Run the rules for updating the text track rendering of each of the text tracks in affected tracks that are showing, providing the text track's text track language as the fallback language if it is not the empty string. For example, for text tracks based on WebVTT, the rules for updating the display of WebVTT text tracks. [WEBVTT]
To update a color well control color, given an element element:
Assert: element is an input element whose type attribute is in the Color state.
Let value be the result of running these steps:
If element's dirty value flag is
false, then return the result of getting an attribute by namespace and
local name given null, "value", and element.
Return element's value.
Let color be the result of parsing value.
If color is failure, then set color to opaque black.
Set element's value to the result of serializing a color well control color given element and color.
Two origins, A and B, are said to be same origin if the following algorithm returns true:
If A and B are the same opaque origin, then return true.
If A and B are both tuple origins and their schemes, hosts, and port are identical, then return true.
Return false.
Two origins, A and B, are said to be same origin-domain if the following algorithm returns true:
If A and B are the same opaque origin, then return true.
If A and B are both tuple origins:
If A and B's schemes are identical, and their domains are identical and non-null, then return true.
Otherwise, if A and B are same origin and their domains are both null, return true.
Return false.
Every CSP list cspList has CSP-derived sandboxing flags, which is a sandboxing flag set. It is the return value of the following algorithm:
Let directives be an empty ordered set.
For each policy in cspList:
If policy's disposition is not "enforce", then continue.
If policy's directive set contains a directive whose name is "sandbox",
then append that directive to
directives.
If directives is empty, then return an empty sandboxing flag set.
Let directive be directives[directives's size − 1].
Return the result of parsing the sandboxing directive directive.
To clone a policy container given a policy container policyContainer:
Let clone be a new policy container.
For each policy in policyContainer's CSP list, append a copy of policy into clone's CSP list.
Set clone's embedder policy to a copy of policyContainer's embedder policy.
Set clone's referrer policy to policyContainer's referrer policy.
Set clone's integrity policy to a copy of policyContainer's integrity policy.
Return clone.
To determine navigation params policy container given a URL responseURL and four policy container-or-nulls historyPolicyContainer, initiatorPolicyContainer, parentPolicyContainer, and responsePolicyContainer:
If historyPolicyContainer is not null:
Assert: responseURL requires storing the policy container in history.
Return a clone of historyPolicyContainer.
If responseURL is about:srcdoc:
If responseURL is local and initiatorPolicyContainer is not null, then return a clone of initiatorPolicyContainer.
If responsePolicyContainer is not null, then return responsePolicyContainer.
Return a new policy container.
To Location-object navigate a Location object
location to a URL url, optionally given a NavigationHistoryBehavior historyHandling
(default "auto"):
Let navigable be location's relevant global object's navigable.
Let sourceDocument be the incumbent
global object's associated
Document.
If location's relevant Document is not yet
completely loaded, and the incumbent global
object does not have transient activation, then set
historyHandling to "replace".
Navigate navigable to url using sourceDocument, with exceptionsEnabled set to true and historyHandling set to historyHandling.
The assign(url) method steps are:
If this's relevant Document is null, then
return.
If this's relevant Document's origin is not same origin-domain with the
entry settings object's origin, then throw a
"SecurityError" DOMException.
Let urlRecord be the result of encoding-parsing a URL given url, relative to the entry settings object.
If urlRecord is failure, then throw a "SyntaxError"
DOMException.
Location-object navigate this to
urlRecord.
Each Window has an associated navigation
API, which is a Navigation object. Upon creation of the Window
object, its navigation API must be set to a
new Navigation object created in the Window object's relevant realm.
The current entry of a Navigation
navigation is the result of running the following steps:
If navigation has entries and events disabled, then return null.
Assert: navigation's current entry index is not −1.
Return navigation's entry list[navigation's current entry index].
To get the navigation API entry
index of a session history entry she within a
Navigation navigation:
Let index be 0.
For each nhe of navigation's entry list:
If nhe's session history entry is equal to she, then return index.
Increment index by 1.
Return −1.
To initialize the navigation API entries for a new document given a
Navigation navigation, a list of session history entries newSHEs, and a session history
entry initialSHE:
Assert: navigation's entry list is empty.
Assert: navigation's current entry index is −1.
If navigation has entries and events disabled, then return.
For each newSHE of newSHEs:
Let newNHE be a new NavigationHistoryEntry created
in the relevant realm of
navigation.
Set newNHE's session history entry to newSHE.
Append newNHE to navigation's entry list.
newSHEs will have originally come from getting session history entries for the navigation API, and thus each newSHE will be contiguous same origin with initialSHE.
Set navigation's current entry index to the result of getting the navigation API entry index of initialSHE within navigation.
To update the navigation API entries for a same-document navigation given a
Navigation navigation, a session history entry
destinationSHE, and a NavigationType navigationType:
If navigation has entries and events disabled, then return.
Let oldCurrentNHE be the current entry of navigation.
Let disposedNHEs be a new empty list.
If navigationType is "traverse":
Set navigation's current entry index to the result of getting the navigation API entry index of destinationSHE within navigation.
Assert: navigation's current entry index is not −1.
This algorithm is only called for same-document traversals. Cross-document traversals will instead call either initialize the navigation API entries for a new document or update the navigation API entries for reactivation.
Otherwise, if navigationType is "push":
Set navigation's current entry index to navigation's current entry index + 1.
Let i be navigation's current entry index.
While i < navigation's entry list's size:
Append navigation's entry list[i] to disposedNHEs.
Set i to i + 1.
Remove all items in disposedNHEs from navigation's entry list.
Otherwise, if navigationType is "replace":
Append oldCurrentNHE to disposedNHEs.
If navigationType is "push" or
"replace":
Let newNHE be a new NavigationHistoryEntry created
in the relevant realm of
navigation.
Set newNHE's session history entry to destinationSHE.
Set navigation's entry list[navigation's current entry index] to newNHE.
If navigation's ongoing API method tracker is non-null, then notify about the committed-to entry given navigation's ongoing API method tracker and the current entry of navigation.
It is important to do this before firing the dispose or currententrychange events, since event handlers could
start another navigation, or otherwise change the value of navigation's ongoing
API method tracker.
Let navigateEvent be navigation's ongoing navigate event.
Let apiMethodTracker be navigation's ongoing API method tracker.
Prepare to run script given navigation's relevant settings object.
See the discussion for other navigation API events to understand why we do this.
Fire an event named currententrychange at navigation using
NavigationCurrentEntryChangeEvent, with its navigationType attribute
initialized to navigationType and its from initialized to
oldCurrentNHE.
For each disposedNHE of disposedNHEs:
Fire an event named dispose at disposedNHE.
Run the navigate event intercept commit handler steps given navigation, navigateEvent, and apiMethodTracker.
Clean up after running script given navigation's relevant settings object.
To fire a traverse navigate event at a
Navigation navigation given a session history entry destinationSHE and an optional
user navigation involvement userInvolvement (default "none"):
Let event be the result of creating an event given
NavigateEvent, in navigation's relevant realm.
Set event's classic history API state to null.
Let destination be a new NavigationDestination
created in navigation's relevant
realm.
Let destinationNHE be the NavigationHistoryEntry in
navigation's entry list whose session history entry is destinationSHE, or null if no such
NavigationHistoryEntry exists.
If destinationNHE is non-null:
Set destination's entry to destinationNHE.
Set destination's state to destinationSHE's navigation API state.
Otherwise,
Set destination's entry to null.
Set destination's state to StructuredSerializeForStorage(null).
Set destination's is
same document to true if destinationSHE's document is equal to navigation's relevant global
object's associated Document;
otherwise false.
Return the result of performing the inner navigate event firing algorithm given
navigation, "traverse",
event, destination, userInvolvement, null, null, and
null.
To fire a push/replace/reload navigate event at
a Navigation navigation given a NavigationType navigationType, a URL destinationURL, a boolean isSameDocument, an optional user
navigation involvement userInvolvement (default "none"), an optional Element-or-null sourceElement (default null), an
optional entry list-or-null formDataEntryList (default null), an
optional serialized state navigationAPIState (default
StructuredSerializeForStorage(null)), an optional serialized
state-or-null classicHistoryAPIState (default
null), and an optional navigation API method tracker-or-null apiMethodTracker:
Let document be navigation's relevant global object's associated Document.
Inform the navigation API about aborting navigation in document's node navigable.
If navigation has entries and events disabled, and apiMethodTracker is not null:
Set apiMethodTracker's pending to false.
Set apiMethodTracker to null.
If navigation has entries and events disabled, then
navigate() and reload() calls return promises that will never fulfill. We
never create a NavigationHistoryEntry object for such Documents, there
is no NavigationHistoryEntry to apply serializedState to, and there is
no navigate event to include info with. So, we
don't need to track this API method call after all. We need to check this after aborting
previous navigations, in case the Document has became non-fully active
as a result of a navigateerror event.
If document is not fully active, then return false.
Let event be the result of creating an event given
NavigateEvent, in navigation's relevant realm.
Set event's classic history API state to classicHistoryAPIState.
Let destination be a new NavigationDestination
created in navigation's relevant
realm.
Set destination's URL to destinationURL.
Set destination's entry to null.
Set destination's state to navigationAPIState.
Set destination's is same document to isSameDocument.
Return the result of performing the inner navigate event firing algorithm given
navigation, navigationType, event, destination,
userInvolvement, sourceElement, formDataEntryList, null, and
apiMethodTracker.
The inner navigate event firing algorithm
consists of the following steps, given a Navigation navigation, a
NavigationType navigationType, a NavigateEvent
event, a NavigationDestination destination, a user
navigation involvement userInvolvement, an Element-or-null
sourceElement, an entry list-or-null formDataEntryList, a
string-or-null downloadRequestFilename, and an optional navigation API method
tracker-or-null apiMethodTracker (default null):
If navigation has entries and events disabled:
Assert: navigation's ongoing API method tracker is null.
Assert: navigation's upcoming traverse API method trackers is empty.
Assert: apiMethodTracker is null.
Return true.
These assertions holds because traverseTo(), back(), and forward() will immediately fail when entries and events
are disabled (since there are no entries to traverse to).
Assert: navigation's ongoing API method tracker is null.
If destination's entry is non-null:
Assert: apiMethodTracker is null.
apiMethodTracker is passed as an argument only for navigate() and reload() calls.
Assert: destinationKey is not the empty string.
If navigation's upcoming traverse API method trackers[destinationKey] exists:
Set apiMethodTracker to navigation's upcoming traverse API method trackers[destinationKey].
Remove navigation's upcoming traverse API method trackers[destinationKey].
If apiMethodTracker is not null:
Set navigation's ongoing API method tracker to apiMethodTracker.
Set apiMethodTracker's pending to false.
Let navigable be navigation's relevant global object's navigable.
Let document be navigation's relevant global object's
associated Document.
If document can have its URL rewritten to destination's
URL, and either destination's
is same document is true or
navigationType is not "traverse",
then initialize event's canIntercept to true. Otherwise, initialize it to
false.
If either:
navigationType is not "traverse"; or
traverseCanBeCanceled is true,
then initialize event's cancelable to
true. Otherwise, initialize it to false.
Initialize event's navigationType to
navigationType.
Initialize event's destination to destination.
Initialize event's downloadRequest to
downloadRequestFilename.
If apiMethodTracker is not null, then initialize event's info to apiMethodTracker's info. Otherwise, initialize it to
undefined.
At this point apiMethodTracker's info is no longer needed and can be nulled out instead of keeping it alive for the lifetime of the navigation API method tracker.
Initialize event's hasUAVisualTransition to true if a visual
transition, to display a cached rendered state of the document's latest
entry, was done by the user agent. Otherwise, initialize it to false.
Initialize event's sourceElement to
sourceElement.
Set event's abort
controller to a new AbortController created in
navigation's relevant realm.
Initialize event's signal to
event's abort
controller's signal.
Let currentURL be document's URL.
If all of the following are true:
event's classic history API state is null;
destination's is same document is true;
destination's URL equals currentURL with exclude fragments set to true; and
destination's URL's fragment is not identical to currentURL's fragment,
then initialize event's hashChange to true. Otherwise, initialize it to
false.
The first condition here means that hashChange will be true for fragment navigations, but false for cases like history.pushState(undefined, "", "#fragment").
If userInvolvement is not "none", then
initialize event's userInitiated
to true. Otherwise, initialize it to false.
If formDataEntryList is not null, then initialize event's formData to a new FormData
created in navigation's relevant realm,
associated to formDataEntryList. Otherwise, initialize it to null.
Assert: navigation's ongoing navigate event is null.
Set navigation's ongoing navigate
event to event.
Set navigation's focus changed during ongoing navigation to false.
Set navigation's suppress normal scroll restoration during ongoing navigation to false.
Let dispatchResult be the result of dispatching event at navigation.
If dispatchResult is false:
If navigationType is "traverse", then consume history-action user
activation given navigation's relevant global object.
If event's abort controller's signal is not aborted, then abort the ongoing navigation given navigation.
Return false.
If event's interception
state is not "none":
Let fromNHE be the current entry of navigation.
Assert: fromNHE is not null.
Set navigation's transition
to a new NavigationTransition created in navigation's
relevant realm, with
destinationMark as handled navigation's transition's finished promise.
See the discussion about other finished promises to understand why this is done.
Mark as handled navigation's transition's committed promise.
If event's navigation precommit handler list is empty then commit event given apiMethodTracker.
Otherwise:
Let precommitController be a new NavigationPrecommitController
created in navigation's relevant realm,
whose event is
event.
Let precommitPromisesList be an empty list.
For each handler of event's navigation precommit handler list:
Wait for all precommitPromisesList with the following success steps: commit event given apiMethodTracker, and the following failure step given reason: process navigate event handler failure given event and reason.
If event's interception
state is "none", then return true.
Return false.
The state attribute must return the value it was
initialized to. It represents the context information for the event, or null, if the state
represented is the initial state of the Document.
The
hasUAVisualTransition attribute must return the value it was initialized to.
The oldURL attribute must return the value it was
initialized to. It represents context information for the event, specifically the URL of the
session history entry that was traversed from.
The newURL attribute must return the value it was
initialized to. It represents context information for the event, specifically the URL of the
session history entry that was traversed to.
A navigable's active document is its active session history entry's document.
A navigable's active window
is its active WindowProxy's [[Window]].
A navigable's target name is its active session history entry's document state's navigable target name.
To get the node navigable of a node node, return the navigable whose active document is node's node document, or null if there is no such navigable.
To get the traversable navigable of a navigable inputNavigable:
Let navigable be inputNavigable.
While navigable is not a traversable navigable, set navigable to navigable's parent.
Return navigable.
The container of a navigable navigable is the navigable container whose content navigable is navigable, or null if there is no such element.
The container document of a navigable navigable is the result of running these steps:
If navigable's container is null, then return null.
Return navigable's container's node document.
This is equal to navigable's container's shadow-including root as navigable's container has to be connected.
The inclusive descendant navigables of a
Document document are given by these steps:
Let navigables be « document's node navigable ».
Extend navigables with document's descendant navigables.
Return navigables.
To determine the origin, given a URL url, a sandboxing flag set sandboxFlags, and an origin-or-null sourceOrigin:
If sandboxFlags has its sandboxed origin browsing context flag set, then return a new opaque origin.
If url is null, then return a new opaque origin.
If url is about:srcdoc:
Assert: sourceOrigin is non-null.
Return sourceOrigin.
If url matches about:blank and
sourceOrigin is non-null, then return sourceOrigin.
Return url's origin.
The cases that return sourceOrigin result in two
Documents that end up with the same underlying origin, meaning that document.domain affects both.
To get a session history entry's document, return its document state's document.
To append session history traversal steps to a traversable navigable traversable given algorithm steps steps, append steps to traversable's session history traversal queue's algorithm set.
To snapshot source snapshot params
given a Document-or-null sourceDocument:
If sourceDocument is null, then return a new source snapshot params with
This only occurs in the case of a browser UI-initiated navigation.
Return a new source snapshot params with
To snapshot target snapshot params given a navigable targetNavigable, return a new target snapshot params with:
iframe element referrer policyiframe element referrer policy given
targetNavigable's containerThe navigation must be a replace, given a URL url and a
Document document, if any of the following are true:
url's scheme is "javascript"; or
document's is initial about:blank is true.
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 the navigation must be a replace given url and
navigable's active document, then set
historyHandling to "replace".
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":
Let request be a new request, with
This is a synthetic request, needed
because the Content Security Policy check in navigate to a javascript:
URL operates on a request. It will never hit the
network.
Queue a global task on the navigation and traversal task
source given navigable's active window to
navigate to a javascript: URL given navigable,
request, historyHandling, 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.
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.
To finalize a cross-document navigation given a navigable navigable, a history handling behavior historyHandling, a user navigation involvement userInvolvement, and a session history entry historyEntry:
Assert: this is running on navigable's traversable navigable's session history traversal queue.
Set navigable's is delaying load
events to false.
If historyEntry's document is null, then return.
This means that attempting to populate the history entry's document ended up not creating a document, as a result of e.g., the navigation being canceled by a subsequent navigation, a 204 No Content response, etc.
If all of the following are true:
navigable's parent is null;
historyEntry's document's browsing context is not an auxiliary browsing context whose opener browsing context is non-null; and
historyEntry's document's origin is not navigable's active document's origin,
then set historyEntry's document state's navigable target name to the empty string.
Let entryToReplace be navigable's active session history entry if
historyHandling is "replace",
otherwise null.
Let traversable be navigable's traversable navigable.
Let targetStep be null.
Let targetEntries be the result of getting session history entries for navigable.
If entryToReplace is null:
Clear the forward session history of traversable.
Set targetStep to traversable's current session history step + 1.
Set historyEntry's step to targetStep.
Append historyEntry to targetEntries.
Otherwise:
Replace entryToReplace with historyEntry in targetEntries.
If historyEntry's document state's origin is same origin with entryToReplace's document state's origin, then set historyEntry's navigation API key to entryToReplace's navigation API key.
Set targetStep to traversable's current session history step.
Apply the push/replace history step targetStep to traversable given historyHandling and userInvolvement.
To navigate to a javascript: URL, given a navigable
targetNavigable, a request request, a
history handling behavior historyHandling, an origin
initiatorOrigin, a user navigation involvement userInvolvement,
a string cspNavigationType, a boolean initialInsertion, and a
navigation ID navigationId:
If targetNavigable's ongoing navigation is no longer navigationId, then return.
Set the ongoing navigation for targetNavigable to null.
If initiatorOrigin is not same origin-domain with targetNavigable's active document's origin, then return.
If the result of should navigation request of type be blocked by Content Security
Policy? given request and cspNavigationType is "Blocked", then return. [CSP]
This can change request's URL, as the require-trusted-types-for pre-navigation check passes the script source
through the default policy. [TRUSTED-TYPES]
Let newDocument be the result of evaluating a javascript: URL given targetNavigable,
request's URL, initiatorOrigin,
userInvolvement, and navigationId.
If newDocument is null:
If initialInsertion is true, targetNavigable's container is non-null, and targetNavigable's active document's is initial
about:blank is true, then run the iframe load event steps
given targetNavigable's container.
The pre-navigation check runs author code through the default policy, which can have removed targetNavigable's container in the meantime.
Return.
In this case, some JavaScript code was executed, but no new
Document was created, so we will not perform a navigation.
Let entryToReplace be targetNavigable's active session history entry.
Let oldDocState be entryToReplace's document state.
Let documentState be a new document state with
Let historyEntry be a new session history entry, with
For the URL, we do not use
request's URL, i.e., the javascript: URL that was evaluated. This means javascript: URLs are never stored in session history, and so
can never be traversed to.
Append session history traversal steps to targetNavigable's traversable navigable to finalize a cross-document navigation with targetNavigable, historyHandling, userInvolvement, and historyEntry.
To navigate to a fragment given a navigable
navigable, a URL url, a history handling behavior
historyHandling, a user navigation involvement userInvolvement,
an Element-or-null sourceElement, a serialized state-or-null
navigationAPIState, and a navigation ID navigationId:
Let navigation be navigable's active window's navigation API.
Let destinationNavigationAPIState be navigable's active session history entry's navigation API state.
If navigationAPIState is not null, then set destinationNavigationAPIState to navigationAPIState.
Let continue be the result of firing a push/replace/reload navigate event at
navigation with navigationType set to
historyHandling, isSameDocument set
to true, userInvolvement set to
userInvolvement, sourceElement set
to sourceElement, destinationURL
set to url, and navigationAPIState set to
destinationNavigationAPIState.
If continue is false:
If navigation's ongoing navigate
event is not null, then set the ongoing navigation of navigable
to navigationId.
This makes intercepted hash navigations cancelable by browser UI or window.stop().
Return.
Let historyEntry be a new session history entry, with
For navigations performed with navigation.navigate(), the value provided by the state option is used for the new navigation API state. (This will set it to the
serialization of undefined, if no value is provided for that option.) For other fragment
navigations, including user-initiated ones, the navigation API state is carried over from the previous
entry.
The classic history API state is never carried over.
Let entryToReplace be navigable's active session history entry if
historyHandling is "replace",
otherwise null.
If entryToReplace is non-null, then set historyEntry's navigation API key to entryToReplace's navigation API key.
Let history be navigable's active document's history object.
Let scriptHistoryIndex be history's index.
Let scriptHistoryLength be history's length.
If historyHandling is "push":
Set history's state to null.
Increment scriptHistoryIndex.
Set scriptHistoryLength to scriptHistoryIndex + 1.
Set navigable's active document's URL to url.
Set navigable's active session history entry to historyEntry.
Update document for history step application given navigable's active document, historyEntry, true, scriptHistoryIndex, scriptHistoryLength, and historyHandling.
This algorithm will be called twice as a result of a single fragment
navigation: once synchronously, where best-guess values scriptHistoryIndex and
scriptHistoryLength are set, history.state
is nulled out, and various events are fired; and once asynchronously, where the final values for
index and length are set, history.state remains
untouched, and no events are fired.
Scroll to the fragment given navigable's active document.
If the scrolling fails because the Document is new and the
relevant ID has not yet been parsed, then the second
asynchronous call to update document for history step application will take
care of scrolling.
Let traversable be navigable's traversable navigable.
Append the following session history synchronous navigation steps involving navigable to traversable:
Finalize a same-document navigation given traversable, navigable, historyEntry, entryToReplace, historyHandling, and userInvolvement.
Invoke WebDriver BiDi fragment navigated with navigable and a
new WebDriver BiDi navigation status whose id is navigationId, url is url, and status is "complete".
To finalize a same-document navigation given a traversable navigable traversable, a navigable targetNavigable, a session history entry targetEntry, a session history entry-or-null entryToReplace, a history handling behavior historyHandling, and a user navigation involvement userInvolvement:
This is used by both fragment navigations and by the URL and history update steps, which are the only synchronous updates to session history. By virtue of being synchronous, those algorithms are performed outside of the top-level traversable's session history traversal queue. This puts them out of sync with the top-level traversable's current session history step, so this algorithm is used to resolve conflicts due to race conditions.
Assert: this is running on traversable's session history traversal queue.
If targetNavigable's active session history entry is not targetEntry, then return.
Let targetStep be null.
Let targetEntries be the result of getting session history entries for targetNavigable.
If entryToReplace is null:
Clear the forward session history of traversable.
Set targetStep to traversable's current session history step + 1.
Set targetEntry's step to targetStep.
Append targetEntry to targetEntries.
Otherwise:
Replace entryToReplace with targetEntry in targetEntries.
Set targetStep to traversable's current session history step.
Apply the push/replace history step targetStep to traversable given historyHandling and userInvolvement.
This is done even for "replace" navigations, as it resolves race
conditions across multiple synchronous navigations.
A navigable source is allowed by sandboxing to navigate a second navigable target, given a source snapshot params sourceSnapshotParams, if the following steps return true:
If source is target, then return true.
If source is an ancestor of target, then return true.
If target is an ancestor of source:
If target is not a top-level traversable, then return true.
If sourceSnapshotParams's has transient activation is true, and sourceSnapshotParams's sandboxing flags's sandboxed top-level navigation with user activation browsing context flag is set, then return false.
If sourceSnapshotParams's has transient activation is false, and sourceSnapshotParams's sandboxing flags's sandboxed top-level navigation without user activation browsing context flag is set, then return false.
Return true.
If target is a top-level traversable:
If source is the one permitted sandboxed navigator of target, then return true.
If sourceSnapshotParams's sandboxing flags's sandboxed navigation browsing context flag is set, then return false.
Return true.
If sourceSnapshotParams's sandboxing flags's sandboxed navigation browsing context flag is set, then return false.
Return true.
To check if unloading is canceled for a list of navigables navigablesThatNeedBeforeUnload, given an optional
traversable navigable traversable, an optional integer
targetStep, and an optional user navigation involvement
userInvolvementForNavigateEvent, run these steps. They return "canceled-by-beforeunload", "canceled-by-navigate", or
"continue".
Let documentsToFireBeforeunload be the active document of each item in navigablesThatNeedBeforeUnload.
Let unloadPromptShown be false.
Let finalStatus be "continue".
If traversable was given:
Assert: targetStep and userInvolvementForNavigateEvent were given.
Let targetEntry be the result of getting the target history entry given traversable and targetStep.
If targetEntry is not traversable's current session history entry, and targetEntry's document state's origin is the same as traversable's current session history entry's document state's origin:
In this case, we're going to fire the navigate event
for traversable here. Because under some circumstances it might be
canceled, we need to do this separately from other traversal navigate events, which happen later.
Additionally, because we want beforeunload events
to fire before navigate events, this means we need to
fire beforeunload for traversable here
(if applicable), instead of doing it as part of the below loop over
documentsToFireBeforeunload.
Let eventsFired be false.
Let needsBeforeunload be true if navigablesThatNeedBeforeUnload contains traversable; otherwise false.
If needsBeforeunload is true, then remove traversable's active document from documentsToFireBeforeunload.
Queue a global task on the navigation and traversal task source given traversable's active window to perform the following steps:
If needsBeforeunload is true:
Let (unloadPromptShownForThisDocument,
unloadPromptCanceledByThisDocument) be the result of running the steps
to fire beforeunload given
traversable's active document and
false.
If unloadPromptShownForThisDocument is true, then set unloadPromptShown to true.
If unloadPromptCanceledByThisDocument is true, then set
finalStatus to "canceled-by-beforeunload".
If finalStatus is "canceled-by-beforeunload", then
abort these steps.
Let navigation be traversable's active window's navigation API.
Let navigateEventResult be the result of firing a traverse navigate
event at navigation given targetEntry and
userInvolvementForNavigateEvent.
If navigateEventResult is false, then set finalStatus to
"canceled-by-navigate".
Set eventsFired to true.
Wait until eventsFired is true.
If finalStatus is not "continue", then return
finalStatus.
Let totalTasks be the size of documentsToFireBeforeunload.
Let completedTasks be 0.
For each document of documentsToFireBeforeunload, queue a global task on the navigation and traversal task source given document's relevant global object to run the steps:
Let (unloadPromptShownForThisDocument,
unloadPromptCanceledByThisDocument) be the result of running the steps to fire
beforeunload given document and
unloadPromptShown.
If unloadPromptShownForThisDocument is true, then set unloadPromptShown to true.
If unloadPromptCanceledByThisDocument is true, then set
finalStatus to "canceled-by-beforeunload".
Increment completedTasks.
Wait for completedTasks to be totalTasks.
Return finalStatus.
To set the ongoing navigation for a navigable navigable to newValue:
If navigable's ongoing navigation is equal to newValue, then return.
Inform the navigation API about aborting navigation given navigable.
Set navigable's ongoing navigation to newValue.
To attempt to populate the history entry's document for a session history
entry entry, given a navigable navigable, a
NavigationTimingType navTimingType, a source snapshot params
sourceSnapshotParams, a target snapshot params
targetSnapshotParams, a user navigation involvement
userInvolvement, an optional navigation ID-or-null navigationId
(default null), an optional navigation params-or-null navigationParams
(default null), an optional string cspNavigationType (default "other"), an optional boolean allowPOST (default false), and optional
algorithm steps completionSteps (default an empty
algorithm):
Assert: this is running in parallel.
Assert: if navigationParams is non-null, then navigationParams's response is non-null.
Let documentResource be entry's document state's resource.
If navigationParams is null:
If documentResource is a string, then set navigationParams to the result of creating navigation params from a srcdoc resource given entry, navigable, targetSnapshotParams, userInvolvement, navigationId, and navTimingType.
Otherwise, if all of the following are true:
entry's URL's scheme is a fetch scheme; and
documentResource is null, or allowPOST is true and documentResource's request body is not failure,
then set navigationParams to the result of creating navigation params by fetching given entry, navigable, sourceSnapshotParams, targetSnapshotParams, cspNavigationType, userInvolvement, navigationId, and navTimingType.
Otherwise, if entry's URL's scheme is not a fetch scheme, then set navigationParams to a new non-fetch scheme navigation params, with
To apply the traverse history step given a non-negative integer step to a traversable navigable traversable, with source snapshot params sourceSnapshotParams, navigable initiatorToCheck, and user navigation involvement userInvolvement:
Return the result of applying the history
step step to traversable given true,
sourceSnapshotParams, initiatorToCheck,
userInvolvement, and "traverse".
To update document for history step application given a Document
document, a session history entry entry, a boolean
doNotReactivate, integers scriptHistoryLength and
scriptHistoryIndex, NavigationType-or-null navigationType, an
optional list of session history entries
entriesForNavigationAPI, and an optional session history entry
previousEntryForActivation:
Let documentIsNew be true if document's latest entry is null; otherwise false.
Let documentsEntryChanged be true if document's latest entry is not entry; otherwise false.
Set document's history object's index to scriptHistoryIndex.
Set document's history object's length to scriptHistoryLength.
Let navigation be history's relevant global object's navigation API.
If documentsEntryChanged is true:
Let oldURL be document's latest entry's URL.
Set document's latest entry to entry.
Restore the history object state given document and entry.
If documentIsNew is false:
Assert: navigationType is not null.
Update the navigation API entries for a same-document navigation given navigation, entry, and navigationType.
Fire an event named popstate at document's relevant global
object, using PopStateEvent, with the state attribute initialized to document's
history object's state and hasUAVisualTransition initialized to
true if a visual transition, to display a cached rendered state of the latest
entry, was done by the user agent.
Restore persisted state given entry.
If oldURL's fragment is not
equal to entry's URL's fragment, then queue a global task on the
DOM manipulation task source given document's relevant global
object to fire an event named hashchange at document's relevant global
object, using HashChangeEvent, with the oldURL attribute initialized to the serialization of oldURL and the newURL attribute initialized to the serialization of entry's URL.
Otherwise:
Assert: entriesForNavigationAPI is given.
Restore persisted state given entry.
Initialize the navigation API entries for a new document given navigation, entriesForNavigationAPI, and entry.
If all the following are true:
previousEntryForActivation is given;
navigationType is non-null; and
navigationType is "reload" or
previousEntryForActivation's document is not
document,
then:
If navigation's activation is null, then set navigation's
activation to a new
NavigationActivation object in navigation's
relevant realm.
Let previousEntryIndex be the result of getting the navigation API entry index of previousEntryForActivation within navigation.
If previousEntryIndex is non-negative, then set activation's old entry to navigation's entry list[previousEntryIndex].
Otherwise, if all the following are true:
navigationType is "replace";
previousEntryForActivation's document state's origin is same origin with document's origin; and
previousEntryForActivation's document's
is initial about:blank is
false,
then set activation's old entry
to a new NavigationHistoryEntry in navigation's relevant realm, whose session history entry is
previousEntryForActivation.
Set activation's new entry to navigation's current entry.
Set activation's navigation type to navigationType.
If documentIsNew is true:
Assert: document's during-loading navigation ID for WebDriver BiDi is not null.
Invoke WebDriver BiDi navigation committed with navigable and a
new WebDriver BiDi navigation status whose id is document's during-loading navigation ID for WebDriver BiDi,
status is "committed", and url is document's URL.
Try to scroll to the fragment for document.
At this point scripts may run for the newly-created document document.
Otherwise, if documentsEntryChanged is false and doNotReactivate is false:
Assert: entriesForNavigationAPI is given.
Reactivate document given entry and entriesForNavigationAPI.
documentsEntryChanged can be false for one of two reasons: either we are restoring from bfcache, or we are asynchronously finishing up a synchronous navigation which already synchronously set document's latest entry. The doNotReactivate argument distinguishes between these two cases.
To restore the history object state given Document
document and session history entry entry:
Let targetRealm be document's relevant realm.
Let state be StructuredDeserialize(entry's classic history API state, targetRealm). If this throws an exception, catch it and let state be null.
Set document's history object's state to state.
To reactivate a
Document document given a session history entry
reactivatedEntry and a list of session history entries entriesForNavigationAPI:
This algorithm updates document after it has come out of bfcache, i.e., after it has been made fully active again. Other specifications that want to watch for this change to the fully active state are encouraged to add steps into this algorithm, so that the ordering of events that happen in effect of the change is clear.
For each
formControl of form controls in document with an autofill field
name of "off", invoke the reset algorithm for formControl.
If document's suspended timer handles is not empty:
Assert: document's suspension time is not zero.
Let suspendDuration be the current high resolution time minus document's suspension time.
Let activeTimers be document's relevant global object's map of active timers.
For each handle in document's suspended timer handles, if activeTimers[handle] exists, then increase activeTimers[handle] by suspendDuration.
Update the navigation API entries for reactivation given document's relevant global object's navigation API, entriesForNavigationAPI, and reactivatedEntry.
If document's current document readiness is "complete", and document's page showing is false:
Set document's page showing to true.
Set document's has been revealed to false.
Update the visibility state of document to "visible".
Fire a page transition event named pageshow at document's relevant global
object with true.
To try to scroll to the fragment for a Document document,
perform the following steps in parallel:
Wait for an implementation-defined amount of time. (This is intended to allow the user agent to optimize the user experience in the face of performance concerns.)
Queue a global task on the navigation and traversal task source given document's relevant global object to run these steps:
If document has no parser, or its parser has stopped parsing, or the user agent has reason to believe the user is no longer interested in scrolling to the fragment, then abort these steps.
Scroll to the fragment given document.
If document's indicated part is still null, then try to scroll to the fragment for document.
To restore persisted state from a session history entry entry:
If entry's scroll restoration
mode is "auto", and entry's
document's relevant global object's navigation API's suppress normal scroll restoration
during ongoing navigation is false, then restore scroll position data given
entry.
The user agent not restoring scroll positions does not imply that scroll positions will be left at any particular value (e.g., (0,0)). The actual scroll position depends on the navigation type and the user agent's particular caching strategy. So web applications cannot assume any particular scroll position but rather are urged to set it to what they want it to be.
If suppress normal scroll restoration during ongoing navigation is
true, then restoring scroll position data
might still happen at a later point, as part of finishing the relevant NavigateEvent, or via a
navigateEvent.scroll() method call.
Optionally, update other aspects of entry's document and its rendering, for instance values of form fields, that the user agent had previously recorded in entry's persisted user state.
This can even include updating the dir attribute
of textarea elements or input elements whose type attribute is in the Text, Search,
Telephone, URL, or Email
state, if the persisted state includes the directionality of user input in such controls.
Restoring the value of form controls as part of this process does not fire any
input or change events, but
can trigger the formStateRestoreCallback of form-associated custom elements.
To load a
multipart/x-mixed-replace document, given navigation params
navigationParams, source snapshot params sourceSnapshotParams,
and origin initiatorOrigin:
Parse navigationParams's response's body using the rules for multipart types. [RFC2046]
Let firstPartNavigationParams be a copy of navigationParams.
Set firstPartNavigationParams's response to a new response representing the first part of navigationParams's response's body's multipart stream.
Let document be the result of loading a document given firstPartNavigationParams, sourceSnapshotParams, and initiatorOrigin.
For each additional body part obtained from navigationParams's response, the user agent must navigate
document's node navigable to navigationParams's request's URL, using document, with response set to navigationParams's response and historyHandling set to "replace".
Return document.
To abort a document and its descendants given a Document
document:
Assert: this is running as part of a task queued on document's relevant agent's event loop.
Let descendantNavigables be document's descendant navigables.
For each descendantNavigable of descendantNavigables in what order?, queue a global task on the navigation and traversal task source given descendantNavigable's active window to perform the following steps:
Abort descendantNavigable's active document.
If descendantNavigable's active document's salvageable is false, then set document's salvageable to false.
Abort document.
The relevant agent for a platform object platformObject is platformObject's relevant realm's agent.
The relevant realm for a platform object is the value of its [[Realm]] field.
Similarly, the relevant global object for a platform object o is the global object of the relevant realm for o.
To queue a global task on a task source source, with a global object global and a series of steps steps:
Let event loop be global's relevant agent's event loop.
Let document be global's associated Document, if global is
a Window object; otherwise null.
Queue a task given source, event loop, document, and steps.