-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathindex.html
1274 lines (1261 loc) · 55.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="color-scheme" content="light dark">
<title>
Navigation Timing Level 2
</title>
<style>
#obsolete {
background-position: right;
background-repeat: repeat-y;
background-color: rgba(251, 233, 233, 0.5);
padding: 0 1em;
background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='300px' width='125px'><text x='0' y='100' fill='red' font-size='15' fill-opacity='0.20'>Obsolete<\/text><\/svg>")
}
</style>
<script src='https://www.w3.org/Tools/respec/respec-w3c' class='remove' defer></script>
<script class='remove'>
var respecConfig = {
shortName: "navigation-timing-2",
specStatus: "ED",
editors: [{
name: "Yoav Weiss",
url: "https://blog.yoav.ws/",
company: "Google",
companyURL: "https://google.com/",
w3cid: "58673"
}, {
name: "Noam Rosenthal",
mailto: "noam.j.rosenthal@gmail.com",
company: "Invited Expert",
w3cid: "121539"
}],
formerEditors: [
{
name: "Ilya Grigorik",
url: "https://www.igvita.com/",
company: "Google",
companyURL: "https://www.google.com/",
w3cid: "56102",
},
{
name: "Tobin Titus",
mailto: "tobint@microsoft.com",
retiredDate: "2015-01-01",
company: "Microsoft Corp.",
w3cid: "69474",
},
{
name: "Jatinder Mann",
mailto: "jmann@microsoft.com",
company: "Microsoft Corp.",
retiredDate: "2014-02-01",
w3cid: "44357",
},
{
name: "Arvind Jain",
mailto: "arvind@google.com",
company: "Google Inc.",
retiredDate: "2014-12-01",
w3cid: "45188",
},
],
group:"webperf",
wgPublicList: "public-web-perf",
subjectPrefix: "[NavigationTiming]",
github: "https://github.com/w3c/navigation-timing/",
testSuiteURI: "https://wpt.fyi/navigation-timing/",
caniuse: "nav-timing",
mdn: "navigation-timing",
xref: {
specs: [ "service-workers", "hr-time", "performance-timeline", "resource-timing", "html", "fetch"],
profile: "web-platform",
},
localBiblio: {
JSMEASURE: {
title: "Measuring Client-Perceived Response Times on the WWW",
href:
"http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.69.7329&rep=rep1&type=pdf",
authors: ["Ramakrishnan Rajamony", "Mootaz Elnozahy"],
status:
"The Proceedings of the 3rd USENIX Symposium on Internet Technologies and Systems (USITS)",
date: "March 2001",
}
},
lint: {
"check-punctuation": true,
},
doJsonLd: true,
};
</script>
</head>
<body>
<section id="abstract">
<p>
This specification defines an interface for web applications to access
the complete timing information for navigation of a document.
</p>
</section>
<section id="sotd">
<p>
Navigation Timing 2 replaces the first version of [[NAVIGATION-TIMING]]
and includes the following changes:
</p>
<ul>
<li>the definition of Performance interface was moved to
[[PERFORMANCE-TIMELINE-2]];
</li>
<li>builds on top of [[RESOURCE-TIMING-2]];
</li>
<li>support for [[PERFORMANCE-TIMELINE-2]];
</li>
<li>support for [[HR-TIME-2]];
</li>
<li>support for <a data-cite="resource-hints#prerender">prerender</a>
navigations [[RESOURCE-HINTS]];
</li>
<li>exposes <a data-lt=
'PerformanceNavigationTiming.redirectCount'>number of redirects</a>
since the last non-redirect navigation;
</li>
<li>exposes <a data-cite=
'resource-timing-2#dom-performanceresourcetiming-nexthopprotocol'>next
hop network protocol</a>;
</li>
<li>exposes <a data-cite=
'resource-timing-2#dom-performanceresourcetiming-transfersize'>transfer</a>,
<a data-cite=
'resource-timing-2#dom-performanceresourcetiming-encodedbodysize'>encoded
body</a> and <a data-cite=
'resource-timing-2#dom-performanceresourcetiming-decodedbodysize'>decoded
body</a> size information;
</li>
<li>
<a data-cite=
'resource-timing-2#dom-performanceresourcetiming-secureconnectionstart'>
secureConnectionStart</a> attribute is now mandatory.
</li>
</ul>
</section>
<section id="introduction" class='informative'>
<h2>
Introduction
</h2>
<p>
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:
</p>
<pre class='example'>
<html>
<head>
<script type="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>
<body onload="onLoad()">
<!- Main page body goes from here. -->
</body>
</html>
</pre>
<p>
The above script calculates the time it takes to load the page
<b>after</b> 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.
</p>
<p>
This specification defines the {{PerformanceNavigationTiming}}
interface which participates in the [[PERFORMANCE-TIMELINE-2]] to store
and retrieve high resolution performance metric data related to the
navigation of a document. As the {{PerformanceNavigationTiming}}
interface uses [[HR-TIME]], all time values are measured with respect
to the [=environment settings object/time origin=] of the entry's
[=relevant settings object=].
</p>
<p>
For example, if we know that the response end occurs 100ms after the
start of navigation, the {{PerformanceNavigationTiming}} data could
look like so:
</p>
<pre class="example">
startTime: 0.000 // start time of the navigation request
responseEnd: 100.000 // high resolution time of last received byte
</pre>
<p>
The following script shows how a developer can use the
{{PerformanceNavigationTiming}} interface to obtain accurate timing
data related to the navigation of the document:
</p>
<pre class="example">
<script>
function showNavigationDetails() {
// Get the first entry
const [entry] = performance.getEntriesByType("navigation");
// Show it in a nice table in the developer console
console.table(entry.toJSON());
}
</script>
<body onload="showNavigationDetails()">
</pre>
</section>
<section id="terminology">
<h2>
Terminology
</h2>
<p>
The construction "a <code>Foo</code> object", where <code>Foo</code> is
actually an interface, is sometimes used instead of the more accurate
"an object implementing the interface <code>Foo</code>.
</p>
<p>
The term <dfn>current document</dfn> refers to the document associated
with the <a data-lt="associated document">Window object's newest
Document object</a>.
</p>
<p>
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 <i>current
time</i> 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.
</p>
</section>
<section id="sec-navigation-timing">
<h2>
Navigation Timing
</h2>
<section id='performanceentry'>
<h3>
Relation to the {{PerformanceEntry}} interface
</h3>
<p>
{{PerformanceNavigationTiming}} interface extends the following
attributes of {{PerformanceEntry}} interface:
</p>
<ul>
<li>The <code>entryType</code>
getter step is to return the {{DOMString}} "<code id="perf-navigation">navigation</code>".
</li>
<li>The {{PerformanceEntry/startTime}}
getter step is to return a {{DOMHighResTimeStamp}}</code>
with a time value of 0.
</li>
<li>The {{PerformanceEntry/duration}}
getter step is to return a {{DOMHighResTimeStamp}} equal to the
difference between {{PerformanceNavigationTiming/loadEventEnd}} and [=this=]'s {{PerformanceEntry/startTime}}.
</li>
</ul>
<p class="note">
A user agent implementing {{PerformanceNavigationTiming}} would need
to include <code>"navigation"</code> in <a data-cite=
"PERFORMANCE-TIMELINE-2#supportedentrytypes-attribute">supportedEntryTypes</a>
for <a data-cite="HTML/window-object.html#window">Window</a>
contexts. This allows developers to detect support for Navigation
Timing.
</p>
</section>
<section id='PerformanceResourceTiming'>
<h3>
Relation to the <code>PerformanceResourceTiming</code> interface
</h3>
<p>
{{PerformanceNavigationTiming}} interface extends the following
attributes of the <code><dfn data-cite=
"RESOURCE-TIMING-2#dom-performanceresourcetiming">PerformanceResourceTiming</dfn></code>
interface:
</p>
<ul>
<li>The {{PerformanceResourceTiming/redirectStart}} getter steps are to perform the following steps:
<ol>
<li>If |this|'s [=PerformanceNavigationTiming/redirect count] is 0, return 0.
<li>Otherwise return |this|'s {{PerformanceResourceTiming/redirectStart}}.
</ol>
</li>
<li>The {{PerformanceResourceTiming/redirectEnd}} getter steps are to perform the following steps:
<ol>
<li>If |this|'s [=PerformanceNavigationTiming/redirect count] is 0, return 0.
<li>Otherwise return |this|'s {{PerformanceResourceTiming/redirectEnd}}.
</ol>
<p class="note">
Though `redirectStart` and `redirectEnd` are exposed in <a data-cite=
"RESOURCE-TIMING-2#dom-performanceresourcetiming">PerformanceResourceTiming</a>, they
have a different meaning in Navigation Timing, where they return zero for navigations with
cross-origin redirects.
</p>
</li>
<li>The {{PerformanceResourceTiming/workerStart}} getter steps are to perform the following steps:
<ol>
<li>Let |workerTiming| be |this|'s [=PerformanceNavigationTiming/service worker timing=].
<li>If |workerTiming| is null, then return |this|'s prototype's `workerStart`.
<li>Return |workerTiming|'s [=service worker timing info/start time=].
</ol>
<p class="note">
Though `workerStart` is exposed in <a data-cite=
"RESOURCE-TIMING-2#dom-performanceresourcetiming">PerformanceResourceTiming</a>, 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.
</p>
</li>
<li>The {{PerformanceResourceTiming/fetchStart}} getter steps are to perform the following steps:
<ol>
<li>Let |workerTiming| be |this|'s [=PerformanceNavigationTiming/service worker timing=].
<li>If |workerTiming| is null, then return |this|'s prototype's `fetchStart`.
<li>Return |workerTiming|'s [=service worker timing info/fetch event dispatch time=].
</ol>
<p class="note">
When a [=service worker=] is used as part of the navigation, The `fetchStart` overload
holds a different meaning than the meaning in
<a data-cite="resource-timing-2#dom-performanceresourcetiming-requeststart">
<code>PerformanceResourceTiming</code></a>.
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.
</p>
</li>
</ul>
<p class="note">
Only the <a>current document</a> resource is included in the
performance timeline; there is only one
{{PerformanceNavigationTiming}} object in the performance timeline.
</p>
</section>
<section data-dfn-for="PerformanceNavigationTiming" id=
"sec-PerformanceNavigationTiming">
<h3>
The <dfn>PerformanceNavigationTiming</dfn> interface
</h3><!-- from domainLookupEnd -->
<div class="note">
<p>
Checking and retrieving contents from the <a href=
"https://tools.ietf.org/html/RFC7234">HTTP cache</a> [[RFC7234]] is
part of the <a data-cite="FETCH#concept-fetch" title=
'fetch'>fetching process</a>. It's covered by the <a data-cite=
"resource-timing-2#dom-performanceresourcetiming-requeststart"><code>
requestStart</code></a>, <a data-cite=
"resource-timing-2#dom-performanceresourcetiming-responsestart"><code>
responseStart</code></a> and <a data-cite=
"resource-timing-2#dom-performanceresourcetiming-responseend"><code>
responseEnd</code></a> attributes.
</p>
</div>
<pre class='idl'>
[Exposed=Window]
interface PerformanceNavigationTiming : PerformanceResourceTiming {
readonly attribute DOMHighResTimeStamp unloadEventStart;
readonly attribute DOMHighResTimeStamp unloadEventEnd;
readonly attribute DOMHighResTimeStamp domInteractive;
readonly attribute DOMHighResTimeStamp domContentLoadedEventStart;
readonly attribute DOMHighResTimeStamp domContentLoadedEventEnd;
readonly attribute DOMHighResTimeStamp domComplete;
readonly attribute DOMHighResTimeStamp loadEventStart;
readonly attribute DOMHighResTimeStamp loadEventEnd;
readonly attribute NavigationTimingType type;
readonly attribute unsigned short redirectCount;
readonly attribute DOMHighResTimeStamp criticalCHRestart;
readonly attribute NotRestoredReasons? notRestoredReasons;
[Default] object toJSON();
};
</pre>
<p>A <a>PerformanceNavigationTiming</a> has an associated
[=document load timing info=] <a data-dfn-for="PerformanceResourceTiming">
<dfn>document load timing</dfn></a>.
<p>A <a>PerformanceNavigationTiming</a> has an associated
[=document unload timing info=] <a data-dfn-for="PerformanceNavigationTiming">
<dfn>previous document unload timing</dfn></a>.
<p>A <a>PerformanceNavigationTiming</a> has an associated
number <a data-dfn-for="PerformanceNavigationTiming"><dfn>redirect count</dfn></a>.
<p>A <a>PerformanceNavigationTiming</a> has an associated
{{NavigationTimingType}} <a data-dfn-for="PerformanceNavigationTiming"><dfn>navigation type</dfn></a>.
<p>A <a>PerformanceNavigationTiming</a> has an associated
{{DOMHighResTimeStamp}} <a data-dfn-for="PerformanceNavigationTiming"><dfn>`Critical-CH` restart time</dfn></a>.
<p>A <a>PerformanceNavigationTiming</a> has an associated
{{NotRestoredReasons}} <a data-dfn-for="PerformanceNavigationTiming"><dfn>not restored reasons</dfn></a>.
<p>A {{PerformanceNavigationTiming}} has an associated null or [=service worker timing info=]
<dfn data-dfn-for="PerformanceNavigationTiming">service worker timing</dfn>.
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>unloadEventStart</dfn> getter steps are to return |this|'s
[=previous document unload timing=]'s [=document unload timing info/unload event start
time=].
<p class="note">If the previous document and the current document have the same
<a data-cite="html#concept-origin">origin</a>, this timestamp is measured immediately
before the user agent starts the <a data-cite=
"HTML/browsing-the-web.html#unloading-documents">unload</a> event
of the previous document. If there is no previous document or the
previous document has a different <a data-cite=
"html#concept-origin">origin</a> than the current document, this attribute will return
zero.
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>unloadEventEnd</dfn> getter steps are to return |this|'s
[=previous document unload timing=]'s
[=document unload timing info/unload event end time=].
<p class="note">If the previous document and the current document have the same
<a data-cite="html#concept-origin">origin</a>, this timestamp is measured immediately
after the user agent handles the <a data-cite=
"HTML/browsing-the-web.html#unloading-documents">unload</a> event
of the previous document. If there is no previous document or the
previous document has a different <a data-cite=
"html#concept-origin">origin</a> than the current document, this attribute will return
zero.
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>domInteractive</dfn> getter steps are to return
|this|'s [=document load timing=]'s [=document load timing info/DOM interactive time=].</p>
<p class="note">This timestamp is measured before the user agent sets the
<a data-cite="HTML/dom.html#current-document-readiness">current document readiness</a> to
<a data-cite="HTML/parsing.html#the-end">"interactive"</a>.
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>domContentLoadedEventStart</dfn> getter steps are to return |this|'s
[=document load timing=]'s
[=document load timing info/DOM content loaded event start time=].</p>
</p>
<p class="note">This timestamp is measured before the user agent dispatches the
<a data-cite="HTML/parsing.html#the-end:event-domcontentloaded">DOMContentLoaded</a>
event.
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>domContentLoadedEventEnd</dfn> getter steps are to return
|this|'s [=document load timing=]'s
[=document load timing info/DOM content loaded event end time=].</p>
<p class="note">This timestamp is measured after the user agent completes handling of the
<a data-cite="HTML/parsing.html#the-end:event-domcontentloaded">DOMContentLoaded</a>
event.
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>domComplete</dfn> getter steps are to return
|this|'s [=document load timing=]'s [=document load timing info/DOM complete time=].
<p class="note">This timestamp is measured before the user agent sets the
<a data-cite="HTML/dom.html#current-document-readiness">current document readiness</a> to
<a data-cite="HTML/parsing.html#the-end">"complete"</a>. See <a data-cite=
"HTML/dom.html#current-document-readiness">document readiness</a> for a precise
definition.
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>loadEventStart</dfn> getter steps are to return
|this|'s [=document load timing=]'s [=document load timing info/load event start time=].</p>
</p>
<p class="note">This timestamp is measured before the user agent dispatches the
[=Window/load=] event for the document.
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>loadEventEnd</dfn> getter steps are to return
|this|'s [=document load timing=]'s [=document load timing info/load event end time=].</p>
</p>
<p class="note">This timestamp is measured after the user agent completes handling the
[=Window/load=] event for the document.
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>type</dfn> getter steps are to run the |this|'s [=navigation type=].
</p>
<div class="note">
<p>
Client-side redirects, such as those using the <a data-cite=
"HTML/semantics.html#attr-meta-http-equiv-refresh">Refresh pragma
directive</a>, are not considered <a data-cite=
"FETCH#redirect-status">HTTP redirects</a> by this spec. In those
cases, the <a data-link-for="PerformanceNavigationTiming">type</a>
attribute SHOULD return appropriate value, such as
<a data-link-for="NavigationTimingType">reload</a> if reloading the
current page, or <a data-link-for="NavigationTimingType">navigate</a> if
navigating to a new URL.
</p>
</div>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>redirectCount</dfn> getter steps are to return |this|'s
<span>redirect count</span>.</p>
</p>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>criticalCHRestart</dfn> getter steps are to return |this|'s
<span>`Critical-CH` restart time</span>.</p>
</p>
<div class="note">
<p>
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.
</p>
</div>
<p data-dfn-for='PerformanceNavigationTiming'>
The <dfn>notRestoredReasons</dfn> getter steps are to return |this|'s
<span>not restored reasons</span>.</p>
<p>
The <dfn>toJSON()</dfn> method runs the [=default toJSON steps=] for [=this=].
</p>
<section id="sec-performance-navigation-types">
<h4>
<dfn>NavigationTimingType</dfn> enum
</h4>
<pre class='idl'>
enum NavigationTimingType {
"navigate",
"reload",
"back_forward",
"prerender"
};
</pre>
<p>
The values are defined as follows:
</p>
<dl data-dfn-for='NavigationTimingType'>
<dt>
<dfn>navigate</dfn>
</dt>
<dd>
Navigation where the
<a data-cite="HTML/browsing-the-web.html#history-handling-behavior">history handling behavior</a>
is set to
<a data-cite="HTML/browsing-the-web.html#hh-default">"default"</a>
or <a data-cite="HTML/browsing-the-web.html#hh-replace">"replace"</a>
and the navigation was not initiated by a <a data-cite=
'resource-hints#prerender'>prerender</a> hint [[RESOURCE-HINTS]].
</dd>
<dt>
<dfn>reload</dfn>
</dt>
<dd>
Navigation where the [=navigable=] was <a
data-cite="HTML/browsing-the-web.html#reload">reloaded</a>.
</dd>
<dt>
<dfn>back_forward</dfn>
</dt>
<dd>
Navigation that's <a
data-cite="HTML/browsing-the-web.html#apply-the-history-step">applied from history</a>.
</dd>
<dt>
<dfn>prerender</dfn>
</dt>
<dd>
Navigation initiated by a <a data-cite=
'resource-hints#prerender'>prerender</a> hint [[RESOURCE-HINTS]].
</dd>
</dl>
<p class="note">
The format of the above enumeration value is inconsistent with the
[=enumeration|WebIDL recommendation for
formatting of enumeration values=]. Unfortunately, we are unable
to change it due to backwards compatibility issues with shipped
implementations. [[WebIDL]]
</p>
</section>
</section>
</section>
<section id="process">
<h2>
Process
</h2>
<section id="processing-model">
<h3>
Processing Model
</h3>
<figure title='Timing attributes'>
<figcaption>
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 <a data-cite=
"html#concept-origin" title='origin'>origins</a>.
</figcaption>
<!-- Source: https://docs.google.com/document/d/1I7XGNJ57Qgjkg9pL11s7MK7zGEcwAgdNj1W5f7NKbW8/ -->
<img src="timestamp-diagram.svg" alt="Navigation Timing attributes"
style='width: 100%'>
</figure>
</section>
</section>
<section id="marking-navigation-timing">
<h2>Creating a navigation timing entry</h2>
<p data-dfn-for="Document">Each [=document=] has an associated <dfn>navigation timing entry</dfn>, initially unset.
<p>To <dfn data-export="">create the navigation timing entry</dfn> for {{Document}} |document|,
given a [=fetch timing info=] |fetchTiming|, a number |redirectCount|, a
{{NavigationTimingType}} |navigationType|, a null or [=service worker timing info=] |serviceWorkerTiming|,
a DOMString |cacheMode|, a {{DOMHighResTimeStamp}} |criticalCHRestart|, and a [=response body info=] |bodyInfo|, do the following:
<ol>
<li>Let |global| be |document|'s [=relevant global object=].</li>
<li>Let |navigationTimingEntry| be a new {{PerformanceNavigationTiming}} object in |global|'s
[=global object/realm=].
<li><a data-cite="RESOURCE-TIMING-2#dfn-setup-the-resource-timing-entry">Setup the resource
timing entry</a> for |navigationTimingEntry| given "<code>navigation</code>", |document|'s
{{Document/URL}}, |fetchTiming|, |cacheMode|, and |bodyInfo|.
<li>Set |navigationTimingEntry|'s <a data-for="PerformanceNavigationTiming">document load
timing</a> to |document|'s [=Document/load timing info=]
<li>Set |navigationTimingEntry|'s <a data-for="PerformanceNavigationTiming">previous
document unload timing</a> to |document|'s [=Document/previous document unload timing=].
<li>Set |navigationTimingEntry|'s <a data-for="PerformanceNavigationTiming">redirect
count</a> to |redirectCount|.
<li>Set |navigationTimingEntry|'s <a data-for="PerformanceNavigationTiming">navigation
type</a> to |navigationType|.
<li>Set |navigationTimingEntry|'s [=PerformanceNavigationTiming/service worker timing=]
to |serviceWorkerTiming|.
<li>Set |document|'s <span>navigation timing entry</span> to |navigationTimingEntry|.
<li>Set |navigationTimingEntry|'s <a data-for="PerformanceNavigationTiming">`Critical-CH` restart time</a>
to |criticalCHRestart|.
<li> Set |navigationTimingEntry|'s [=PerformanceNavigationTiming/not restored reasons=]
to the result of <a data-lt="create a notrestoredreasons object">creating a
NotRestoredReasons object</a> given |document|'s [=Document/not restored reasons=].</li>
<li>add |navigationTimingEntry| to |global|'s
<a data-cite='performance-timeline-2#dfn-performance-entry-buffer'>performance entry buffer</a>.
</ol>
<p>To <dfn data-export="">queue the navigation timing entry</dfn> for {{Document}} |document|,
<a data-lt="queue a navigation performanceentry">queue</a> |document|'s
[=navigation timing entry=].
</section>
<section id="privacy" class='informative'>
<h2>
Privacy Considerations
</h2>
<section id="info_disclosure">
<h3>
Information disclosure
</h3>
<p>
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
<a data-cite="HTML#update-the-session-history-with-the-new-page">the HTML spec</a>.
</p>
<p>
The <a data-cite=
"HTML/origin.html#relaxing-the-same-origin-restriction">relaxed same
origin policy</a> 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.
</p>
</section>
<section id="cross-directory">
<h3>
Cross-directory access
</h3>
<p>
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.
</p>
</section>
</section>
<section id="security" class='informative'>
<h2>
Security Considerations
</h2>
<p>
The {{PerformanceNavigationTiming}} interface exposes timing
information about the previous document to the <a>current document</a>.
To limit the access to {{PerformanceNavigationTiming}} attributes which
include information on the previous document, the
<a data-cite="HTML#update-the-session-history-with-the-new-page">previous document
unloading</a> algorithm enforces the <a data-cite="html#same-origin">same origin policy</a>
and attributes related to the previous document are set to zero.
</p>
<section id="authentication">
<h3>
Detecting proxy servers
</h3>
<p>
In case a proxy is deployed between the user agent and the web
server, the time interval between the <a data-cite=
"resource-timing-2#dom-performanceresourcetiming-connectstart"><code>connectStart</code></a>
and the <a data-cite=
"resource-timing-2#dom-performanceresourcetiming-connectend"><code>connectEnd</code></a>
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.
</p>
</section>
</section>
<section id='obsolete'>
<h2>
Obsolete
</h2>
<p>
This section defines attributes and interfaces previously introduced in
[[NAVIGATION-TIMING]] Level 1 and are kept here for backwards
compatibility. Authors should not use the following interfaces and are
<strong>strongly advised</strong> to use the new
{{PerformanceNavigationTiming}} interface—see <a href="#sotd">summary
of changes and improvements</a>.
</p>
<section data-dfn-for="PerformanceTiming">
<h3>
The <dfn>PerformanceTiming</dfn> interface
</h3>
<pre class="idl">
[Exposed=Window]
interface PerformanceTiming {
readonly attribute unsigned long long navigationStart;
readonly attribute unsigned long long unloadEventStart;
readonly attribute unsigned long long unloadEventEnd;
readonly attribute unsigned long long redirectStart;
readonly attribute unsigned long long redirectEnd;
readonly attribute unsigned long long fetchStart;
readonly attribute unsigned long long domainLookupStart;
readonly attribute unsigned long long domainLookupEnd;
readonly attribute unsigned long long connectStart;
readonly attribute unsigned long long connectEnd;
readonly attribute unsigned long long secureConnectionStart;
readonly attribute unsigned long long requestStart;
readonly attribute unsigned long long responseStart;
readonly attribute unsigned long long responseEnd;
readonly attribute unsigned long long domLoading;
readonly attribute unsigned long long domInteractive;
readonly attribute unsigned long long domContentLoadedEventStart;
readonly attribute unsigned long long domContentLoadedEventEnd;
readonly attribute unsigned long long domComplete;
readonly attribute unsigned long long loadEventStart;
readonly attribute unsigned long long loadEventEnd;
[Default] object toJSON();
};
</pre>
<p class="note">
All time values defined in this section are measured in milliseconds
since midnight of <time datetime="1970-01-01T00:00Z">January 1, 1970
(UTC)</time>.
</p>
<dl>
<dt>
<dfn>navigationStart</dfn>
</dt>
<dd>
<p>
This attribute must return the time immediately after the user
agent finishes <a data-cite=
"HTML/browsing-the-web.html#prompt-to-unload-a-document">prompting
to unload</a> the previous document. If there is no previous
document, this attribute must return the time the current
document is created.
</p>
<p class="note">
This attribute is not defined for
{{PerformanceNavigationTiming}}. Instead, authors can use
{{Performance/timeOrigin}} to obtain an equivalent timestamp.
</p>
</dd>
<dt>
<dfn>unloadEventStart</dfn>
</dt>
<dd>
<p>
If the previous document and the current document have the same
<a data-cite="html#concept-origin">origin</a>, this attribute
must return the time immediately before the user agent starts the
<a data-cite=
"HTML/browsing-the-web.html#unloading-documents">unload</a> event
of the previous document. If there is no previous document or the
previous document has a different <a data-cite=
"html#concept-origin">origin</a> than the current document, this
attribute must return zero.
</p>
</dd>
<dt>
<dfn>unloadEventEnd</dfn>
</dt>
<dd>
<p>
If the previous document and the current document have the same
<a data-cite="html#same-origin">same origin</a>, this attribute
must return the time immediately after the user agent finishes
the <a data-cite=
"HTML/browsing-the-web.html#unload-a-document">unload</a> event
of the previous document. If there is no previous document or the
previous document has a different <a data-cite=
"html#concept-origin">origin</a> than the current document or the
unload is not yet completed, this attribute must return zero.
</p>
<p>
If there are <a data-cite="FETCH#redirect-status">HTTP
redirects</a> when navigating and not all the redirects are from
the same <a data-cite="html#concept-origin">origin</a>, both
{{PerformanceTiming.unloadEventStart}} and
{{PerformanceTiming.unloadEventEnd}} must return zero.
</p>
</dd>
<dt>
<dfn>redirectStart</dfn>
</dt>
<dd>
<p>
If there are <a data-cite="FETCH#redirect-status">HTTP
redirects</a> when navigating and if all the redirects are from
the same <a data-cite="html#concept-origin">origin</a>, this
attribute must return the <a data-lt=
'PerformanceTiming.fetchStart'>starting time of the fetch</a>
that initiates the redirect. Otherwise, this attribute must
return zero.
</p>
</dd>
<dt>
<dfn>redirectEnd</dfn>
</dt>
<dd>
<p>
If there are <a data-cite="FETCH#redirect-status">HTTP
redirects</a> when navigating and all redirects are from the same
<a data-cite="html#concept-origin">origin</a>, 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.
</p>
</dd>
<dt>
<dfn>fetchStart</dfn>
</dt>
<dd>
<p>
If the new resource is to be <a data-cite=
"HTML/urls-and-fetching.html#fetching-resources">fetched</a>
using a "GET" <a data-cite="FETCH#concept-request-method">request
method</a>, fetchStart must return the time immediately before
the user agent starts checking the [[RFC7234|HTTP cache]]. Otherwise, it must
return the time when
the user agent starts <a data-cite=
"HTML/urls-and-fetching.html#fetching-resources">fetching</a> the
resource.
</p>
</dd>
<dt>
<dfn>domainLookupStart</dfn>
</dt>
<dd>
<p>
This attribute must return the time immediately before the user
agent starts the domain name lookup for the current document. If
a <a href=
"https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1">persistent
connection</a> [[RFC2616]] is used or the current document is
retrieved from the [[RFC7234|HTTP cache]] or local resources, this attribute must
return the same value as {{PerformanceTiming.fetchStart}}.
</p>
</dd>
<dt>
<dfn>domainLookupEnd</dfn>
</dt>
<dd>
<p>
This attribute must return the time immediately after the user
agent finishes the domain name lookup for the current document.
If a <a href=
"https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1">persistent
connection</a> [[RFC2616]] is used or the current document is
retrieved from the [[RFC7234|HTTP cache]] or local resources, this attribute must
return the same value as {{PerformanceTiming.fetchStart}}.
</p>
<div class="note">
<p>
Checking and retrieving contents from the <a href=
"https://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13">
HTTP cache</a> [[RFC2616]] is part of the <a data-cite=
"HTML/urls-and-fetching.html#fetching-resources">fetching
process</a>. It's covered by the
{{PerformanceTiming.requestStart}},
{{PerformanceTiming.responseStart}} and
{{PerformanceTiming.responseEnd}} attributes.
</p>
</div>
<p class="note">
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.
</p>
</dd>
<dt>
<dfn>connectStart</dfn>
</dt>
<dd>
<p>
This attribute must return the time immediately before the user
agent start establishing the connection to the server to retrieve
the document. If a <a href=
"https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1">persistent
connection</a> [[RFC2616]] is used or the current document is
retrieved from the [[RFC7234|HTTP cache]] or local resources, this attribute must
return value of {{PerformanceTiming.domainLookupEnd}}.
</p>
</dd>
<dt>
<dfn>connectEnd</dfn>
</dt>
<dd>
<p>
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 <a href=
"https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1">persistent
connection</a> [[RFC2616]] is used or the current document is
retrieved from the [[RFC7234|HTTP cache]] or local resources, this attribute must
return the value of {{PerformanceTiming.domainLookupEnd}}.
</p>
<p>
If the transport connection fails and the user agent reopens a
connection, {{PerformanceTiming.connectStart}} and
{{PerformanceTiming.connectEnd}} should return the corresponding
values of the new connection.
</p>
<p>
{{PerformanceTiming.connectEnd}} must include the time interval
to establish the transport connection as well as other time
interval such as SSL handshake and SOCKS authentication.
</p>
</dd>
<dt>
<dfn>secureConnectionStart</dfn>
</dt>
<dd>
<p>
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 <a data-cite=
"url#concept-url-scheme">scheme</a> [[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.
</p>
</dd>
<dt>
<dfn>requestStart</dfn>
</dt>
<dd>
<p>
This attribute must return the time immediately before the user
agent starts requesting the current document from the server, or
from the [[RFC7234|HTTP cache]] or from local resources.
</p>
<p>
If the transport connection fails after a request is sent and the
user agent reopens a connection and resend the request,
{{PerformanceTiming.requestStart}} should return the
corresponding values of the new request.
</p>
<div class="note">
<p>
This interface does not include an attribute to represent the
completion of sending the request, e.g., requestEnd.
</p>
<ul>
<li>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.
</li>
<li>Some user agents have high cost to determine the actual
completion time of sending the request due to the HTTP layer
encapsulation.
</li>
</ul>
</div>
</dd>
<dt>
<dfn>responseStart</dfn>
</dt>
<dd>
<p>
This attribute must return the time immediately after the user
agent receives the first byte of the response from the server, or
from the [[RFC7234|HTTP cache]] or from local resources.