Skip to content

Commit

Permalink
WIP: Navigation Timing integration
Browse files Browse the repository at this point in the history
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 w3c/navigation-timing#136
Depends on whatwg/fetch#1185
  • Loading branch information
noamr committed Apr 7, 2021
1 parent f4bbe03 commit 8cf2e3e
Showing 1 changed file with 119 additions and 13 deletions.
132 changes: 119 additions & 13 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -9361,8 +9361,21 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
data-x="">loading</code>" if the document is associated with an <span>HTML parser</span>, an
<span>XML parser</span>, or an XSLT processor, and to the string "<code data-x="">complete</code>"
otherwise. Various algorithms during page loading affect this value. When the value is set, the
user agent must <span data-x="concept-event-fire">fire an event</span> named <code
user agent must perform the following steps given <var>readinessValue</var>:
<ol>
<li><p>Let <var>now</var> be the <span>current high resolution time</span>.

<li><p>If <var>readinessValue</var> is "<code data-x="">complete</code>", then set the
<code>Document</code>'s <a for=Document>load timing info</a>'s
<a for="document load timing info">dom complete time</a> to <var>now</var>.

<li><p>Otherwise, if <var>readinessValue</var> is "<code data-x="">interactive</code>", then set
the <code>Document</code>'s <a for=Document>load timing info</a>'s
<a for="document load timing info">dom interactive time</a> to <var>now</var>.

<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
data-x="event-readystatechange">readystatechange</code> at the <code>Document</code> object.</p>
</ol>

<p>A <code>Document</code> is said to have an <dfn>active parser</dfn> if it is associated with an
<span>HTML parser</span> or an <span>XML parser</span> that has not yet been <span data-x="stop
Expand Down Expand Up @@ -84542,12 +84555,48 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface

<dt><dfn data-x="navigation-params-hh">history handling</dfn></dt>
<dd>a <span>history handling behavior</span></dd>

<dt>dfn data-x="navigation-params-cross-origin-redirects">cross-origin redirects flag</dfn></td>
<dd>a flag, unset by default.
</dl>

<p class="note">Once a <span>navigation params</span> struct is created, this standard does not
mutate any of its <span data-x="struct item">items</span>. They are only passed onward to other
algorithms.</p>

<p>A <code>Document</code> has a <dfn for=/>document load timing info</a>
<a for=/>load timing info</a>.

<p>The <dfn>document load timing info</dfn> <span>struct</span> has the following
<span data-x="struct item">items</span>:</p>
<dl>
<dt><dfn for="document load timing info">fetch timing</dfn>
<dd>A <a for=/>fetch timing info</a.

<dt><dfn for="document load timing info">previous document unload timing</dfn>
<dd>An <a for=/>unload timing info</a.

<dt><dfn for="document load timing info">dom interactive time</dfn> (default 0)
<dt><dfn for="document load timing info">dom content loaded event start time (default 0)
<dt><dfn for="document load timing info">dom content loaded event end time (default 0)
<dt><dfn for="document load timing info">dom complete time (default 0)
<dt><dfn for="document load timing info">load event start time (default 0)
<dt><dfn for="document load timing info">load event end time (default 0)
<dd>A <span>DOMHighResTimeStamp</span>.

<dt><dfn for="document load timing info">redirect count</dfn> (default zero)
<dd>A number.
</dl>


<p>The <dfn>unload timing info</dfn> <span>struct</span> has the following
<span data-x="struct item">items</span>:</p>
<dl>
<dt><dfn for="unload timing info">unload event start time</dfn> (default zero)
<dt><dfn for="unload timing info">unload event end time</dfn> (default zero)
<dd>A <span>DOMHighResTimeStamp</span>.
</dl>

<p>After <code>Document</code> creation, the <span>session history</span> gets updated. A
<dfn>history handling behavior</dfn> is used to track the desired type of session history update
throughout the navigation process. It is one of the following:</p>
Expand Down Expand Up @@ -84929,12 +84978,19 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
<li><p>Let <var>currentURL</var> be <var>request</var>'s <span
data-x="concept-request-current-url">current URL</span>.</p></li>

