-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathprerendering.bs
More file actions
1291 lines (872 loc) · 77.7 KB
/
Copy pathprerendering.bs
File metadata and controls
1291 lines (872 loc) · 77.7 KB
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
<pre class="metadata">
Title: Prerendering Revamped
Shortname: prerendering-revamped
Group: WICG
Status: CG-DRAFT
Repository: WICG/nav-speculation
URL: https://wicg.github.io/nav-speculation/prerendering.html
Level: 1
Editor: Domenic Denicola, Google https://www.google.com/, d@domenic.me
Editor: Dominic Farolino, Google https://www.google.com/, domfarolino@gmail.com
Abstract: This document contains a collection of specification patches for well-specified prerendering.
Markup Shorthands: css no, markdown yes
Assume Explicit For: yes
Complain About: accidental-2119 yes, missing-example-ids yes
Indent: 2
Boilerplate: omit conformance
</pre>
<pre class="link-defaults">
spec:fetch; type:dfn; text:credentials
spec:infra; type:dfn; text:user agent
spec:html; type:element; text:a
spec:html; type:element-attr; for:a; text:target
</pre>
<pre class="anchors">
spec: ecma262; urlPrefix: https://tc39.es/ecma262/
type: dfn
text: current realm; url: current-realm
spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/
type: dfn
text: valid navigable target name or keyword; url: document-sequences.html#valid-navigable-target-name-or-keyword
text: active needed worker; url: workers.html#active-needed-worker
text: attempt to populate the history entry's document; url: browsing-the-web.html#attempt-to-populate-the-history-entry's-document
text: can have its URL rewritten; url: nav-history-apis.html#can-have-its-url-rewritten
text: check if unloading is user-canceled; url: browsing-the-web.html#checking-if-unloading-is-user-canceled
text: create a new child navigable; url: document-sequences.html#create-a-new-child-navigable
text: create a new top-level traversable; url: document-sequences.html#creating-a-new-top-level-traversable
text: create navigation params by fetching; url: browsing-the-web.html#create-navigation-params-by-fetching
text: current playback position; url: media.html#current-playback-position
text: destroy a top-level traversable; url: document-sequences.html#destroy-a-top-level-traversable
text: finalize a cross-document navigation; url: browsing-the-web.html#finalize-a-cross-document-navigation
text: fire a push/replace/reload navigate event; url: nav-history-apis.html#fire-a-push/replace/reload-navigate-event
text: hand-off to external software; url: browsing-the-web.html#hand-off-to-external-software
text: history handling behavior; url: browsing-the-web.html#history-handling-behavior
text: navigation and traversal task source; url: webappapis.html#navigation-and-traversal-task-source
text: navigation API; url: nav-history-apis.html#window-navigation-api
text: navigation ID; url: browsing-the-web.html#navigation-id
text: playing the media resource; url: media.html#playing-the-media-resource
text: session history entry; url: browsing-the-web.html#session-history-entry
text: the worker's lifetime; url: workers.html#the-worker's-lifetime
text: URL and history update steps; url: browsing-the-web.html#url-and-history-update-steps
for: Document
text: abort; url: document-lifecycle.html#abort-a-document
text: destroy; url: document-lifecycle.html#destroy-a-document
text: is initial about:blank; url: dom.html#is-initial-about%3Ablank
for: document state
text: initiator origin; url: browsing-the-web.html#document-state-initiator-origin
for: navigable
text: ongoing navigation; url: browsing-the-web.html#ongoing-navigation
text: parent; url: document-sequences.html#nav-parent
for: navigate
text: referrerPolicy; url: browsing-the-web.html#navigation-referrer-policy
for: navigation params
text: request; url: browsing-the-web.html#navigation-params-request
text: response; url: browsing-the-web.html#navigation-params-response
for: NavigationType
text: replace; url: nav-history-apis.html#dom-navigationtype-replace
for: session history entry
text: document state; url: browsing-the-web.html#she-document-state
text: document; url: browsing-the-web.html#she-document
for: traversable navigable
text: append session history traversal steps; url: browsing-the-web.html#tn-append-session-history-traversal-steps
text: current session history step; url: document-sequences.html#tn-current-session-history-step
text: session history entries; url: document-sequences.html#tn-session-history-entries
for: HTMLHyperlinkElementUtils
text: url; url: links.html#concept-hyperlink-url
for: Window
text: navigable; url: nav-history-apis.html#window-navigable
spec: HTML; urlPrefix: https://whatpr.org/html/11426/speculative-loading.html#
type: dfn
text: collecting tags from speculative load candidates; url: collect-tags-from-speculative-load-candidates
text: compute a speculative load referrer policy; url: compute-speculative-load-referrer-policy
text: consider speculative loads; url: consider-speculative-loads
text: finding matching links; url: finding-matching-links
text: inner consider speculative loads steps; url: inner-consider-speculative-loads-steps
text: parse a speculation rule set string; url: speculation-rule-set
text: parse a speculation rule; url: parse-a-speculation-rule
text: prefetch candidate; url: prefetch-candidate
text: speculation rule set; url: speculation-rule-set
text: speculation rule; url: speculation-rule
text: speculative load candidate; url: speculative-load-candidate
for: Document
text: speculation rule sets; url: document-sr-sets
for: prefetch candidate
text: anonymization policy; url: sl-candidate-anonymization-policy
for: speculation rule
text: URLs; url: sr-urls
text: predicate; url: sr-predicate
text: eagerness; url: sr-eagerness
text: referrer policy; url: sr-referrer-policy
text: tags; url: sr-tags
text: No-Vary-Search hint; url: sr-nvs-hint
text: requirements; url: sr-requirements
for: speculation rule set
text: prefetch rules; url: sr-set-prefetch
for: speculative load candidate
text: URL; url: sl-candidate-url
text: No-Vary-Search hint; url: sl-candidate-nvs-hint
text: eagerness; url: sl-candidate-eagerness
text: referrer policy; url: sl-candidate-referrer-policy
text: tags; url: sl-candidate-tags
spec: HTML; urlPrefix: https://whatpr.org/html/11426/semantics.html#
type: dfn
text: get an element's target; url: get-an-element's-target
spec: battery; urlPrefix: https://w3c.github.io/battery/
type: dfn
text: [[BatteryPromise]]; url: dfn-batterypromise
spec: picture-in-picture; urlPrefix: https://w3c.github.io/picture-in-picture/
type: dfn
text: request Picture-in-Picture; url: request-picture-in-picture-algorithm
spec: mediacapture-main; urlPrefix: https://w3c.github.io/mediacapture-main/
type: dfn
text: device change notification steps; url: dfn-device-change-notification-steps
spec: no-vary-search; urlPrefix: https://httpwg.org/http-extensions/draft-ietf-httpbis-no-vary-search.html
type: dfn
text: URL search variance; url: name-data-model
text: default URL search variance; url: iref-default-url-search-variance
text: obtain a URL search variance; url: name-obtain-a-url-search-varianc
text: equivalent modulo search variance; url: name-comparing
type: http-header
text: No-Vary-Search; url: name-http-header-field-definitio
spec: PREFETCH; urlPrefix: prefetch.html
type: dfn
text: supports prefetch; url: supports-prefetch
text: list of sufficiently-strict speculative navigation referrer policies
text: wait for a matching prefetch record; url: wait-for-a-matching-prefetch-record
text: has a matching prefetch record
text: start a referrer-initiated navigational prefetch
for: prefetch record
text: source
text: prerendering traversable
text: prerendering target navigable name hint
for: has a matching prefetch record
text: checkPrerender
for: Sec-Purpose prefetch
text: prerender
spec: RFC8941; urlPrefix: https://www.rfc-editor.org/rfc/rfc8941.html
type: dfn
text: structured header; url: #section-1
for: structured header
text: list; url: name-lists
text: token; url: name-tokens
spec: client-hints-infrastructure; urlPrefix: https://wicg.github.io/client-hints-infrastructure
type: dfn
text: Accept-CH cache; url: accept-ch-cache
text: create or override the cached client hints set; url: abstract-opdef-create-or-override-the-cached-client-hints-set
text: client hints token; url: client-hints-token-definition
text: client hints set; url: client-hints-set
text: update the client hints set from cache; url: update-the-client-hints-set-from-cache
for: environment settings object
text: client hints set; url: environment-settings-object-client-hints-set
for: accept-ch-cache
text: origin; url:accept-ch-cache-origin
spec: web-audio; urlPrefix: https://webaudio.github.io/web-audio-api/
type: dfn
text: allowed to start; url: allowed-to-start
text: control message; url: control-message
text: [[control thread state]]; url: dom-baseaudiocontext-control-thread-state-slot
text: running; url: dom-audiocontextstate-running
text: queue a control message; url: queuing
text: [[pending resume promises]]; url: dom-audiocontext-pending-resume-promises-slot
</pre>
<pre class="biblio">
{
"IDLE-DETECTION": {
"authors": [
"Reilly Grant"
],
"href": "https://wicg.github.io/idle-detection/",
"title": "Idle Detection API",
"status": "CG-DRAFT",
"publisher": "W3C"
}
}
</pre>
<style>
/* domintro and XXX from https://resources.whatwg.org/standard.css */
.domintro {
position: relative;
color: green;
background: #DDFFDD;
margin: 2.5em 0 2em 0;
padding: 1.5em 1em 0.5em 2em;
}
.domintro dt, .domintro dt * {
color: black;
font-size: inherit;
}
.domintro dd {
margin: 0.5em 0 1em 2em; padding: 0;
}
.domintro dd p {
margin: 0.5em 0;
}
.domintro::before {
content: 'For web developers (non-normative)';
background: green;
color: white;
padding: 0.15em 0.25em;
font-style: normal;
position: absolute;
top: -0.8em;
left: -0.8em;
}
.XXX {
color: #D50606;
background: white;
border: solid #D50606;
}
/* dl.props from https://resources.whatwg.org/standard.css */
dl.props { display: grid; grid-template-columns: max-content auto; row-gap: 0.25em; column-gap: 1em; }
dl.props > dt { grid-column-start: 1; margin: 0; }
dl.props > dd { grid-column-start: 2; margin: 0; }
p + dl.props { margin-top: -0.5em; }
</style>
<h2 id="speculation-rules">Speculation rules</h2>
Modify the HTML Standard's speculation rules specification as follows to support prerendering.
(Currently, the HTML Standard's speculation rules lives in <a href="https://github.com/whatwg/html/pull/11426">whatwg/html#11426</a>, with the rendered specification text at <a href="https://whatpr.org/html/11426/speculative-loading.html">this PR preview</a>. But we anticipate it merging in the main HTML Standard shortly.)
<h3 id="speculation-rules-parsing">Parsing</h3>
Extend the [=speculation rule set=] [=struct=] with one additional [=struct/item=]:
* <dfn for="speculation rule set">prerender rules</dfn>, a [=list=] of [=speculation rules=], initially empty
Extend the [=speculation rule=] [=struct=] with one additional [=struct/item=]:
* <dfn for="speculation rule">target navigable name hint</dfn>, a [=string=] or null
<div algorithm="parse a speculation rule set string">
Modify [=parse a speculation rule set string=] as follows:
* Remove the <var ignore>typesToTreatAsPrefetch</var> construct, and instead parse |parsed|["`prerender`"] into the [=speculation rule set/prerender rules=] list, in an identical manner to what is done for |parsed|["`prefetch`"] and the [=speculation rule set/prefetch rules=].
* Discard rules parsed from |parsed|["`prefetch`"] if the [=speculation rule/target navigable name hint=] is not null.
* Discard rules parsed from |parsed|["`prerender`"] if the [=speculation rule/requirements=] contain "`anonymous-client-ip-when-cross-origin`".
<p class="note">Implementations will still be allowed to treat prerender candidates as prefetches, per the modifications in [[#speculation-rules-processing]].</p>
</div>
<div algorithm="parse a speculation rule">
Modify [=parse a speculation rule=] by adding the following steps:
1. Let |targetHint| be null.
1. If |input|["`target_hint`"] [=map/exists=]:
1. If |input|["`target_hint`"] is not a [=valid navigable target name or keyword=]:
1. The user agent may [=report a warning to the console=] indicating that the supplied target hint was invalid.
1. Return null.
1. Set |targetHint| to |input|["`target_hint`"].
and then updating the final step which returns a [=speculation rule=] to include setting the [=speculation rule/target navigable name hint=] to |targetHint|.
</div>
<h3 id="speculation-rules-processing">Processing model</h3>
A <dfn>prerender candidate</dfn> is a [=speculative load candidate=] with the following additional [=struct/item=]:
* <dfn for="prerender candidate">target navigable name hint</dfn>, a [=valid navigable target name or keyword=] or null
<div algorithm="inner consider speculative loads steps">
Update the [=inner consider speculative loads steps=] algorithm by appending the following steps near the beginning, after assembling |prefetchCandidates|:
1. Let |prerenderCandidates| be an empty [=list=].
1. [=list/For each=] |ruleSet| of |document|'s [=Document/speculation rule sets=]:
1. [=list/For each=] |rule| of |ruleSet|'s [=speculation rule set/prerender rules=]:
1. [=list/For each=] |url| of |rule|'s [=speculation rule/URLs=]:
1. Let |referrerPolicy| be the result of [=computing a speculative load referrer policy=] given |rule| and null.
1. [=list/Append=] a new [=prerender candidate=] with
<dl class="props">
: [=speculative load candidate/URL=]
:: |url|
: [=speculative load candidate/No-Vary-Search hint=]
:: |rule|'s [=speculation rule/No-Vary-Search hint=]
: [=speculative load candidate/eagerness=]
:: |rule|'s [=speculation rule/eagerness=]
: [=speculative load candidate/referrer policy=]
:: |referrerPolicy|
: [=speculative load candidate/tags=]
:: |rule|'s [=speculation rule/tags=]
: [=prerender candidate/target navigable name hint=]
:: |rule|'s [=speculation rule/target navigable name hint=]
</dl>
to |prerenderCandidates|.
1. If |rule|'s [=speculation rule/predicate=] is not null, then:
1. Let |links| be the result of [=finding matching links=] given |document| and |rule|'s [=speculation rule/predicate=].
1. [=list/For each=] |link| of |links|:
1. Let |target| be |rule|'s [=speculation rule/target navigable name hint=].
1. If |target| is null, set it to the result of [=getting an element's target=] given |link|.
1. Let |referrerPolicy| be the result of [=computing a speculative load referrer policy=] given |rule| and |link|.
1. [=list/Append=] a [=prerender candidate=] with
<dl class="props">
: [=speculative load candidate/URL=]
:: |link|'s [=HTMLHyperlinkElementUtils/url=]
: [=speculative load candidate/No-Vary-Search hint=]
:: |rule|'s [=speculation rule/No-Vary-Search hint=]
: [=speculative load candidate/eagerness=]
:: |rule|'s [=speculation rule/eagerness=]
: [=speculative load candidate/referrer policy=]
:: |referrerPolicy|
: [=speculative load candidate/tags=]
:: |rule|'s [=speculation rule/tags=]
: [=prerender candidate/target navigable name hint=]
:: |target|
</dl>
to |prerenderCandidates|.
1. Let |speculativeLoadCandidates| be the union of |prefetchCandidates| and |prerenderCandidates|.
Update subsequent steps for canceling not-still-being-speculated [=prefetch records=] to operate on |speculativeLoadCandidates| instead of |prefetchCandidates|.
Create a list |prerenderCandidateGroups| in an analogous way to |prefetchCandidateGroups|, but using |prerenderCandidates| instead of |prefetchCandidates|.
Replace the step which performs the actual prefetching by looping over |prefetchCandidateGroups| with the following:
1. Let |speculativeLoadCandidateGroups| be the union of |prefetchCandidateGroups| and |prerenderCandidateGroups|.
1. [=list/For each=] |group| of |speculativeLoadCandidateGroups|:
1. The user agent may run the following steps:
1. Let |candidate| be |group|[0].
1. Let |tagsToSend| be the result of [=collecting tags from speculative load candidates=] given |group|.
1. Let |prefetchRecord| be a new [=prefetch record=] with
<dl class="props">
: [=prefetch record/source=]
:: "`speculation rules`"
: [=prefetch record/URL=]
:: |candidate|'s [=speculative load candidate/URL=]
: [=prefetch record/No-Vary-Search hint=]
:: |candidate|'s [=speculative load candidate/No-Vary-Search hint=]
: [=prefetch record/referrer policy=]
:: |candidate|'s [=speculative load candidate/referrer policy=]
: [=prefetch record/tags=]
:: |tagsToSend|
</dl>
1. If |candidate| is a [=prefetch candidate=], then set |prefetchRecord|'s [=prefetch record/anonymization policy=] to |candidate|'s [=prefetch candidate/anonymization policy=].
1. If |candidate| is a [=prerender candidate=], then the user agent may run the following steps:
1. Set |prefetchRecord|'s [=prefetch record/prerendering traversable=] to "`to be created`".
1. Set |prefetchRecord|'s [=prefetch record/prerendering target navigable name hint=] to |candidate|'s [=prerender candidate/target navigable name hint=].
1. [=Start a referrer-initiated navigational prerender=] given |document| and |prefetchRecord|.
1. If the user agent did not run the previous step, then [=start a referrer-initiated navigational prefetch=] given |document| and |prefetchRecord|.
(And keep the subsequent discussion of when to execute this "may" step.)
</div>
<h3 id="speculation-rules-triggering">Triggering</h3>
Update the [=attribute change steps=] for <{a}> and <{area}> elements to also monitor the <{a/target}> attribute and [=consider speculative loads=] if it changes.
<h2 id="prerendering-infra">Prerendering infrastructure</h2>
<h3 id="document-prerendering">Extensions to the {{Document}} interface</h3>
We'd modify [[HTML]]'s centralized definition of {{Document}} as follows:
<pre class="idl">
partial interface Document {
readonly attribute boolean prerendering;
// Under "special event handler IDL attributes that only apply to Document objects"
attribute EventHandler onprerenderingchange;
};
</pre>
The <dfn attribute for="Document">onprerenderingchange</dfn> attribute is an [=event handler IDL attribute=] corresponding to the <dfn event for="Document">prerenderingchange</dfn> [=event handler event type=]. (We would update the corresponding table in [[HTML]], which currently only contains {{Document/onreadystatechange}}.)
As is customary for [[HTML]], the definition of {{Document/prerendering}} would be located in another section of the spec; we'd place it in the new section introduced below:
<h3 id="prerendering-navigables">Prerendering navigables</h3>
<em>The following section would be added as a new sub-section of [[HTML]]'s <a href="https://html.spec.whatwg.org/multipage/document-sequences.html#navigables">Navigables</a> section.</em>
Every [=navigable=] has a <dfn for="navigable">loading mode</dfn>, which is one of the following:
: "`default`"
:: No special considerations are applied to content loaded in this navigable
: "`prerender`"
:: This navigable is displaying prerendered content
By default, a [=navigable=]'s [=navigable/loading mode=] is "`default`". A navigable whose [=navigable/loading mode=] is "`prerender`" is known as a <dfn>prerendering navigable</dfn>. A [=prerendering navigable=] that is also a [=top-level traversable=] is known as a <dfn>prerendering traversable</dfn>.
<p class="note">[=Prerendering navigables=]'s [=navigable/active browsing contexts=] are never [=auxiliary browsing contexts=].
<p class="note">Although there are only two values for the [=navigable/loading mode=], we use a flexible structure in anticipation of other future loading modes, such as those provided by fenced frames, portals, and uncredentialed (cross-site) prerendering. It's not yet clear whether that anticipation is correct; if, as those features gain full specifications, it turns out not to be, we will instead convert this into a boolean.
Every [=prerendering traversable=] has a <dfn for="prerendering traversable">prerender initial response search variance</dfn>, which is a [=URL search variance=] or null, and is initially null.
<dl class="domintro">
<dt><code><var ignore>document</var>.{{Document/prerendering}}</code></dt>
<dd>
<p>Returns true if the page is being presented in a non-interactive prerendering context.
<p>The value can change from true to false, which will be accompanied by the {{Document}} firing a {{Document/prerenderingchange}} event. (It can never then change back to true.)
</dl>
The <dfn attribute for="Document">prerendering</dfn> getter steps are to return true if [=this=] has a non-null [=node navigable=] that is a [=prerendering navigable=]; otherwise, false.
<hr>
Every {{Document}} has a <dfn for="Document">post-prerendering activation steps list</dfn>, which is a [=list=] where each [=list/item=] is a series of algorithm steps. For convenience, we define the <dfn for="platform object">post-prerendering activation steps list</dfn> for any platform object |platformObject| as:
<dl class="switch">
: If |platformObject| is a [=node=]
:: 1. Return |platformObject|'s [=Node/node document=]'s [=Document/post-prerendering activation steps list=].
: Otherwise
:: 1. Assert: |platformObject|'s [=relevant global object=] is a {{Window}} object.
:: 1. Return |platformObject|'s [=relevant global object=]'s [=associated Document=]'s [=Document/post-prerendering activation steps list=].
</dl>
Every {{Document}} has an <dfn for="Document">activation start time</dfn>, which is initially a {{DOMHighResTimeStamp}} with a time value of zero.
<h3 id="prerendering-algorithms">Prerender algorithms</h3>
<div algorithm="User-agent initiated prerendering">
[=User agents=] may choose to initiate prerendering without a referrer document, for example as a result of the address bar or other browser user interactions.
To <dfn export>start user-agent initiated prerendering</dfn> given a [=URL=] |startingURL|:
1. [=Assert=]: |startingURL|'s [=url/scheme=] is an [=HTTP(S) scheme=].
1. Let |prerenderingTraversable| be the result of [=creating a new top-level traversable=] given null and the empty string.
1. Set |prerenderingTraversable|'s [=navigable/loading mode=] to "`prerender`".
1. Let |prefetchRecord| be a new [=prefetch record=] whose [=prefetch record/URL=] is |startingURL|, [=prefetch record/anonymization policy=] is null, [=prefetch record/referrer policy=] is the empty string, [=prefetch record/No-Vary-Search hint=] is the [=default URL search variance=], [=prefetch record/source=] is "`browser UI`", and [=prefetch record/prerendering traversable=] is |prerenderingTraversable|.
1. [=Start a referrer-initiated navigational prefetch=] given |prerenderingTraversable|'s [=navigable/active document=] and |prefetchRecord|.
1. [=Navigate=] |prerenderingTraversable| to |startingURL| using |prerenderingTraversable|'s [=navigable/active document=].
<p class="note">We treat this initial navigation as |prerenderingTraversable| navigating itself, which will ensure all relevant security checks pass.
1. When the user indicates they wish to commit a navigation to an |activationURL| which is a [=URL=] such that |prefetchRecord| [=prefetch record/matches a URL=] given |activationURL|:
1. If the user indicates they wish to create a new user-visible [=top-level traversable=] while doing so (e.g., by pressing <kbd><kbd>Shift</kbd>+<kbd>Enter</kbd></kbd> after typing in the address bar):
1. [=prerendering traversable/Update the successor for activation=] given |prerenderingTraversable|, |startingURL|, and |activationURL|.
1. Update the user agent's user interface to present |prerenderingTraversable|, e.g., by creating a new tab/window.
1. [=prerendering traversable/Finalize activation=] for |prerenderingTraversable| given |startingURL|'s [=url/origin=].
1. Alternately, if the user indicates they wish to commit the navigation into an existing [=top-level traversable=] |predecessorTraversable| (e.g., by pressing <kbd>Enter</kbd> after typing in the address bar):
1. [=prerendering traversable/Activate=] |prerenderingTraversable| in place of |predecessorTraversable| given "`push`", |startingURL|, and |activationURL|.
<p class="note">The user might never indicate such a commitment, or might take long enough to do so that the user agent needs to reclaim the resources used by the prerender for some more immediate task. In that case the user agent can [=destroy a top-level traversable|destroy=] |prerenderingTraversable|.
</div>
<div>
To <dfn export>start a referrer-initiated navigational prerender</dfn> given a {{Document}} |referrerDoc| and a [=prefetch record=] |prefetchRecord|:
1. [=Assert=]: |prefetchRecord|'s [=prefetch record/URL=]'s [=url/scheme=] is an [=HTTP(S) scheme=].
1. If |referrerDoc|'s [=node navigable=] is not a [=top-level traversable=], then return.
<p class="note">Currently, prerendering from inside a [=child navigable=] is not specified or implemented. Doing so would involve tricky considerations around how the prerendered navigable appears in the navigable tree.
1. If |referrerDoc|'s [=Document/browsing context=] is an [=auxiliary browsing context=], then return.
<p class="note">This avoids having to deal with any potential opener relationship between the prerendering traversable and |referrerDoc|'s [=Document/browsing context=]'s [=opener browsing context=].
1. If |referrerDoc|'s [=Document/origin=] is not [=/same site=] with |prefetchRecord|'s [=prefetch record/URL=]'s [=url/origin=], then return.
<p class="note">Currently, cross-site prerendering is not specified or implemented, although we have various ideas about how it could work in this repository's explainers.
1. If |referrerDoc| [=has a matching prefetch record=] given |prefetchRecord| with <i>[=has a matching prefetch record/checkPrerender=]</i> set to true, then return.
1. [=Assert=]: |prefetchRecord|'s [=prefetch record/prerendering traversable=] is "`to be created`".
1. Let |prerenderingTraversable| be the result of [=creating a new top-level traversable=].
The user agent can use |prefetchRecord|'s [=prefetch record/prerendering target navigable name hint=] as a hint to their implementation of [=create a new top-level traversable=]. This hint indicates that the web developer expects the eventual [=prerendering traversable/activate|activation=] of the created [=prerendering traversable=] to be in place of a particular predecessor traversable: the one that would be chosen by the invoking <a spec="HTML">the rules for choosing a navigable</a> given |prefetchRecord|'s [=prefetch record/prerendering target navigable name hint=] and |referrerDoc|'s [=node navigable=].
<p class="note">This is just a hint. The value has no normative implications. It would still be perfectly fine in the future to [=prerendering traversable/activate=] in place of a different predecessor traversable that was not hinted at.
1. Set |prerenderingTraversable|'s [=navigable/loading mode=] to "`prerender`".
1. Set |prefetchRecord|'s [=prefetch record/prerendering traversable=] to |prerenderingTraversable|.
1. Set |prerenderingTraversable|'s [=prerendering traversable/remove from referrer=] to be an algorithm which sets |prefetchRecord|'s [=prefetch record/prerendering traversable=] to null.
<p class="note">As with all [=top-level traversables=], the [=prerendering traversable=] can be [=destroy a top-level traversable|destroyed=] for any reason, for example if it becomes unresponsive, performs a restricted operation, or if the user agent believes prerendering takes too many resources. In such cases, the [=prefetch record=] will remain, so it can be used to fulfill future navigations, even if the [=prerendering traversable=] has been destroyed.
1. [=Start a referrer-initiated navigational prefetch=] given |referrerDoc| and |prefetchRecord|.
1. [=Navigate=] |prerenderingTraversable| to |prefetchRecord|'s [=prefetch record/URL=] using |referrerDoc|, with <i>[=navigate/referrerPolicy=]</i> set to |prefetchRecord|'s [=prefetch record/referrer policy=].
</div>
<div algorithm>
To <dfn for="prerendering traversable">update the successor for activation</dfn> given a [=prerendering traversable=] |successorTraversable|, a [=URL=] |startingURL|, and a [=URL=] |activationURL|:
1. Let |successorDocument| be |successorTraversable|'s [=navigable/active document=].
1. If |startingURL| equals |successorDocument|'s [=Document/URL=] and |startingURL| does not equal |activationURL|:
1. [=Assert=]: |successorDocument| [=can have its URL rewritten=] to |activationURL|.
1. Let |navigation| be |successorDocument|'s [=relevant global object=]'s [=navigation API=].
1. Let |continue| be the result of <a>firing a push/replace/reload <code>navigate</code> event</a> at |navigation| given "[=NavigationType/replace=]", |activationURL|, and true.
1. If |continue| is true, run the [=URL and history update steps=] given |successorDocument| and |activationURL|.
<p class="note">This allows for the URL of the prerender to match the URL actually navigated to, in the case of inexact matching based on [:No-Vary-Search:].
</div>
<div algorithm>
To <dfn for="prerendering traversable">activate</dfn> a [=prerendering traversable=] |successorTraversable| in place of a [=top-level traversable=] |predecessorTraversable| given a [=history handling behavior=] |historyHandling|, a [=URL=] |startingURL|, a [=URL=] |activationURL|, an optional [=navigation ID=] |navigationId|:
1. [=Assert=]: |successorTraversable|'s [=navigable/active document=]'s [=Document/is initial about:blank=] is false.
1. If |navigationId| is not given, then let |navigationId| be the result of [=generating a random UUID=].
1. Let |referrerOrigin| be |predecessorTraversable|'s [=navigable/active document=]'s [=Document/origin=].
1. Set |predecessorTraversable|'s [=navigable/ongoing navigation=] to |navigationId|.
<p class="note">This will have the effect of aborting any other ongoing navigations of |predecessorTraversable|.
1. [=In parallel=], run these steps:
1. Let |unloadPromptCanceled| be the result of [=checking if unloading is user-canceled=] for |predecessorTraversable|'s [=navigable/active document=]'s [=Document/inclusive descendant navigables=].
1. If |unloadPromptCanceled| is true, or |predecessorTraversable|'s [=navigable/ongoing navigation=] is no longer |navigationId|, then abort these steps.
1. [=Queue a global task=] on the [=navigation and traversal task source=] given |predecessorTraversable|'s [=navigable/active window=] to [=Document/abort=] |predecessorTraversable|'s [=navigable/active document=].
1. [=prerendering traversable/Update the successor for activation=] given |successorTraversable|, |startingURL|, and |activationURL|.
1. [=traversable navigable/Append session history traversal steps=] to |predecessorTraversable| to perform the following steps:
1. [=Assert=]: |successorTraversable|'s [=traversable navigable/current session history step=] is 0.
1. [=Assert=]: |successorTraversable|'s [=traversable navigable/session history entries=]'s [=list/size=] is 1.
1. Let |successorEntry| be |successorTraversable|'s [=traversable navigable/session history entries=][0].
1. [=list/Remove=] |successorEntry| from |successorTraversable|'s [=traversable navigable/session history entries=].
<p class="note">At this point, |successorTraversable| is empty and can be unobservably destroyed. (As long as the implementation takes care to keep |successorEntry|, including its [=session history entry/document=] and that {{Document}}'s [=Document/browsing context=], alive for the next step.)
1. [=Finalize a cross-document navigation=] given |predecessorTraversable|, |historyHandling|, and |successorEntry|.
<p class="note">Because we have moved the entire [=session history entry=], including the contained [=session history entry/document=]'s [=Document/browsing context=], this means traversing across the associated history entries will cause a browsing context group switch, similar to what happens with the [:Cross-Origin-Opener-Policy:] header. Importantly, this will sever any opener relationships, in the same way as COOP. Such traversal includes both the actual activation process here, where we make |successorEntry| active, but also e.g. the user pressing the back button (or the page using `history.back()`) after activation, which will switch in the other direction.
1. Update the user agent's user interface to reflect this change, e.g., by updating the tab/window contents and the browser chrome.
1. [=prerendering traversable/Finalize activation=] for |successorTraversable| given |referrerOrigin|.
1. <p class="XXX">Perhaps we should do something with WebDriver BiDi here? See <a href="https://github.com/w3c/webdriver-bidi/issues/321">w3c/webdriver-bidi#321</a>. Right now the pre-[=in parallel=] part of the [=navigate=] algorithm will send [=WebDriver BiDi navigation started=] as if it were a normal navigation, but then nothing will happen to indicate the navigation finishes.
</div>
<div algorithm>
To <dfn for="prerendering traversable">finalize activation</dfn> of a top-level traversable |traversable| given an [=origin=] |origin|:
1. [=list/For each=] |navigable| of |traversable|'s [=navigable/active document=]'s [=Document/inclusive descendant navigables=], [=queue a global task=] on the [=navigation and traversal task source=], given |navigable|'s [=navigable/active window=], to perform the following steps:
1. [=map/For each=] |origin| → |hintSet| in |navigable|'s [=prerendering navigable/prerender-scoped Accept-CH cache=]:
1. [=map/Set=] [=Accept-CH cache=][|origin|] to |hintSet|.
1. Let |doc| be |navigable|'s [=navigable/active document=].
1. <p class="XXX">We should really propagate the loading mode change here, in the posted task. This is where implementations would update what is returned by {{Document/prerendering|document.prerendering}}. However, right now it lives on the traversable, so it gets magically updated when we move over the session history entry. Probably we need to move it to the {{Document}}.
1. If |doc|'s [=Document/origin=] is the same as |origin|, then set |doc|'s [=Document/activation start time=] to the [=current high resolution time=] for |doc|'s [=relevant global object=].
1. [=Fire an event=] named {{Document/prerenderingchange}} at |doc|.
1. [=list/For each=] |steps| in |doc|'s [=Document/post-prerendering activation steps list=]:
1. Run |steps|.
<p class="note">These steps might return something, like a {{Promise}}. That is just an artifact of how the spec is modified; such return values can always be ignored.
1. Assert: running |steps| did not throw an exception.
<p class="note">The order here is observable for {{Document}}s that share an [=event loop=], but not for those in separate event loops.
</div>
<div algorithm>
A [=prerendering traversable=] has an associated <dfn for="prerendering traversable">remove from referrer</dfn>, which is null or an algorithm with no arguments, initially set to null.
To ensure that the references for a [=prerendering traversable=] are cleared once it is [=destroy a top-level traversable|destroyed=], modify [=destroy a top-level traversable=] by appending the following step:
1. If |traversable| is a [=prerendering traversable=] and |traversable|'s [=prerendering traversable/remove from referrer=] is not null, then call |traversable|'s [=prerendering traversable/remove from referrer=].
</div>
<h3 id="creating-navigables-patch">Modifications to creating navigables</h3>
<div algorithm="create a new child navigable patch">
To ensure that any [=child navigables=] inherit their [=navigable/parent=]'s [=navigable/loading mode=], modify [=create a new child navigable=] by appending the following step:
1. Set <var ignore>navigable</var>'s [=navigable/loading mode=] to <var ignore>element</var>'s [=node navigable=]'s [=navigable/loading mode=].
</div>
<h2 id="navigation">Navigation and session history</h2>
<h3 id="navigate-activation">Allowing activation in place of navigation</h3>
<div algorithm>
To <dfn>find a matching prerendered prefetch record</dfn> given a {{Document}} |predecessorDocument| and [=URL=] |url|:
1. Let |recordToUse| be null.
1. [=list/For each=] |record| of |predecessorDocument|'s [=Document/prefetch records=]:
1. If |record|'s [=prefetch record/prerendering traversable=] is not a [=prerendering traversable=], then [=iteration/continue=].
1. If |record|'s [=prefetch record/prerendering traversable=]'s [=navigable/active document=]'s [=Document/is initial about:blank=] is true, then [=iteration/continue=].
1. If |record|'s [=prefetch record/URL=] is equal to |url|:
1. Set |recordToUse| to |record|.
1. [=iteration/Break=].
1. If |recordToUse| is null and |record| [=prefetch record/matches a URL=] given |url|:
1. Set |recordToUse| to |record|.
1. If |recordToUse| is not null:
1. [=list/Remove=] |recordToUse| from |predecessorDocument|'s [=Document/prefetch records=].
1. Return |recordToUse|.
</div>
<div algorithm>
To <dfn>wait for a matching prerendered prefetch record</dfn> given a [=navigable=] |navigable|, a [=URL=] |url|, a string |cspNavigationType|, and a [=POST resource=], string, or null |documentResource|:
1. [=Assert=]: this is running [=in parallel=].
1. If any of the following conditions hold:
* |navigable| is not a [=top-level traversable=];
* |navigable| is a [=prerendering traversable=];
* |navigable| is a [fenced frame](https://github.com/shivanigithub/fenced-frame);
<p class="issue">The concept of a fenced frame navigable is not yet defined but we need to link to it once it exists.</p>
* |cspNavigationType| is not "`other`"; or
* |documentResource| is not null
then return null.
1. Let |predecessorDocument| be |navigable|'s [=navigable/active document=].
1. Let |cutoffTime| be null.
1. While true:
1. Let |completeRecord| be the result of [=finding a matching prerendered prefetch record=] given |predecessorDocument| and |url|.
1. If |completeRecord| is not null, return |completeRecord|.
1. Let |potentialRecords| be an empty [=list=].
1. [=list/For each=] |record| of |predecessorDocument|'s [=Document/prefetch records=]:
1. If all of the following are true, then [=list/append=] |record| to |potentialRecords|:
* |record|'s [=prefetch record/prerendering traversable=] is a [=prerendering traversable=];
* |record|'s [=prefetch record/prerendering traversable=]'s [=navigable/active document=]'s [=Document/is initial about:blank=] is true;
* |record| [=prefetch record/is expected to match a URL=] given |url|; and
* |cutoffTime| is null or |record|'s [=prefetch record/start time=] is less than |cutoffTime|.
1. If |potentialRecords| [=list/is empty=], return null.
1. Wait until the [=navigable/ongoing navigation=] of the [=prefetch record/prerendering traversable=] of any element of |predecessorDocument|'s [=Document/prefetch records=] changes.
1. If |cutoffTime| is null and any element of |potentialRecords| has a [=prefetch record/prerendering traversable=] whose [=navigable/active document=]'s [=Document/is initial about:blank=] is false, set |cutoffTime| to the [=current high resolution time=] for the [=relevant global object=] of |predecessorDocument|.
</div>
Patch the [=navigate=] algorithm to allow the [=prerendering traversable/activate|activation=] of a [=prerendering traversable=] in place of a normal navigation as follows:
<div algorithm="navigate activate patch">
In [=navigate=], insert the following steps as the first ones after we go [=in parallel=]:
1. Let |record| be the result of [=waiting for a matching prerendered prefetch record=] given |navigable|, <var ignore>url</var>, <var ignore>cspNavigationType</var>, and <var ignore>documentResource</var>.
1. If |record| is not null, then:
1. Let |matchingPrerenderedNavigable| be |record|'s [=prefetch record/prerendering traversable=].
1. Let |startingURL| be |record|'s [=prefetch record/URL=].
1. [=prerendering traversable/Activate=] |matchingPrerenderedNavigable| in place of |navigable| given <var ignore>historyHandling</var>, |startingURL|, <var ignore>url</var>, and <var ignore>navigationId</var>.
1. Abort these steps.
</div>
<h3 id="navigate-fetch-patch">Navigation fetch changes</h3>
<div algorithm="create navigation params by fetching patch">
In [=create navigation params by fetching=], add the following step near the top of the algorithm:
1. Let |initiatorOrigin| be <var ignore>entry</var>'s [=session history entry/document state=]'s [=document state/initiator origin=].
Append the following steps after the first sub-step under "While true:":
1. If |navigable| is a [=prerendering navigable=] and <var ignore>currentURL</var>'s [=url/origin=] is not [=/same site=] with |initiatorOrigin|, then:
1. If |navigable| is a [=top-level traversable=], then return null.
1. Otherwise, the user agent must wait to continue this algorithm until |navigable|'s [=navigable/loading mode=] becomes "`normal`". At any point during this wait (including immediately), it may instead choose to [=destroy a top-level traversable|destroy=] |navigable|'s [=top-level traversable=] and return null from this algorithm.
Append the following steps toward the end of the algorithm, after the steps which check <var ignore>locationURL</var>:
1. If |navigable| is a [=prerendering navigable=], and <var ignore>responseOrigin</var> is not [=same origin=] with |initiatorOrigin|, then:
1. Let |loadingModes| be the result of [=getting the supported loading modes=] for <var ignore>response</var>.
1. If |loadingModes| does not [=list/contain=] \`<code><a for="Supports-Loading-Mode">credentialed-prerender</a></code>\`, then return null.
<p class="note">In the future we could possibly also allow the `uncredentialed-prerender` token to work here. However, since that is primarily intended for the cross site case, which isn't specified or implemented yet, we don't want to encourage its use in the wild, so for now we specify that prerendering fails if only the `uncredentialed-prerender` token is found.
</div>
<div algorithm="attempt to populate the history entry's document patch">
In [=attempt to populate the history entry's document=], append the following after the steps which establish the value of |failure|, but before the other steps which act on it:
1. If |navigable| is a [=prerendering navigable=], and any of the following hold:
* |failure| is true;
* |navigationParams|'s [=navigation params/request=] is null;
* |navigationParams|'s [=navigation params/request=]'s [=request/current URL=]'s [=url/scheme=] is not a [=HTTP(S) scheme=];
* |navigationParams|'s [=navigation params/request=]'s [=request/current URL=] is not [=potentially trustworthy URL|potentially trustworthy=];
* |navigationParams|'s [=navigation params/response=] does not [=support prefetch=];
<div class="note">Responses which are ineligible for prefetch, e.g. because they have an error status, are not eligible for prerender either. A future version of this specification might allow responses to more clearly delineate the two.</div>
* |navigationParams|'s [=navigation params/response=] has a \``Content-Disposition`\` header specifying the `attachment` disposition type; or
* |navigationParams|'s [=navigation params/response=]'s [=response/status=] is 204 or 205,
then:
1. [=destroy a top-level traversable|Destroy=] |navigable|'s [=navigable/top-level traversable=].
1. Return.
1. If |navigable| is a [=prerendering traversable=] and |navigable|'s [=prerendering traversable/prerender initial response search variance=] is null:
1. Set |navigable|'s [=prerendering traversable/prerender initial response search variance=] to the result of [=obtaining a URL search variance=] given |navigationParams|'s [=navigation params/response=].
</div>
<div algorithm="hand-off to external software patch">
In [=hand-off to external software=], prepend the following step:
1. If <var ignore>navigable</var> is a [=prerendering navigable=], then return without invoking the external software package.
</div>
<p class="XXX">We could also allow prerendering activations in place of redirects, not just in place of navigations. We've omitted that for now as it adds complexity and is not yet implemented anywhere to our knowledge.
<h3 id="always-replacement">Maintaining a trivial session history</h3>
<div algorithm="navigate historyHandling patch">
Patch the [=navigate=] algorithm to ensure the session history of a [=prerendering navigable=] stays trivial by prepending the following step before all others:
1. If <var ignore>navigable</var> is a [=prerendering navigable=], then set <var ignore>historyHandling</var> to "`replace`".
</div>
<div algorithm="URL and history update steps patch">
Patch the <a spec=HTML>URL and history update steps</a> by adding the following step after step 1:
1. If <var ignore>navigable</var> is a [=prerendering navigable=], then set <var ignore>historyHandling</var> to "`replace`".
</div>
<h3 id="interaction-with-workers">Interaction with worker lifetime</h3>
<div algorithm="The worker's lifetime patch">
In <a spec=HTML>The worker's lifetime</a>, modify the definition of [=active needed worker=], to count workers with a [=prerendering navigable=] owner as not [=active needed worker|active=]:
A worker is said to be an [=active needed worker=] if any of its [=WorkerGlobalScope/owner set|owners=] are either {{Document}} objects that are [=Document/fully active=] and their [=node navigable=] is not a [=prerendering navigable=], or [=active needed worker|active needed workers=].
<p class="note">This means that the worker's script would load, but the execution would be suspended until the document is activated.
</div>
<h3 id="cleanup-upon-discarding">Cleanup upon discarding a {{Document}}</h3>
Modify the [=Document/destroy=] algorithm for {{Document}}s by appending the following step:
<div algorithm="discard a Document patch">
1. [=list/Empty=] <var ignore>document</var>'s [=Document/post-prerendering activation steps list=].
</div>
<h2 id="interaction-with-other-specs">Interaction with other specifications and concepts</h2>
<h3 id="interaction-with-visibility-state">Interaction with Page Visibility</h3>
Documents in [=prerendering navigables=] always have a [=Document/visibility state=] of "<code>hidden</code>".
<p class="XXX">We should probably explicitly update this, similar to how we need to update {{Document/prerendering|document.prerendering}}.
<h3 id="interaction-with-system-focus">Interaction with system focus</h3>
[=Prerendering traversables=] never have [=top-level traversable/system focus=].
<h3 id="performance-navigation-timing-extension">Extensions to the {{PerformanceNavigationTiming}} interface</h3>
Extend the {{PerformanceNavigationTiming}} interface as follows:
<pre class="idl">
partial interface PerformanceNavigationTiming {
readonly attribute DOMHighResTimeStamp activationStart;
};
</pre>
The <dfn attribute for="PerformanceNavigationTiming">activationStart</dfn> getter steps are:
1. Return [=this=]'s [=relevant global object=]'s [=associated Document=]'s [=Document/activation start time=].
<h3 id="client-hint-cache">Interaction with Client Hint Cache</h3>
We need to ensure that the [=Accept-CH cache=], which is owned by user agent as a global storage, is not modified while prerendering, but is properly updated after activation. The following modifications ensure this.
Each [=prerendering navigable=] has a <dfn for="prerendering navigable">prerender-scoped Accept-CH cache</dfn>, which is an [=ordered map=] of [=origin=] to [=client hints sets=].
This stores which client hints each origin has opted into receiving, until it can be copied to the global [=Accept-CH cache=] when [=prerendering traversable/finalize activation|activation is finalized=].
<div algorithm="update the client hints set from cache patch">
Modify the <a spec=CLIENT-HINTS-INFRASTRUCTURE>update the client hints set from cache</a> algorithm, by replacing the second step with the following steps.
1. Let |navigable| be <var ignore>settingsObject</var>’s [=environment settings object/global object=]'s [=Window/navigable=].
1. Let |originMatchingEntries| be the entries in the [=Accept-CH cache=] whose [=accept-ch-cache/origin=] is
[=same origin=] with |settingsObject|'s [=environment settings object/origin=].
1. If |navigable| is a [=prerendering navigable=], then:
1. Let |prerenderAcceptClientHintsCache| be |navigable|'s [=prerendering navigable/prerender-scoped Accept-CH cache=].
1. Let |origin| be |settingsObject|'s [=environment settings object/origin=].
1. If |prerenderAcceptClientHintsCache|[|origin|] [=map/exists=], then let |originMatchingEntries| be the entries in the |prerenderAcceptClientHintsCache| whose [=origin=] is [=same origin=] with |origin|.
</div>
<div algorithm="create or override the cached client hints set patch">
Modify the <a spec=CLIENT-HINTS-INFRASTRUCTURE>create or override the cached client hints set</a> algorithm, by updating the last step.
1. Let |navigable| be <var ignore>settingsObject</var>’s [=environment settings object/global object=]'s [=Window/navigable=].
1. If |navigable| is a [=prerendering navigable=], [=map/set=] |navigable|'s [=prerendering navigable/prerender-scoped Accept-CH cache=][|origin|] to |hintSet|.
1. Otherwise, [=map/set=] [=Accept-CH cache=][|origin|] to |hintSet|.
</div>
<h3 id="interaction-with-clear-site-data">Interaction with Clear Site Data</h3>
Add an additional header value description in [[CLEAR-SITE-DATA#header]]:
: "<dfn><code>prerenderCache</code></dfn>"
::
<p>The "`prerenderCache`" type indicates that the server wishes to remove any prerenders initiated by the [=url/origin=] of a particular [=/response=]'s [=response/URL=].
<p>This type is a subset of the "`cache`" type.
<p>Implementation details are below.
Modify <a abstract-op spec="CLEAR-SITE-DATA">parse response's Clear-Site-Data header</a>'s parsing step such that:
* encountering <code>\`"cache"\`</code> or <code>\`"*"\`</code> appends "<code>[=prerenderCache=]</code>" to <var ignore>types</var> (in addition to the values already appended in those branches); and
* encountering <code>\`"prerenderCache"\`</code> appends "<code>[=prerenderCache=]</code>" to <var ignore>types</var>.
Modify <a abstract-op spec="CLEAR-SITE-DATA">clear site data for response</a>'s switch to add a case that handles "<code>[=prerenderCache=]</code>" and calls [=clear prerender cache=] for <var ignore>origin</var>.
<div>
To <dfn>clear prerender cache</dfn> given an [=origin=] |origin|:
1. [=list/For each=] [=navigable/top-level traversable=] |traversable| of the user agent's [=user agent/top-level traversable set=]:
1. Let |navigables| be the [=Document/inclusive descendant navigables=] of |traversable|'s [=navigable/active document=].
1. [=list/For each=] |navigable| in |navigables|:
1. Let |activeDocument| be the |navigable|'s [=navigable/active document=].
1. If |activeDocument|'s [=Document/origin=] is not [=same origin=] with |origin|, then [=iteration/continue=].
1. [=list/For each=] |prefetchRecord| in |activeDocument|'s [=Document/prefetch records=]:
1. If |prefetchRecord|'s [=prefetch record/prerendering traversable=] is null, then [=iteration/continue=].
1. [=prefetch record/Cancel and discard=] |prefetchRecord| given |activeDocument|.
</div>
<h3 id="interaction-with-fetch">Interaction with Fetch</h3>
<div algorithm="HTTP-network-or-cache fetch patch">
Modify <a spec=FETCH>HTTP-network-or-cache fetch</a> by adding the following step after the existing step that sets [:Sec-Purpose:]:
1. Otherwise, if |httpRequest|'s [=request/client=] is an [=environment settings object=] whose [=environment settings object/global object=] is a {{Window}}, and that {{Window}}'s [=Window/navigable=] is a [=prerendering navigable=]:
1. Let |purpose| be a [=structured header/List=] containing the [=structured header/Token=] `prefetch`.
1. Add a parameter whose key is "<a for="Sec-Purpose prefetch">`prerender`</a>" and whose value is true to the `prefetch` token in |purpose|.
1. [=header list/Set a structured field value=] given ([:Sec-Purpose:], |purpose|) in |httpRequest|'s [=request/header list=].
<p class="note">This includes both subresources within the prerendering navigable, and cases where the prerendering navigable is navigating itself.
</div>
<h2 id="supports-loading-mode">The \`<dfn export http-header><code>Supports-Loading-Mode</code></dfn>\` HTTP response header</h2>
<em>The following section would be added as a sub-section of [[HTML]]'s <a href="https://html.spec.whatwg.org/multipage/browsers.html#browsers">Loading web pages</a> section.</em>
In some cases, cross-origin web pages might not be prepared to be loaded in a novel context. To allow them to opt in to being loaded in such ways, the [:Supports-Loading-Mode:] HTTP response header can be used. This header is a [=structured header=]; if present its value must be one or more of the [=structured header/tokens=] listed below.
<p class="note">The parsing is actually done as a [=structured header/list=] of [=structured header/tokens=], and unknown tokens will be ignored.
The \`<code><dfn export for="Supports-Loading-Mode">credentialed-prerender</dfn></code>\` token indicates that the response can be used to create a [=prerendering navigable=], despite the prerendering being initiated by a cross-origin same-site referrer. Without this opt-in, such prerenders will fail, as outlined in [[#navigate-fetch-patch]].
The \`<code><dfn export for="Supports-Loading-Mode">uncredentialed-prefetch</dfn></code>\` token indicates that the response is suitable to use even if a top-level navigation to this URL would ordinarily send [=credentials=] such as cookies. For instance, the response may be identical or it may be semantically equivalent (e.g., an HTML resource containing script which can update the document after navigation, when local user state is available).
To <dfn export>get the supported loading modes</dfn> for a [=response=] |response|:
1. If |response| is a [=network error=], then return an empty list.
1. Let |slmHeader| be the result of [=header list/getting a structured field value=] given [:Supports-Loading-Mode:] and "`list`" from |response|'s [=response/header list=].
1. Return a [=list=] containing all elements of |slmHeader| that are [=structured header/tokens=].
<h2 id="intrusive-behaviors">Preventing intrusive behaviors</h2>
Various behaviors are disallowed in [=prerendering navigables=] because they would be intrusive to the user, since the prerendered content is not being actively interacted with.
<h3 id="patch-downloading">Downloading resources</h3>
Modify the <a spec=HTML>download the hyperlink</a> algorithm to ensure that downloads inside [=prerendering navigable=] are delayed until [=prerendering traversable/activate|activation=], by inserting the following before the step which goes [=in parallel=]:
<div algorithm="download the hyperlink patch">
1. If <var ignore>subject</var>'s [=node navigable=] is a [=prerendering navigable=], then append the following step to <var ignore>subject</var>'s [=platform object/post-prerendering activation steps list=] and return.
</div>
<h3 id="patch-modals">User prompts</h3>
<div algorithm="cannot show simple dialogs patch">
Modify the <a spec=HTML>cannot show simple dialogs</a> algorithm, given a {{Window}} |window|, by prepending the following step:
1. If |window|'s [=Window/navigable=] is a [=prerendering navigable=], then return true.
</div>
<div algorithm="window print() patch">
Modify the {{Window/print()}} method steps by prepending the following step:
1. If [=this=]'s [=Window/navigable=] is a [=prerendering navigable=], then return.
</div>
<h3 id="delay-async-apis">Delaying async API results</h3>
Many specifications need to be patched so that, if a given algorithm invoked in a [=prerendering navigable=], most of its work is deferred until the navigable's [=navigable/top-level traversable=] is [=prerendering traversable/activated=]. This is tricky to do uniformly, as many of these specifications do not have great hygeine around <a href="https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-for-spec-authors">using the event loop</a>. Nevertheless, the following sections give our best attempt.
<h4 id="delay-while-prerendering">The {{[DelayWhilePrerendering]}} extended attribute</h4>
To abstract away some of the boilerplate involved in delaying the action of asynchronous methods until [=prerendering traversable/activate|activation=], we introduce the <dfn extended-attribute>[DelayWhilePrerendering]</dfn> Web IDL extended attribute. It indicates that when a given method is called in a [=prerendering navigable=], it will immediately return a pending promise and do nothing else. Only upon activation will the usual method steps take place, with their result being used to resolve or reject the previously-returned promise.
The {{[DelayWhilePrerendering]}} extended attribute must take no arguments, and must only appear on a <a lt="regular operation" spec="WEBIDL">regular</a> or <a spec="WEBIDL">static operation</a> whose <a spec="WEBIDL">return type</a> is a <a spec="WEBIDL">promise type</a> or {{undefined}}, and whose <a spec="WEBIDL">exposure set</a> contains only {{Window}}.
<div algorithm="DelayWhilePrerendering method steps">
The method steps for any operation annotated with the {{[DelayWhilePrerendering]}} extended attribute are replaced with the following:
1. Let |realm| be the [=current realm=].
1. If the operation in question is a <a spec="WEBIDL">regular operation</a>, then set |realm| to the [=relevant realm=] of [=this=].
1. If |realm|'s [=realm/global object=]'s [=Window/navigable=] is a [=prerendering navigable=], then:
1. Let |promise| be [=a new promise=], created in |realm|.
1. Append the following steps to [=this=]'s [=platform object/post-prerendering activation steps list=]:
1. Let |result| be the result of running the originally-specified steps for this operation, with the same [=this=] and arguments.
1. [=Resolve=] |promise| with |result|.
1. If this operation's <a spec="WEBIDL">return type</a> is a <a spec="WEBIDL">promise type</a>, then return |promise|.
1. Otherwise, return the result of running the originally-specified steps for this operation, with the same [=this=] and arguments.
</div>
<h4 id="patch-service-workers">Service Workers</h4>
Add {{[DelayWhilePrerendering]}} to {{ServiceWorkerRegistration/update()}}, {{ServiceWorkerRegistration/unregister()}}, {{ServiceWorkerContainer/register(scriptURL, options)}}, {{ServiceWorker/postMessage(message, transfer)}}, and {{ServiceWorker/ postMessage(message, options)}}.
<p class="note">This allows prerendered page to take advantage of existing service workers, but not have any effect on the state of service worker registrations.</p>
<h4 id="patch-broadcast-channel">BroadcastChannel</h4>
Add {{[DelayWhilePrerendering]}} to {{BroadcastChannel/postMessage()}}.
<h4 id="patch-geolocation">Geolocation API</h4>
<div algorithm="Geolocation getCurrentPosition patch">
Modify the {{Geolocation/getCurrentPosition()}} method steps by prepending the following step:
1. If [=this=]'s [=relevant global object=]'s [=Window/navigable=] is a [=prerendering navigable=], then append the following steps to [=this=]'s [=platform object/post-prerendering activation steps list=] and return.