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:

  1. If document has no descendant base element that has an href attribute, then return document's fallback base URL.

  2. 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:

  1. If document is an iframe srcdoc document:

    1. Assert: document's about base URL is non-null.

    2. Return document's about base URL.

  2. If document's URL matches about:blank and document's about base URL is non-null, then return document's about base URL.

  3. Return document's URL.

The will lazy load element steps, given an element element, are as follows:

  1. 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.

  2. If element's lazy loading attribute is in the Lazy state, then return true.

  3. Return false.

To stop intersection-observing a lazy loading element element, run these steps:

  1. Let doc be element's node document.

  2. Assert: doc's lazy load intersection observer is not null.

  3. 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]

2.7.5 StructuredSerializeForStorage ( value )

  1. 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:

  1. Let current cues be a list of cues, initialized to contain all the cues of all the hidden 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.

  2. Let other cues be a list of cues, initialized to contain all the cues of hidden and showing text tracks of the media element that are not present in current cues.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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:

    1. Let track be the text track with which the text track cue target is associated.

    2. Create a task to fire an event named event at target.

    3. Add the newly created task to events, associated with the time time, the text track track, and the text track cue target.

    4. Add track to affected tracks.

  10. For each text track cue in missed cues, prepare an event named enter for the TextTrackCue object with the text track cue start time.

  11. 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.

  12. 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.

  13. 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.

  14. Queue a media element task given the media element for each task in events, in list order.

  15. Sort affected tracks in the same order as the text tracks appear in the media element's list of text tracks, and remove duplicates.

  16. 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.

  17. 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.

  18. 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:

  1. Assert: element is an input element whose type attribute is in the Color state.

  2. Let value be the result of running these steps:

    1. 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.

    2. Return element's value.

  3. Let color be the result of parsing value.

  4. If color is failure, then set color to opaque black.

  5. 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:

  1. If A and B are the same opaque origin, then return true.

  2. If A and B are both tuple origins and their schemes, hosts, and port are identical, then return true.

  3. Return false.