<li><p>Let <var>hasCrossOriginRedirectsFlag</var> be an unset flag.

<li>
<p>While true:</p>

<ol>
<li><p>If <var>locationURL</var> is non-null, then set <var>currentURL</var> to
<var>locationURL</var>.</p></li>
<li><p>If <var>locationURL</var> is non-null, then perform the following steps:
<ol>
<li><p>If <var>locationURL</var> is not the <span data-x="same origin">same</span> as
<var>currentURL</var>, then set <var>hasCrossOriginRedirectsFlag</var>.

<li><p>Set <var>currentURL</var> to <var>locationURL</var>.</p></li>
</ol>

<li>
<p>If <var>request</var>'s <span data-x="concept-request-reserved-client">reserved
Expand Down Expand Up @@ -85127,8 +85183,9 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
data-x="navigation-params-reserved-environment">reserved environment</span> is
<var>request</var>'s <span data-x="concept-request-reserved-client">reserved client</span>, <span
data-x="navigation-params-browsing-context">browsing context</span> is
<var>browsingContext</var>, and <span data-x="navigation-params-hh">history handling</span> is
<var>historyHandling</var>.</p></li>
<var>browsingContext</var>, <span data-x="navigation-params-hh">history handling</span> is
<var>historyHandling</var>, and <span data-x="navigation-params-cross-origin-redirects">has
cross-origin redirects flag</span> is <var>hasCrossOriginRedirectsFlag</var>.</p></li>

<li><p>Run <span>process a navigate response</span> with <var>navigationType</var>,
<var>allowedToDownload</var>, <var>hasTransientActivation</var>, and
Expand Down Expand Up @@ -85612,6 +85669,15 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
</ol>
</li>

<li><p>Set <var>document</var>'s <a for=Document</code>load timing info</a> to a new
<a for=/>document load timing info</a>, with its
<a for="document load timing info">fetch timing</a> set to <var>navigationParams</var>'s <span
data-x="navigation-params-response">response</span>'s <a for=response>timing info</a>,
its <a for="document load timing info">redirect count</a> set to <var>navigationParams</var>'s
<span data-x="navigation-params-request">request</span>'s <a for=request>redirect count</a>, and
its <a for="document load timing info">previous document unload timing</a> set to a new
<a for=/>unload timing info</a>.

<li>
<p>If <var>navigationParams</var>'s <span data-x="navigation-params-response">response</span>
has a `<code data-x="http-refresh">Refresh</code>` header, then:</p>
Expand Down Expand Up @@ -85688,10 +85754,14 @@ new PaymentRequest(&hellip;); // Allowed to use
data-x="navigation-params-browsing-context">browsing context</span>'s <span>session
history</span>.</p></li>

<li><p>Let <var>unloadTimingInfo</var> be to a new <a for=/>unload timing info</a>.

<li><p>Let <var>previousDocument</var> be <var>sessionHistory</var>'s <span>current
entry</span>'s <span data-x="she-document">document</span>.

<li>
<p><span data-x="unload a document">Unload</span> <var>sessionHistory</var>'s <span>current
entry</span>'s <span
data-x="she-document">document</span>.</p>
<p><span data-x="unload a document">Unload</span> <var>previousDocument</var> with
<var>unloadTimingInfo</var>.</p>

<p>If this instance of the <span data-x="navigate">navigation</span> algorithm is canceled while
this step is running the <span>unload a document</span> algorithm, then the <span>unload a
Expand All @@ -85701,6 +85771,14 @@ new PaymentRequest(&hellip;); // Allowed to use
execution occurring as part of unloading the document or its descendants.)</p>
</li>

<li><p>If <var>navigationParams</var>'s <a for="navigation params">has cross-origin
redirects</var> is not set, <var>previousDocument</var> is not null, and
<var>newDocument</var>'s <a for=Document>origin</a> is the same as
<var>previousDocument</var>'s <a for=Document>origin</a>, then set
<var>newDocument</var>'s <a for=Document>load timing info</a>'s
<a for="document load timing info">previous document unload timing</a> to
<var>unloadTimingInfo</var>.

