You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: prerendering.bs
+79-43Lines changed: 79 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -234,9 +234,10 @@ Modify [[HTML#speculation-rules]] as follows to support prerendering.
234
234
235
235
<h3 id="speculation-rules-parsing">Parsing</h3>
236
236
237
-
Extend the [=speculation rule set=][=struct=] with one additional [=struct/item=]:
237
+
Extend the [=speculation rule set=][=struct=] with two additional [=struct/items=]:
238
238
239
239
* <dfn for="speculation rule set">prerender rules</dfn>, a [=list=] of [=speculation rules=], initially empty
240
+
* <dfn for="speculation rule set">prerender_until_script rules</dfn>, a [=list=] of [=speculation rules=], initially empty
240
241
241
242
Extend the [=speculation rule=][=struct=] with one additional [=struct/item=]:
242
243
@@ -245,11 +246,11 @@ Extend the [=speculation rule=] [=struct=] with one additional [=struct/item=]:
245
246
<div algorithm="parse a speculation rule set string">
246
247
Modify [=parse a speculation rule set string=] as follows:
247
248
248
-
* 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=].
249
+
* Remove the <var ignore>typesToTreatAsPrefetch</var> construct, and instead parse |parsed|["`prerender`"] into the [=speculation rule set/prerender rules=] list, and |parsed|["`prerender_until_script`"] into the [=speculation rule set/prerender_until_script rules=] list, both in an identical manner to what is done for |parsed|["`prefetch`"] and the [=speculation rule set/prefetch rules=].
249
250
250
251
* Discard rules parsed from |parsed|["`prefetch`"] if the [=speculation rule/target navigable name hint=] is not null.
251
252
252
-
* Discard rules parsed from |parsed|["`prerender`"] if the [=speculation rule/requirements=] contain "`anonymous-client-ip-when-cross-origin`".
253
+
* Discard rules parsed from |parsed|["`prerender`"]and |parsed|["`prerender_until_script`"]if the [=speculation rule/requirements=] contain "`anonymous-client-ip-when-cross-origin`".
253
254
254
255
<p class="note">Implementations will still be allowed to treat prerender candidates as prefetches, per the modifications in [[#speculation-rules-processing]].</p>
255
256
</div>
@@ -269,9 +270,10 @@ Extend the [=speculation rule=] [=struct=] with one additional [=struct/item=]:
Update the [=consider speculative loads=] algorithm to bail out early if <var ignore>document</var>'s [=node navigable=] is a [=prerendering navigable=], with an explanatory note about how performing speculative loads in a speculatively-loaded page is too wasteful.
@@ -282,43 +284,14 @@ A <dfn>prerender candidate</dfn> is a [=speculative load candidate=] with the fo
282
284
283
285
1. Let |prerenderCandidates| be an empty [=list=].
284
286
1. [=list/For each=] |ruleSet| of |document|'s [=Document/speculation rule sets=]:
285
-
1. [=list/For each=] |rule| of |ruleSet|'s [=speculation rule set/prerender rules=]:
286
-
1. [=list/For each=] |url| of |rule|'s [=speculation rule/URLs=]:
287
-
1. Let |referrerPolicy| be the result of [=computing a speculative load referrer policy=] given |rule| and null.
288
-
1. [=list/Append=] a new [=prerender candidate=] with
: [=prerender candidate/target navigable name hint=]
339
+
:: |target|
340
+
341
+
: [=prerender candidate/should block scripts=]
342
+
:: |shouldBlockScripts|
343
+
</dl>
344
+
to |prerenderCandidates|.
340
345
1. Let |speculativeLoadCandidates| be the union of |prefetchCandidates| and |prerenderCandidates|.
341
346
342
347
Update subsequent steps for canceling not-still-being-speculated [=prefetch records=] to operate on |speculativeLoadCandidates| instead of |prefetchCandidates|.
@@ -382,7 +387,7 @@ A <dfn>prerender candidate</dfn> is a [=speculative load candidate=] with the fo
382
387
383
388
1. Set |prefetchRecord|'s [=prefetch record/prerendering target navigable name hint=] to |candidate|'s [=prerender candidate/target navigable name hint=].
384
389
385
-
1. [=Start a referrer-initiated navigational prerender=] given |document|and |prefetchRecord|.
390
+
1. [=Start a referrer-initiated navigational prerender=] given |document|, |prefetchRecord|, and |candidate|'s [=prerender candidate/should block scripts=].
386
391
387
392
1. If the user agent did not run the previous step, then [=start a referrer-initiated navigational prefetch=] given |document| and |prefetchRecord|.
388
393
@@ -429,6 +434,17 @@ By default, a [=navigable=]'s [=navigable/loading mode=] is "`default`". A navig
429
434
430
435
<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.
431
436
437
+
Every [=navigable=] has a <dfn for="navigable">scripting mode</dfn>, which is one of the following:
438
+
439
+
: "`enabled`"
440
+
:: Scripts are executed as normal.
441
+
: "`blocked-until-activation`"
442
+
:: Scripts are blocked until the navigable is activated.
443
+
444
+
By default, a [=navigable=]'s [=navigable/scripting mode=] is "`enabled`".
445
+
446
+
<p class="note">The scripting mode is a property of the navigable, instead of the document, so that it can persist across navigations within the same navigable. This is important for cases like the initial `about:blank` document, or for client-side redirects that occur before activation.</p>
447
+
432
448
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.
433
449
434
450
<dl class="domintro">
@@ -497,7 +513,7 @@ Every {{Document}} has an <dfn for="Document">allow cross origin iframes navigat
497
513
</div>
498
514
499
515
<div>
500
-
To <dfn export>start a referrer-initiated navigational prerender</dfn> given a {{Document}} |referrerDoc| and a [=prefetch record=] |prefetchRecord|:
516
+
To <dfn export>start a referrer-initiated navigational prerender</dfn> given a {{Document}} |referrerDoc|, a [=prefetch record=] |prefetchRecord|, and a boolean |blockScripts|:
501
517
502
518
1. [=Assert=]: |prefetchRecord|'s [=prefetch record/URL=]'s [=url/scheme=] is an [=HTTP(S) scheme=].
503
519
@@ -524,6 +540,8 @@ Every {{Document}} has an <dfn for="Document">allow cross origin iframes navigat
524
540
<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.
525
541
526
542
1. Set |prerenderingTraversable|'s [=navigable/loading mode=] to "`prerender`".
543
+
544
+
1. If |blockScripts| is true, set |prerenderingTraversable|'s [=navigable/scripting mode=] to "`blocked-until-activation`".
527
545
528
546
1. Set |prefetchRecord|'s [=prefetch record/prerendering traversable=] to |prerenderingTraversable|.
529
547
@@ -612,6 +630,14 @@ Every {{Document}} has an <dfn for="Document">allow cross origin iframes navigat
612
630
613
631
1. [=map/Set=][=Accept-CH cache=][|origin|] to |hintSet|.
614
632
633
+
1. If |navigable|'s [=navigable/scripting mode=] is "`blocked-until-activation`":
634
+
635
+
1. Set |navigable|'s [=navigable/scripting mode=] to "`enabled`".
636
+
637
+
1. Unblock script execution in |navigable|'s [=navigable/active document=].
638
+
639
+
<p class="XXX">The precise mechanism for how script execution is resumed, especially how previously-queued tasks are processed, needs to be specified in more detail.</p>
640
+
615
641
1. Let |doc| be |navigable|'s [=navigable/active document=].
616
642
617
643
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}}.
@@ -950,6 +976,14 @@ To <dfn export>get the supported loading modes</dfn> for a [=response=] |respons
950
976
951
977
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.
If a [=navigable=]'s [=navigable/scripting mode=] is "`blocked-until-activation`", the user agent must not execute script in the navigable's [=navigable/active document=]. This includes, but is not limited to executing `<script>` elements.
982
+
983
+
<p class="XXX">The precise mechanism for how script execution is blocked, and how various script-related tasks are queued instead of being processed, needs to be specified in more detail.</p>
984
+
985
+
<p class="note">This effectively pauses all JavaScript execution until the page is activated. For inline event handlers, the expected behavior is under discussion.</p>
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=]:
@@ -976,6 +1010,8 @@ Modify the <a spec=HTML>download the hyperlink</a> algorithm to ensure that down
976
1010
977
1011
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.
978
1012
1013
+
<p class="note">Note that if the [=navigable/scripting mode=] is "`blocked-until-activation`", the scripts that would invoke these algorithms are not executed in the first place until activation.</p>
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.
0 commit comments