Two origins, A and B, are said to be same origin-domain if the following algorithm returns true:

  1. If A and B are the same opaque origin, then return true.

  2. If A and B are both tuple origins:

    1. If A and B's schemes are identical, and their domains are identical and non-null, then return true.

    2. Otherwise, if A and B are same origin and their domains are both null, return true.

  3. 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:

  1. Let directives be an empty ordered set.

  2. For each policy in cspList:

    1. If policy's disposition is not "enforce", then continue.

    2. If policy's directive set contains a directive whose name is "sandbox", then append that directive to directives.

  3. If directives is empty, then return an empty sandboxing flag set.

  4. Let directive be directives[directives's size − 1].

  5. Return the result of parsing the sandboxing directive directive.

To clone a policy container given a policy container policyContainer:

  1. Let clone be a new policy container.

  2. For each policy in policyContainer's CSP list, append a copy of policy into clone's CSP list.

  3. Set clone's embedder policy to a copy of policyContainer's embedder policy.

  4. Set clone's referrer policy to policyContainer's referrer policy.

  5. Set clone's integrity policy to a copy of policyContainer's integrity policy.

  6. Return clone.

To determine navigation params policy container given a URL responseURL and four policy container-or-nulls historyPolicyContainer, initiatorPolicyContainer, parentPolicyContainer, and responsePolicyContainer:

  1. If historyPolicyContainer is not null:

    1. Assert: responseURL requires storing the policy container in history.

    2. Return a clone of historyPolicyContainer.

  2. If responseURL is about:srcdoc:

    1. Assert: parentPolicyContainer is not null.

    2. Return a clone of parentPolicyContainer.

  3. If responseURL is local and initiatorPolicyContainer is not null, then return a clone of initiatorPolicyContainer.

  4. If responsePolicyContainer is not null, then return responsePolicyContainer.

  5. Return a new policy container.

To Location-object navigate a Location object location to a URL url, optionally given a NavigationHistoryBehavior historyHandling (default "auto"):

  1. Let navigable be location's relevant global object's navigable.

  2. Let sourceDocument be the incumbent global object's associated Document.

  3. 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".

  4. Navigate navigable to url using sourceDocument, with exceptionsEnabled set to true and historyHandling set to historyHandling.

The assign(url) method steps are:

  1. If this's relevant Document is null, then return.

  2. If this's relevant Document's origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.

  3. Let urlRecord be the result of encoding-parsing a URL given url, relative to the entry settings object.

  4. If urlRecord is failure, then throw a "SyntaxError" DOMException.

  5. 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:

  1. If navigation has entries and events disabled, then return null.

  2. Assert: navigation's current entry index is not −1.

  3. 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:

  1. Let index be 0.

  2. For each nhe of navigation's entry list:

    1. If nhe's session history entry is equal to she, then return index.

    2. Increment index by 1.

  3. 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:

  1. Assert: navigation's entry list is empty.

  2. Assert: navigation's current entry index is −1.

  3. If navigation has entries and events disabled, then return.

  4. For each newSHE of newSHEs:

    1. Let newNHE be a new NavigationHistoryEntry created in the relevant realm of navigation.

    2. Set newNHE's session history entry to newSHE.

    3. 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.

  5. 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:

  1. If navigation has entries and events disabled, then return.

  2. Let oldCurrentNHE be the current entry of navigation.

  3. Let disposedNHEs be a new empty list.

  4. If navigationType is "traverse":

    1. Set navigation's current entry index to the result of getting the navigation API entry index of destinationSHE within navigation.

    2. 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.

  5. Otherwise, if navigationType is "push":

    1. Set navigation's current entry index to navigation's current entry index + 1.

    2. Let i be navigation's current entry index.

    3. While i < navigation's entry list's size:

      1. Append navigation's entry list[i] to disposedNHEs.

      2. Set i to i + 1.

    4. Remove all items in disposedNHEs from navigation's entry list.

  6. Otherwise, if navigationType is "replace":

    1. Append oldCurrentNHE to disposedNHEs.

  7. If navigationType is "push" or "replace":

    1. Let newNHE be a new NavigationHistoryEntry created in the relevant realm of navigation.

    2. Set newNHE's session history entry to destinationSHE.

    3. Set navigation's entry list[navigation's current entry index] to newNHE.

  8. 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.

  9. Let navigateEvent be navigation's ongoing navigate event.

  10. Let apiMethodTracker be navigation's ongoing API method tracker.

  11. Prepare to run script given navigation's relevant settings object.

    See the discussion for other navigation API events to understand why we do this.

  12. Fire an event named currententrychange at navigation using NavigationCurrentEntryChangeEvent, with its navigationType attribute initialized to navigationType and its from initialized to oldCurrentNHE.

  13. For each disposedNHE of disposedNHEs:

    1. Fire an event named dispose at disposedNHE.

  14. Run the navigate event intercept commit handler steps given navigation, navigateEvent, and apiMethodTracker.

  15. 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"):

  1. Let event be the result of creating an event given NavigateEvent, in navigation's relevant realm.

  2. Set event's classic history API state to null.

  3. Let destination be a new NavigationDestination created in navigation's relevant realm.

  4. Set destination's URL to destinationSHE's URL.

  5. Let destinationNHE be the NavigationHistoryEntry in navigation's entry list whose session history entry is destinationSHE, or null if no such NavigationHistoryEntry exists.

  6. If destinationNHE is non-null:

    1. Set destination's entry to destinationNHE.

    2. Set destination's state to destinationSHE's navigation API state.

  7. Otherwise,

    1. Set destination's entry to null.

    2. Set destination's state to StructuredSerializeForStorage(null).

  8. 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.

  9. 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:

  1. Let document be navigation's relevant global object's associated Document.

  2. Inform the navigation API about aborting navigation in document's node navigable.

  3. If navigation has entries and events disabled, and apiMethodTracker is not null:

    1. Set apiMethodTracker's pending to false.

    2. 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.

  4. If document is not fully active, then return false.

  5. Let event be the result of creating an event given NavigateEvent, in navigation's relevant realm.

  6. Set event's classic history API state to classicHistoryAPIState.

  7. Let destination be a new NavigationDestination created in navigation's relevant realm.

  8. Set destination's URL to destinationURL.

  9. Set destination's entry to null.

  10. Set destination's state to navigationAPIState.

  11. Set destination's is same document to isSameDocument.

  12. 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):

  1. If navigation has entries and events disabled:

    1. Assert: navigation's ongoing API method tracker is null.

    2. Assert: navigation's upcoming traverse API method trackers is empty.

    3. Assert: apiMethodTracker is null.

    4. 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).

  2. Assert: navigation's ongoing API method tracker is null.

  3. If destination's entry is non-null:

    1. Assert: apiMethodTracker is null.

      apiMethodTracker is passed as an argument only for navigate() and reload() calls.

    2. Let destinationKey be destination's entry's key.

    3. Assert: destinationKey is not the empty string.

    4. If navigation's upcoming traverse API method trackers[destinationKey] exists:

      1. Set apiMethodTracker to navigation's upcoming traverse API method trackers[destinationKey].

      2. Remove navigation's upcoming traverse API method trackers[destinationKey].

  4. If apiMethodTracker is not null:

    1. Set navigation's ongoing API method tracker to apiMethodTracker.

    2. Set apiMethodTracker's pending to false.

  5. Let navigable be navigation's relevant global object's navigable.

  6. Let document be navigation's relevant global object's associated Document.

  7. 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.

  8. If either:

    • navigationType is not "traverse"; or

    • traverseCanBeCanceled is true,

    then initialize event's cancelable to true. Otherwise, initialize it to false.

  9. Initialize event's type to "navigate".

  10. Initialize event's navigationType to navigationType.

  11. Initialize event's destination to destination.

  12. Initialize event's downloadRequest to downloadRequestFilename.

  13. 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.

  14. 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.

  15. Initialize event's sourceElement to sourceElement.

  16. Set event's abort controller to a new AbortController created in navigation's relevant realm.

  17. Initialize event's signal to event's abort controller's signal.

  18. Let currentURL be document's URL.

  19. If all of the following are true:

    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").

  20. If userInvolvement is not "none", then initialize event's userInitiated to true. Otherwise, initialize it to false.

  21. 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.

  22. Assert: navigation's ongoing navigate event is null.

  23. Set navigation's ongoing navigate event to event.

  24. Set navigation's focus changed during ongoing navigation to false.

  25. Set navigation's suppress normal scroll restoration during ongoing navigation to false.

  26. Let dispatchResult be the result of dispatching event at navigation.

  27. If dispatchResult is false:

    1. If navigationType is "traverse", then consume history-action user activation given navigation's relevant global object.

    2. If event's abort controller's signal is not aborted, then abort the ongoing navigation given navigation.

    3. Return false.

  28. If event's interception state is not "none":

    1. Let fromNHE be the current entry of navigation.

    2. Assert: fromNHE is not null.

    3. Set navigation's transition to a new NavigationTransition created in navigation's relevant realm, with

      navigation type
      navigationType
      from entry
      fromNHE
      destination
      event's destination
      committed promise
      a new promise created in navigation's relevant realm
      finished promise
      a new promise created in navigation's relevant realm
    4. Mark as handled navigation's transition's finished promise.

      See the discussion about other finished promises to understand why this is done.

    5. Mark as handled navigation's transition's committed promise.

  29. If event's navigation precommit handler list is empty then commit event given apiMethodTracker.

  30. Otherwise:

    1. Let precommitController be a new NavigationPrecommitController created in navigation's relevant realm, whose event is event.

    2. Let precommitPromisesList be an empty list.

    3. For each handler of event's navigation precommit handler list:

      1. Append the result of invoking handler with « precommitController » to precommitPromisesList.

    4. 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.

  31. If event's interception state is "none", then return true.

  32. 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:

  1. Let navigable be inputNavigable.

  2. While navigable is not a traversable navigable, set navigable to navigable's parent.

  3. 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:

  1. If navigable's container is null, then return null.

  2. 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:

  1. Let navigables be « document's node navigable ».

  2. Extend navigables with document's descendant navigables.

  3. Return navigables.