<li>
<p>Switch on <var>navigationParams</var>'s <span data-x="navigation-params-hh">history
handling</span>:</p>
Expand Down Expand Up @@ -86805,7 +86883,8 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
</ol>

<p>To <dfn export data-x="unload a document" data-lt="unload a document">unload</dfn> a
<code>Document</code> <var>document</var>, optionally given a <var>recursiveFlag</var>:</p>
<code>Document</code> <var>document</var>, given an optional <var>recursiveFlag</var> and
an optional <a for=/>unload timing info</a> <var>unloadTimingInfo</var>:</p>

<ol>
<li><p>Increase the <span>event loop</span>'s <span>termination nesting level</span> by
Expand Down Expand Up @@ -86841,12 +86920,20 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
<ref spec=PAGEVIS></p>
</li>

<li><p>If <var>unloadTimingInfo</var> is given, set <var>unloadTimingInfo</var>'s
<a for="unload timing info">unload event start time</a> to the
<span>current high resolution time</span>.

<li><p><i>Unload event</i>: If <var>document</var>'s <i
data-x="concept-document-salvageable">salvageable</i> state is false, then <span
data-x="concept-event-fire">fire an event</span> named <code data-x="event-unload">unload</code>
at <var>document</var>'s <span>relevant global object</span>, with <var>legacy target override
flag</var> set.</p></li>

<li><p>If <var>unloadTimingInfo</var> is given, set <var>unloadTimingInfo</var>'s
<a for="unload timing info">unload event end time</a> to the
<span>current high resolution time</span>.

<li><p>Decrease the <span>event loop</span>'s <span>termination nesting level</span> by
one.</p></li>

Expand Down Expand Up @@ -111492,11 +111579,19 @@ document.body.appendChild(text);
<code>Document</code>'s <span>relevant global object</span> to run the following substeps:</p>

<ol>
<li><p>Set the <code>Document</code>'s <a for=Document>load timing info</a>'s
<a for="document load timing info">dom content loaded event start time</a> to the
<span>current high resolution time</span>.

<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
data-x="event-DOMContentLoaded">DOMContentLoaded</code> at the <code>Document</code>
object, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute initialized to
true.</p></li>

<li><p>Set the <code>Document</code>'s <a for=Document>load timing info</a>'s
<a for="document load timing info">dom content loaded event end time</a> to the
<span>current high resolution time</span>.

<li><p>Enable the <span data-x="dfn-client-message-queue">client message queue</span> of the
<code>ServiceWorkerContainer</code> object whose associated <span
data-x="serviceworkercontainer-service-worker-client">service worker client</span> is the
Expand All @@ -111523,10 +111618,21 @@ document.body.appendChild(text);
this also fires an event immediately during the task -->.</p></li>

<li><p><i>Load event</i>: If the <code>Document</code> object's <span
data-x="concept-document-bc">browsing context</span> is non-null, then <span
data-x="concept-event-fire">fire an event</span> named <code data-x="event-load">load</code> at
the <code>Document</code> object's <span>relevant global object</span>, with <var>legacy target
override flag</var> set.</p></li>
data-x="concept-document-bc">browsing context</span> is non-null, then perform the following
steps:
<ol>
<li><p>Set the <code>Document</code>'s <a for=Document>load timing info</a>'s
<a for="document load timing info">load event start time</a> to the
<span>current high resolution time</span>.

<li><p><span data-x="concept-event-fire">Fire an event</span> named
<code data-x="event-load">load</code> at the <code>Document</code> object's
<span>relevant global object</span>, with <var>legacy target override flag</var> set.</p></li>

<li><p>Set the <code>Document</code>'s <a for=Document>load timing info</a>'s
<a for="document load timing info">load event end time</a> to the
<span>current high resolution time</span>.
</ol>
</ol>
</li>

Expand Down

0 comments on commit 8cf2e3e

Please sign in to comment.