From 8cf2e3eef87b8c296fd11f41b46c3366897a5abd Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 23 Mar 2021 17:41:25 +0200 Subject: [PATCH] WIP: Navigation Timing integration Create a "document load timing info" struct, associated with a document, which receives its information from several sources: - fetch timing of the navigation response - Load/DOMContentLoaded event dispatches - Document readyness state changes - sending unload events to the previous document, if it comes from the same origin. See https://github.com/w3c/navigation-timing/issues/136 Depends on https://github.com/whatwg/fetch/pull/1185 --- source | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 119 insertions(+), 13 deletions(-) diff --git a/source b/source index 4ec75524516..4c5b9fbdcfa 100644 --- a/source +++ b/source @@ -9361,8 +9361,21 @@ partial interface Document { data-x="">loading" if the document is associated with an HTML parser, an XML parser, or an XSLT processor, and to the string "complete" otherwise. Various algorithms during page loading affect this value. When the value is set, the - user agent must fire an event named readinessValue: +
    +
  1. Let now be the current high resolution time. + +

  2. If readinessValue is "complete", then set the + Document's load timing info's + dom complete time to now. + +

  3. Otherwise, if readinessValue is "interactive", then set + the Document's load timing info's + dom interactive time to now. + +

  4. Fire an event named readystatechange at the Document object.

    +

A Document is said to have an active parser if it is associated with an HTML parser or an XML parser that has not yet been history handling

a history handling behavior
+ +
dfn data-x="navigation-params-cross-origin-redirects">cross-origin redirects flag +
a flag, unset by default.

Once a navigation params struct is created, this standard does not mutate any of its items. They are only passed onward to other algorithms.

+

A Document has a document load timing info + load timing info. + +

The document load timing info struct has the following + items:

+
+
fetch timing +
A fetch timing infoprevious document unload timing +
An unload timing infodom interactive time (default 0) +
dom content loaded event start time (default 0) +
dom content loaded event end time (default 0) +
dom complete time (default 0) +
load event start time (default 0) +
load event end time (default 0) +
A DOMHighResTimeStamp. + +
redirect count (default zero) +
A number. +
+ + +

The unload timing info struct has the following + items:

+
+
unload event start time (default zero) +
unload event end time (default zero) +
A DOMHighResTimeStamp. +
+

After Document creation, the session history gets updated. A history handling behavior is used to track the desired type of session history update throughout the navigation process. It is one of the following:

@@ -84929,12 +84978,19 @@ interface Location { // but see also
current URL.

+
  • Let hasCrossOriginRedirectsFlag be an unset flag. +

  • While true:

      -
    1. If locationURL is non-null, then set currentURL to - locationURL.

    2. +
    3. If locationURL is non-null, then perform the following steps: +

        +
      1. If locationURL is not the same as + currentURL, then set hasCrossOriginRedirectsFlag. + +

      2. Set currentURL to locationURL.

      3. +
    4. If request's reserved @@ -85127,8 +85183,9 @@ interface Location { // but see also reserved environment is request's reserved client, browsing context is - browsingContext, and history handling is - historyHandling.

    5. + browsingContext, history handling is + historyHandling, and has + cross-origin redirects flag is hasCrossOriginRedirectsFlag.

    6. Run process a navigate response with navigationType, allowedToDownload, hasTransientActivation, and @@ -85612,6 +85669,15 @@ interface Location { // but see also fetch timing set to navigationParams's response's timing info, + its redirect count set to navigationParams's + request's redirect count, and + its previous document unload timing set to a new + unload timing info. +

    7. If navigationParams's response has a `Refresh` header, then:

      @@ -85688,10 +85754,14 @@ new PaymentRequest(…); // Allowed to use data-x="navigation-params-browsing-context">browsing context's session history.

    8. +
    9. Let unloadTimingInfo be to a new unload timing info. + +

    10. Let previousDocument be sessionHistory's current + entry's document. +

    11. -

      Unload sessionHistory's current - entry's document.

      +

      Unload previousDocument with + unloadTimingInfo.

      If this instance of the navigation algorithm is canceled while this step is running the unload a document algorithm, then the unload a @@ -85701,6 +85771,14 @@ new PaymentRequest(…); // Allowed to use execution occurring as part of unloading the document or its descendants.)

    12. +
    13. If navigationParams's has cross-origin + redirects is not set, previousDocument is not null, and + newDocument's origin is the same as + previousDocument's origin, then set + newDocument's load timing info's + previous document unload timing to + unloadTimingInfo. +

    14. Switch on navigationParams's history handling:

      @@ -86805,7 +86883,8 @@ dictionary PageTransitionEventInit : EventInit {

    To unload a - Document document, optionally given a recursiveFlag:

    + Document document, given an optional recursiveFlag and + an optional unload timing info unloadTimingInfo:

    1. Increase the event loop's termination nesting level by @@ -86841,12 +86920,20 @@ dictionary PageTransitionEventInit : EventInit {

    2. +
    3. If unloadTimingInfo is given, set unloadTimingInfo's + unload event start time to the + current high resolution time. +

    4. Unload event: If document's salvageable state is false, then fire an event named unload at document's relevant global object, with legacy target override flag set.

    5. +
    6. If unloadTimingInfo is given, set unloadTimingInfo's + unload event end time to the + current high resolution time. +

    7. Decrease the event loop's termination nesting level by one.

    8. @@ -111492,11 +111579,19 @@ document.body.appendChild(text); Document's relevant global object to run the following substeps:

        +
      1. Set the Document's load timing info's + dom content loaded event start time to the + current high resolution time. +

      2. Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true.

      3. +
      4. Set the Document's load timing info's + dom content loaded event end time to the + current high resolution time. +

      5. Enable the client message queue of the ServiceWorkerContainer object whose associated service worker client is the @@ -111523,10 +111618,21 @@ document.body.appendChild(text); this also fires an event immediately during the task -->.

      6. Load event: If the Document object's browsing context is non-null, then fire an event named load at - the Document object's relevant global object, with legacy target - override flag set.

      7. + data-x="concept-document-bc">browsing context is non-null, then perform the following + steps: +
          +
        1. Set the Document's load timing info's + load event start time to the + current high resolution time. + +

        2. Fire an event named + load at the Document object's + relevant global object, with legacy target override flag set.

        3. + +
        4. Set the Document's load timing info's + load event end time to the + current high resolution time. +