To determine the origin, given a URL url, a sandboxing flag set sandboxFlags, and an origin-or-null sourceOrigin:

  1. If sandboxFlags has its sandboxed origin browsing context flag set, then return a new opaque origin.

  2. If url is null, then return a new opaque origin.

  3. If url is about:srcdoc:

    1. Assert: sourceOrigin is non-null.

    2. Return sourceOrigin.

  4. If url matches about:blank and sourceOrigin is non-null, then return sourceOrigin.

  5. 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:

  1. If sourceDocument is null, then return a new source snapshot params with

    has transient activation
    true
    sandboxing flags
    an empty sandboxing flag set
    allows downloading
    true
    fetch client
    null
    source policy container
    a new policy container

    This only occurs in the case of a browser UI-initiated navigation.

  2. Return a new source snapshot params with

    has transient activation
    true if sourceDocument's relevant global object has transient activation; otherwise false
    sandboxing flags
    sourceDocument's active sandboxing flag set
    allows downloading
    false if sourceDocument's active sandboxing flag set has the sandboxed downloads browsing context flag set; otherwise true
    fetch client
    sourceDocument's relevant settings object
    source policy container
    a clone of sourceDocument's policy container

To snapshot target snapshot params given a navigable targetNavigable, return a new target snapshot params with:

sandboxing flags
the result of determining the creation sandboxing flags given targetNavigable's active browsing context and targetNavigable's container
iframe element referrer policy
the result of determining the iframe element referrer policy given targetNavigable's container

The navigation must be a replace, given a URL url and a Document document, if any of the following are 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):

  1. Let cspNavigationType be "form-submission" if formDataEntryList is non-null; otherwise "other".

  2. Let sourceSnapshotParams be the result of snapshotting source snapshot params given sourceDocument.

  3. Let initiatorOriginSnapshot be a new opaque origin.

  4. Let initiatorBaseURLSnapshot be about:blank.

  5. If sourceDocument is null:

    1. Assert: userInvolvement is "browser UI".

    2. If url's scheme is "javascript", then set initiatorOriginSnapshot to navigable's active document's origin.

  6. Otherwise:

    1. Assert: userInvolvement is not "browser UI".

    2. Set initiatorOriginSnapshot to sourceDocument's origin.

    3. Set initiatorBaseURLSnapshot to sourceDocument's document base URL.

  7. Let navigationId be the result of generating a random UUID. [WEBCRYPTO]

  8. 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.

  9. 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.

  10. Let container be navigable's container.

  11. 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.

  12. 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.

  13. If the navigation must be a replace given url and navigable's active document, then set historyHandling to "replace".

  14. If navigable's parent is non-null, then set navigable's is delaying load events to true.

  15. Let targetSnapshotParams be the result of snapshotting target snapshot params given navigable.

  16. 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.

  17. If navigable's ongoing navigation is "traversal":

    1. 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.

    2. Return.

    Any attempts to navigate a navigable that is currently traversing are ignored.

  18. 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.

  19. If url's scheme is "javascript":

    1. Let request be a new request, with

      URL
      url
      client
      sourceSnapshotParams's fetch client
      policy container
      sourceSnapshotParams's source policy container

      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.

    2. 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.

    3. Return.

  20. If all of the following are true:

    then:

    1. Let navigation be navigable's active window's navigation API.

    2. Let entryListForFiring be formDataEntryList if documentResource is a POST resource; otherwise, null.

    3. Let navigationAPIStateForFiring be navigationAPIState if navigationAPIState is not null; otherwise, StructuredSerializeForStorage(undefined).

    4. 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.

    5. 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.

  21. If sourceDocument is navigable's container document, then reserve deferred fetch quota for navigable's container given url's origin.

  22. In parallel, run these steps:

    1. Let unloadPromptCanceled be the result of checking if unloading is canceled for navigable's active document's inclusive descendant navigables.

    2. If unloadPromptCanceled is not "continue", or navigable's ongoing navigation is no longer navigationId:

      1. 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.

      2. Abort these steps.

    3. 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.

    4. If url matches about:blank or is about:srcdoc:

      1. Set documentState's origin to initiatorOriginSnapshot.

      2. Set documentState's about base URL to initiatorBaseURLSnapshot.

    5. Let historyEntry be a new session history entry, with its URL set to url and its document state set to documentState.

    6. Let navigationParams be null.

    7. If response is non-null:

      The navigate algorithm is only supplied with a response as part of the object and embed processing models, or for processing parts of multipart/x-mixed-replace responses after the initial response.

      1. Let sourcePolicyContainer be a clone of the sourceDocument's policy container, if sourceDocument is not null; otherwise null.

      2. 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.

      3. Let finalSandboxFlags be the union of targetSnapshotParams's sandboxing flags and policyContainer's CSP list's CSP-derived sandboxing flags.

      4. Let responseOrigin be the result of determining the origin given response's URL, finalSandboxFlags, and documentState's initiator origin.

      5. Let coop be a new opener policy.

      6. Let coopEnforcementResult be a new opener policy enforcement result with

        url
        response's URL
        origin
        responseOrigin
        opener policy
        coop
      7. Set navigationParams to a new navigation params, with

        id
        navigationId
        navigable
        navigable
        request
        null
        response
        response
        fetch controller
        null
        commit early hints
        null
        COOP enforcement result
        coopEnforcementResult
        reserved environment
        null
        origin
        responseOrigin
        policy container
        policyContainer
        final sandboxing flag set
        finalSandboxFlags
        iframe element referrer policy
        targetSnapshotParams's iframe element referrer policy
        opener policy
        coop
        navigation timing type
        "navigate"
        about base URL
        documentState's about base URL
        user involvement
        userInvolvement
    8. 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:

      1. 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:

  1. Assert: this is running on navigable's traversable navigable's session history traversal queue.

  2. Set navigable's is delaying load events to false.

  3. 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.

  4. If all of the following are true:

    then set historyEntry's document state's navigable target name to the empty string.

  5. Let entryToReplace be navigable's active session history entry if historyHandling is "replace", otherwise null.

  6. Let traversable be navigable's traversable navigable.

  7. Let targetStep be null.

  8. Let targetEntries be the result of getting session history entries for navigable.

  9. If entryToReplace is null:

    1. Clear the forward session history of traversable.

    2. Set targetStep to traversable's current session history step + 1.

    3. Set historyEntry's step to targetStep.

    4. Append historyEntry to targetEntries.

    Otherwise:

    1. Replace entryToReplace with historyEntry in targetEntries.

    2. Set historyEntry's step to entryToReplace's step.

    3. 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.

    4. Set targetStep to traversable's current session history step.

  10. 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:

  1. Assert: historyHandling is "replace".

  2. If targetNavigable's ongoing navigation is no longer navigationId, then return.

  3. Set the ongoing navigation for targetNavigable to null.

  4. If initiatorOrigin is not same origin-domain with targetNavigable's active document's origin, then return.

  5. 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]

  6. Let newDocument be the result of evaluating a javascript: URL given targetNavigable, request's URL, initiatorOrigin, userInvolvement, and navigationId.

  7. If newDocument is null:

    1. 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.

    2. Return.

    In this case, some JavaScript code was executed, but no new Document was created, so we will not perform a navigation.

  8. Assert: initiatorOrigin is newDocument's origin.

  9. Let entryToReplace be targetNavigable's active session history entry.

  10. Let oldDocState be entryToReplace's document state.

  11. Let documentState be a new document state with

    document
    newDocument
    history policy container
    a clone of the oldDocState's history policy container if it is non-null; null otherwise
    request referrer
    oldDocState's request referrer
    request referrer policy
    oldDocState's request referrer policy or should this be the referrerPolicy that was passed to navigate?
    initiator origin
    initiatorOrigin
    origin
    initiatorOrigin
    about base URL
    oldDocState's about base URL
    resource
    null
    ever populated
    true
    navigable target name
    oldDocState's navigable target name
  12. Let historyEntry be a new session history entry, with

    URL
    entryToReplace's URL
    document state
    documentState

    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.

  13. 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:

  1. Let navigation be navigable's active window's navigation API.

  2. Let destinationNavigationAPIState be navigable's active session history entry's navigation API state.

  3. If navigationAPIState is not null, then set destinationNavigationAPIState to navigationAPIState.

  4. 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.

  5. If continue is false:

    1. 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().

    2. Return.

  6. Let historyEntry be a new session history entry, with

    URL
    url
    document state
    navigable's active session history entry's document state
    navigation API state
    destinationNavigationAPIState
    scroll restoration mode
    navigable's active session history entry's scroll restoration mode

    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.

  7. Let entryToReplace be navigable's active session history entry if historyHandling is "replace", otherwise null.

  8. If entryToReplace is non-null, then set historyEntry's navigation API key to entryToReplace's navigation API key.

  9. Let history be navigable's active document's history object.

  10. Let scriptHistoryIndex be history's index.

  11. Let scriptHistoryLength be history's length.

  12. If historyHandling is "push":

    1. Set history's state to null.

    2. Increment scriptHistoryIndex.

    3. Set scriptHistoryLength to scriptHistoryIndex + 1.

  13. Set navigable's active document's URL to url.

  14. Set navigable's active session history entry to historyEntry.

  15. 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.

  16. 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.

  17. Let traversable be navigable's traversable navigable.

  18. Append the following session history synchronous navigation steps involving navigable to traversable:

    1. Finalize a same-document navigation given traversable, navigable, historyEntry, entryToReplace, historyHandling, and userInvolvement.

    2. 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.

  1. Assert: this is running on traversable's session history traversal queue.

  2. If targetNavigable's active session history entry is not targetEntry, then return.

  3. Let targetStep be null.

  4. Let targetEntries be the result of getting session history entries for targetNavigable.

  5. If entryToReplace is null:

    1. Clear the forward session history of traversable.

    2. Set targetStep to traversable's current session history step + 1.

    3. Set targetEntry's step to targetStep.

    4. Append targetEntry to targetEntries.

    Otherwise:

    1. Replace entryToReplace with targetEntry in targetEntries.

    2. Set targetEntry's step to entryToReplace's step.

    3. Set targetStep to traversable's current session history step.

  6. 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:

  1. If source is target, then return true.

  2. If source is an ancestor of target, then return true.

  3. If target is an ancestor of source:

    1. If target is not a top-level traversable, then return true.

    2. 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.

    3. 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.

    4. Return true.

  4. If target is a top-level traversable:

    1. If source is the one permitted sandboxed navigator of target, then return true.

    2. If sourceSnapshotParams's sandboxing flags's sandboxed navigation browsing context flag is set, then return false.

    3. Return true.

  5. If sourceSnapshotParams's sandboxing flags's sandboxed navigation browsing context flag is set, then return false.

  6. 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".

  1. Let documentsToFireBeforeunload be the active document of each item in navigablesThatNeedBeforeUnload.

  2. Let unloadPromptShown be false.

  3. Let finalStatus be "continue".

  4. If traversable was given:

    1. Assert: targetStep and userInvolvementForNavigateEvent were given.

    2. Let targetEntry be the result of getting the target history entry given traversable and targetStep.

    3. 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.

      1. Let eventsFired be false.

      2. Let needsBeforeunload be true if navigablesThatNeedBeforeUnload contains traversable; otherwise false.

      3. If needsBeforeunload is true, then remove traversable's active document from documentsToFireBeforeunload.

      4. Queue a global task on the navigation and traversal task source given traversable's active window to perform the following steps:

        1. If needsBeforeunload is true:

          1. Let (unloadPromptShownForThisDocument, unloadPromptCanceledByThisDocument) be the result of running the steps to fire beforeunload given traversable's active document and false.

          2. If unloadPromptShownForThisDocument is true, then set unloadPromptShown to true.

          3. If unloadPromptCanceledByThisDocument is true, then set finalStatus to "canceled-by-beforeunload".

        2. If finalStatus is "canceled-by-beforeunload", then abort these steps.

        3. Let navigation be traversable's active window's navigation API.

        4. Let navigateEventResult be the result of firing a traverse navigate event at navigation given targetEntry and userInvolvementForNavigateEvent.

        5. If navigateEventResult is false, then set finalStatus to "canceled-by-navigate".

        6. Set eventsFired to true.

      5. Wait until eventsFired is true.

      6. If finalStatus is not "continue", then return finalStatus.

  5. Let totalTasks be the size of documentsToFireBeforeunload.

  6. Let completedTasks be 0.

  7. 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:

    1. Let (unloadPromptShownForThisDocument, unloadPromptCanceledByThisDocument) be the result of running the steps to fire beforeunload given document and unloadPromptShown.

    2. If unloadPromptShownForThisDocument is true, then set unloadPromptShown to true.

    3. If unloadPromptCanceledByThisDocument is true, then set finalStatus to "canceled-by-beforeunload".

    4. Increment completedTasks.

  8. Wait for completedTasks to be totalTasks.

  9. Return finalStatus.

