GeezerVison is showing w3c.github.io — Navigation Timing Level 2
1. Introduction
This section is non-normative.
Accurately measuring performance characteristics of web applications is
an important aspect of making web applications faster. While
JavaScript-based mechanisms, such as the one described in
[JSMEASURE], can provide comprehensive instrumentation for user
latency measurements within an application, in many cases, they are
unable to provide a complete or detailed end-to-end latency picture.
For example, the following JavaScript shows a naive attempt to measure
the time it takes to fully load a page:
<html><head><scripttype="text/javascript">var start =new Date().getTime();function onLoad(){var now =new Date().getTime();var latency = now - start;
alert("page loading time: "+ latency);}</script></head><bodyonload="onLoad()"><!- Main page body goes from here. --></body></html>
The above script calculates the time it takes to load the page
after the first bit of JavaScript in the head is executed, but
it does not give any information about the time it takes to get the
page from the server, or the initialization lifecycle of the page.
For example, if we know that the response end occurs 100ms after the
start of navigation, the PerformanceNavigationTiming data could
look like so:
startTime: 0.000 // start time of the navigation request
responseEnd: 100.000 // high resolution time of last received byte
The following script shows how a developer can use the
PerformanceNavigationTiming interface to obtain accurate timing
data related to the navigation of the document:
<script>function showNavigationDetails(){// Get the first entryconst[entry]= performance.getEntriesByType("navigation");// Show it in a nice table in the developer console
console.table(entry.toJSON());}</script><bodyonload="showNavigationDetails()">
2. Terminology
The construction "a Foo object", where Foo is
actually an interface, is sometimes used instead of the more accurate
"an object implementing the interface Foo".
Throughout this work, all time values are measured in milliseconds
since the start of navigation of the document. For example, the start
of navigation of the document occurs at time 0. The term current
time refers to the number of milliseconds since the start of
navigation of the document until the current moment in time. This
definition of time is based on [HR-TIME] specification.
Though `redirectStart` and `redirectEnd` are exposed in PerformanceResourceTiming, they
have a different meaning in Navigation Timing, where they return zero for navigations with
cross-origin redirects.
The workerStart getter steps are to perform the following steps:
Though `workerStart` is exposed in PerformanceResourceTiming, it
has a different meaning in Navigation Timing, as unlike subresources, a navigation may
trigger the activation or running of a service worker.
In the context of Navigation Timing, `workerStart` returns the timestamp measured
just before the worker has been activated or started. See [service-workers] for
a precise definition.
The fetchStart getter steps are to perform the following steps:
When a service worker is used as part of the navigation, The `fetchStart` overload
holds a different meaning than the meaning in
PerformanceResourceTiming.
It returns the timestamp measured right before the FetchEvent is dispatched for
the service worker. The time difference between `workerStart` and `fetchStart` in
the document’s navigation timing entry can be used to determine roughly how long it
took for the worker to be initialized or activated. See [service-workers] for
a precise definition.
If the previous document and the current document have the same
origin, this timestamp is measured immediately
before the user agent starts the unload
event
of the previous document. If there is no previous document or the
previous document has a different origin than the current document, this attribute will return
zero.
If the previous document and the current document have the same
origin, this timestamp is measured immediately
after the user agent handles the unload
event
of the previous document. If there is no previous document or the
previous document has a different origin than the current document, this attribute will return
zero.
This timestamp is measured after the user agent completes handling the
load event for the document.
The type getter steps are to run the this’s navigation type.
Client-side redirects, such as those using the Refresh pragma
directive, are not considered HTTP redirects by this spec. In those
cases, the type
attribute SHOULD return appropriate value, such as
reload if reloading the
current page, or navigate if
navigating to a new URL.
The redirectCount getter steps are to return this’s
redirect count.
The criticalCHRestart getter steps are to return this’s
`Critical-CH` restart time.
If criticalCHRestart is not 0 it will be before all other timestamps except for
navigationStart, unloadEventStart, and unloadEventEnd. This is because it marks
the moment the redirection part of the navigation was restarted.
The notRestoredReasons getter steps are to return this’s
not restored reasons.
The confidence getter steps are to run these steps:
These values should be set once, and not change for the lifetime of this.
This section is intended to help RUM providers and developers interpret
confidence. Since the randomized trigger rate can vary across records,
per-record weighting is needed to recover unbiased aggregates. The procedure
below illustrates how weighting based on value
can be applied before computing summary statistics.
The user agent considers the navigation metrics to be
representative on the current user’s device.
low
The navigation metrics may not be representative of the current
user’s device. The user agent may consider the state of the
machine, or user configuration.
When determining the underlying confidence value, user agents
MUST only base their decision on transient runtime
conditions, such as user agent startup, temporarily high CPU
usage, temporary memory pressure, or other short-lived
considerations.
User agents MUST NOT base the underlying confidence value on
permanent device or profile characteristics. Examples of prohibited
factors include the amount of physical RAM on the device, the
number of CPU cores, the number of installed extensions, or other
static environment settings.
Confidence is intended to reflect runtime variability rather than
system capabilities.
4. Process
4.1. Processing Model
This figure illustrates the timing attributes defined by the
PerformanceNavigationTiming interface. Attributes in
parenthesis indicate that they may not be available for navigations
involving documents from different origins.
5. Creating a navigation timing entry
Each document has an associated navigation timing entry, initially unset.
There is the potential for disclosing an end-user’s browsing and
activity history by using carefully crafted timing attacks. For
instance, the unloading time reveals how long the previous page takes
to execute its unload handler, which could be used to infer the
user’s login status. These attacks have been mitigated by enforcing
the same origin check algorithm when unloading a document, as detailed in
the HTML spec.
The relaxed same
origin policy doesn’t provide sufficient protection against
unauthorized visits across documents. In shared hosting, an untrusted
third party is able to host an HTTP server at the same IP address but
on a different port.
6.2. Cross-directory access
Different pages sharing one host name, for example contents from
different authors hosted on sites with user generated content are
considered from the same origin because there is no feature to
restrict the access by pathname. Navigating between these pages
allows a latter page to access timing information of the previous
one, such as timing regarding redirection and unload event.
In case a proxy is deployed between the user agent and the web
server, the time interval between the
connectStart
and the
connectEnd
attributes indicates the delay between the user agent and the proxy
instead of the web server. With that, web server can potentially
infer the existence of the proxy. For SOCKS proxy, this time interval
includes the proxy authentication time and time the proxy takes to
connect to the web server, which obfuscate the proxy detection. In
case of an HTTP proxy, the user agent might not have any knowledge
about the proxy server at all so it’s not always feasible to mitigate
this attack.
All time values defined in this section are measured in milliseconds
since midnight of .
navigationStart
This attribute must return the time immediately after the user
agent finishes prompting
to unload the previous document. If there is no previous
document, this attribute must return the time the current
document is created.
If the previous document and the current document have the same
origin, this attribute
must return the time immediately before the user agent starts the
unload event
of the previous document. If there is no previous document or the
previous document has a different origin than the current document, this
attribute must return zero.
unloadEventEnd
If the previous document and the current document have the same
same origin, this attribute
must return the time immediately after the user agent finishes
the unload event
of the previous document. If there is no previous document or the
previous document has a different origin than the current document or the
unload is not yet completed, this attribute must return zero.
If there are HTTP
redirects when navigating and if all the redirects are from
the same origin, this
attribute must return the starting time of the fetch
that initiates the redirect. Otherwise, this attribute must
return zero.
redirectEnd
If there are HTTP
redirects when navigating and all redirects are from the same
origin, this attribute
must return the time immediately after receiving the last byte of
the response of the last redirect. Otherwise, this attribute must
return zero.
fetchStart
If the new resource is to be fetched
using a "GET" request
method, fetchStart must return the time immediately before
the user agent starts checking the
HTTP cache[RFC9111]. Otherwise, it must
return the time when
the user agent starts fetching the
resource.
domainLookupStart
This attribute must return the time immediately before the user
agent starts the domain name lookup for the current document. If
a persistent connection[RFC9112] is used or the current document is retrieved from the
HTTP cache[RFC9111] or local resources,
this attribute must return the same value as
fetchStart.
domainLookupEnd
This attribute must return the time immediately after the user
agent finishes the domain name lookup for the current document.
If a persistent connection[RFC9112] is used or the current document is retrieved from the
HTTP cache[RFC9111] or local resources,
this attribute must return the same value as
fetchStart.
In case where the user agent already has the domain information
in cache, domainLookupStart and domainLookupEnd represent the
times when the user agent starts and ends the domain data
retrieval from the cache.
connectStart
This attribute must return the time immediately before the user
agent start establishing the connection to the server to retrieve
the document. If a persistent
connection[RFC9112] is used or the current document is
retrieved from the HTTP cache[RFC9111] or
local resources, this attribute must return value of
domainLookupEnd.
connectEnd
This attribute must return the time immediately after the user
agent finishes establishing the connection to the server to
retrieve the current document. If a
persistent connection[RFC9112] is used or the current document is retrieved from the
HTTP cache[RFC9111] or local resources,
this attribute must return the value of
domainLookupEnd.
If the transport connection fails and the user agent reopens a
connection, connectStart and
connectEnd should return the corresponding
values of the new connection.
connectEnd must include the time interval
to establish the transport connection as well as other time
interval such as SSL handshake and SOCKS authentication.
secureConnectionStart
This attribute is optional. User agents that don’t have this
attribute available must set it as undefined. When this attribute
is available, if the scheme[URL] of the current page
is "https", this attribute must return the time immediately
before the user agent starts the handshake process to secure the
current connection. If this attribute is available but HTTPS is
not used, this attribute must return zero.
requestStart
This attribute must return the time immediately before the user
agent starts requesting the current document from the server, or
HTTP cache[RFC9111] or from local
resources.
If the transport connection fails after a request is sent and the
user agent reopens a connection and resend the request,
requestStart should return the
corresponding values of the new request.
This interface does not include an attribute to represent the
completion of sending the request, e.g., requestEnd.
Completion of sending the request from the user agent does
not always indicate the corresponding completion time in the
network transport, which brings most of the benefit of having
such an attribute.
Some user agents have high cost to determine the actual
completion time of sending the request due to the HTTP layer
encapsulation.
responseStart
This attribute must return the time immediately after the user
agent receives the first byte of the response from the server, or
HTTP cache[RFC9111] or from local
resources.
responseEnd
This attribute must return the time immediately after the user
agent receives the last byte of the current document or
immediately before the transport connection is closed, whichever
comes first. The document here can be received either from the
server, the HTTP cache[RFC9111] or from
local resources.
Due to differences in when a Document object is created in
existing user agents, the value returned by the
domLoading is implementation specific and should not
be used in meaningful metrics.
This attribute must return the time immediately before the load
event of the current document is fired. It must return zero when
the load event is not fired yet.
loadEventEnd
This attribute must return the time when the load event of the
current document is completed. It must return zero when the load
event is not fired or is not completed.
This attribute must return the type of the last non-redirect
navigation.
It must have one of the following navigation type values.
Client-side redirects, such as those using the Refresh
pragma directive, are not considered HTTP redirects by this spec. In those
cases, the type
attribute should return appropriate value, such as
TYPE_RELOAD if reloading the current page, or
TYPE_NAVIGATE if navigating to a new URL.
redirectCount
This attribute must return the number of redirects since the last
non-redirect navigation. If there is no redirect or there is any
redirect that is not from the
same origin as the
destination document, this attribute must return zero.
The timing attribute represents the timing
information since the last non-redirect navigation.
This attribute is defined by the
PerformanceTiming interface.
navigation
The navigation attribute is defined by the
PerformanceNavigation interface.
9. Acknowledgments
Thanks to Anne Van Kesteren, Arvind Jain, Boris Zbarsky, Jason Weber,
Jonas Sicking, James Simonsen, Karen Anderson, Nic Jansma, Philippe Le
Hegaret, Steve Souders, Todd Reifsteck, Tony Gentilcore, William Chan
and Zhiheng Wang for their contributions to this work.
You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.