To set the ongoing navigation for a navigable navigable to newValue:

  1. If navigable's ongoing navigation is equal to newValue, then return.

  2. Inform the navigation API about aborting navigation given navigable.

  3. 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):

  1. Assert: this is running in parallel.

  2. Assert: if navigationParams is non-null, then navigationParams's response is non-null.

  3. Let documentResource be entry's document state's resource.

  4. If navigationParams is null:

    1. 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.

    2. Otherwise, if all of the following are true:

      then set navigationParams to the result of creating navigation params by fetching given entry, navigable, sourceSnapshotParams, targetSnapshotParams, cspNavigationType, userInvolvement, navigationId, and navTimingType.

    3. Otherwise, if entry's URL's scheme is not a fetch scheme, then set navigationParams to a new non-fetch scheme navigation params, with

      id
      navigationId
      navigable
      navigable
      URL
      entry's URL
      target snapshot sandboxing flags
      targetSnapshotParams's sandboxing flags
      source snapshot has transient activation
      sourceSnapshotParams's has transient activation
      initiator origin
      entry's document state's initiator origin
      navigation timing type
      navTimingType
      user involvement
      userInvolvement
  5. Queue a global task on the navigation and traversal task source, given navigable's active window, to run these steps:

    1. If navigable's ongoing navigation no longer equals navigationId, then run completionSteps and abort these steps.

    2. Let saveExtraDocumentState be true.

      Usually, in the cases where we end up populating entry's document state's document, we then want to save some of the state from that Document into entry. This ensures that if there are future traversals to entry where its document has been destroyed, we can use that state when creating a new Document.

      However, in some specific cases, saving the state would be unhelpful. For those, we set saveExtraDocumentState to false later in this algorithm.

    3. If navigationParams is a non-fetch scheme navigation params:

      1. Set entry's document state's document to the result of running attempt to create a non-fetch scheme document given navigationParams.

        This can result in setting entry's document state's document to null, e.g., when handing-off to external software.

      2. Set saveExtraDocumentState to false.

    4. Otherwise, if any of the following are true:

      then:

      1. Set entry's document state's document to the result of creating a document for inline content that doesn't have a DOM, given navigable, null, navTimingType, and userInvolvement. The inline content should indicate to the user the sort of error that occurred.

      2. Make document unsalvageable given entry's document state's document and "navigation-failure".

      3. Set saveExtraDocumentState to false.

      4. If navigationParams is not null:

        1. Run the environment discarding steps for navigationParams's reserved environment.

        2. Invoke WebDriver BiDi navigation failed with navigable and a new WebDriver BiDi navigation status whose id is navigationId, status is "canceled", and url is navigationParams's response's URL.

    5. Otherwise, if navigationParams's response's status is not 204 and is not 205, then set entry's document state's document to the result of loading a document given navigationParams, sourceSnapshotParams, and entry's document state's initiator origin.

      This can result in setting entry's document state's document to null, e.g., when handing-off to external software.

    6. If entry's document state's document is not null:

      1. Set entry's document state's ever populated to true.

      2. If saveExtraDocumentState is true:

        1. Let document be entry's document state's document.

        2. Set entry's document state's origin to document's origin.

        3. If document's URL requires storing the policy container in history:

          1. Assert: navigationParams is a navigation params (i.e., neither null nor a non-fetch scheme navigation params).

          2. Set entry's document state's history policy container to navigationParams's policy container.

      3. If entry's document state's request referrer is "client", and navigationParams is a navigation params (i.e., neither null nor a non-fetch scheme navigation params):

        1. Assert: navigationParams's request is not null.

        2. Set entry's document state's request referrer to navigationParams's request's referrer.

    7. Run completionSteps.

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:

  1. 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:

  1. Let documentIsNew be true if document's latest entry is null; otherwise false.

  2. Let documentsEntryChanged be true if document's latest entry is not entry; otherwise false.

  3. Set document's history object's index to scriptHistoryIndex.

  4. Set document's history object's length to scriptHistoryLength.

  5. Let navigation be history's relevant global object's navigation API.

  6. If documentsEntryChanged is true:

    1. Let oldURL be document's latest entry's URL.

    2. Set document's latest entry to entry.

    3. Restore the history object state given document and entry.

    4. If documentIsNew is false:

      1. Assert: navigationType is not null.

      2. Update the navigation API entries for a same-document navigation given navigation, entry, and navigationType.

      3. 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.

      4. Restore persisted state given entry.

      5. 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.

    5. Otherwise:

      1. Assert: entriesForNavigationAPI is given.

      2. Restore persisted state given entry.

      3. Initialize the navigation API entries for a new document given navigation, entriesForNavigationAPI, and entry.

  7. 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:

    1. If navigation's activation is null, then set navigation's activation to a new NavigationActivation object in navigation's relevant realm.

    2. Let previousEntryIndex be the result of getting the navigation API entry index of previousEntryForActivation within navigation.

    3. If previousEntryIndex is non-negative, then set activation's old entry to navigation's entry list[previousEntryIndex].

    4. Otherwise, if all the following are true:

      then set activation's old entry to a new NavigationHistoryEntry in navigation's relevant realm, whose session history entry is previousEntryForActivation.

    5. Set activation's new entry to navigation's current entry.

    6. Set activation's navigation type to navigationType.

  8. If documentIsNew is true:

    1. Assert: document's during-loading navigation ID for WebDriver BiDi is not null.

    2. 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.

    3. Try to scroll to the fragment for document.

    4. At this point scripts may run for the newly-created document document.

  9. Otherwise, if documentsEntryChanged is false and doNotReactivate is false:

    1. Assert: entriesForNavigationAPI is given.

    2. 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:

  1. Let targetRealm be document's relevant realm.

  2. Let state be StructuredDeserialize(entry's classic history API state, targetRealm). If this throws an exception, catch it and let state be null.

  3. 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.

  1. For each formControl of form controls in document with an autofill field name of "off", invoke the reset algorithm for formControl.

  2. If document's suspended timer handles is not empty:

    1. Assert: document's suspension time is not zero.

    2. Let suspendDuration be the current high resolution time minus document's suspension time.

    3. Let activeTimers be document's relevant global object's map of active timers.

    4. For each handle in document's suspended timer handles, if activeTimers[handle] exists, then increase activeTimers[handle] by suspendDuration.

  3. Update the navigation API entries for reactivation given document's relevant global object's navigation API, entriesForNavigationAPI, and reactivatedEntry.

  4. If document's current document readiness is "complete", and document's page showing is false:

    1. Set document's page showing to true.

    2. Set document's has been revealed to false.

    3. Update the visibility state of document to "visible".

    4. 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:

  1. 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.)

  2. Queue a global task on the navigation and traversal task source given document's relevant global object to run these steps:

    1. 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.

    2. Scroll to the fragment given document.

    3. 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:

  1. 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.

  2. 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:

  1. Parse navigationParams's response's body using the rules for multipart types. [RFC2046]

  2. Let firstPartNavigationParams be a copy of navigationParams.

  3. Set firstPartNavigationParams's response to a new response representing the first part of navigationParams's response's body's multipart stream.

  4. 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".

  5. Return document.

To abort a document and its descendants given a Document document:

  1. Assert: this is running as part of a task queued on document's relevant agent's event loop.

  2. Let descendantNavigables be document's descendant navigables.

  3. 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:

    1. Abort descendantNavigable's active document.

    2. If descendantNavigable's active document's salvageable is false, then set document's salvageable to false.

  4. 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:

  1. Let event loop be global's relevant agent's event loop.

  2. Let document be global's associated Document, if global is a Window object; otherwise null.

  3. Queue a task given source, event loop, document, and steps.