1.
Speculation
rules
This
specification
is
moving
to
HTML
The
only
valid
string
for
requirements
to
contain
is
"
anonymous-client-ip-when-cross-origin
".
A
speculation
rule
set
is
a
struct
with
the
following
items
:
prefetch
rules
,
a
list
of
speculation
rules
prerender
rules
,
a
list
of
speculation
rules
A
pending
external
speculation
rule
resource
is
a
struct
with
the
following
items
:
URL
,
a
URL
controller
,
a
fetch
controller
or
null
A
document
rule
predicate
is
one
of
the
following:
document
rule
conjunction
document
rule
disjunction
document
rule
negation
document
rule
URL
pattern
predicate
document
rule
CSS
selector
predicate
A
document
rule
conjunction
is
a
struct
with
the
following
items
:
clauses
,
a
list
of
document
rule
predicates
A
document
rule
disjunction
is
a
struct
with
the
following
items
:
clauses
,
a
list
of
document
rule
predicates
A
document
rule
negation
is
a
struct
with
the
following
items
:
clause
,
a
document
rule
predicate
A
document
rule
URL
pattern
predicate
is
a
struct
with
the
following
items
:
patterns
,
a
list
of
URL
patterns
A
document
rule
CSS
selector
predicate
is
a
struct
with
the
following
items
:
selectors
,
a
list
majority
of
selectors
The
following
strings
are
valid
eagerness
strings
:
"
immediate
",
"
eager
",
"
moderate
",
"
conservative
".
A
valid
eagerness
string
a
is
less
eager
than
another
valid
eagerness
string
b
if
a
follows
b
in
the
above
list.
A
valid
eagerness
string
A
is
at
least
as
eager
as
another
valid
eagerness
string
B
if
A
is
not
less
eager
than
B
.
A
speculation
rules
tag
this
specification
is
either
an
ASCII
string
whose
code
points
are
all
in
the
range
U+0020
to
U+007E
inclusive,
or
null.
1.2.
The
script
element
Note
:
This
section
contains
modifications
to
the
corresponding
section
of
[HTML]
.
To
process
speculation
rules
consistently
with
the
existing
script
types,
we
make
the
following
changes:
Add
"
speculationrules
"
to
the
list
of
valid
values
for
a
script
element’s
type
.
Add
a
speculation
rule
set
being
upstreamed
to
the
list
of
valid
values
for
a
script
element’s
result
.
The
following
algorithms
are
updated
accordingly:
Prepare
the
script
element
:
HTML
Standard:
see
§ 1.3
Prepare
the
script
element
.
Execute
the
script
element
:
Add
the
following
case
to
the
switch
on
type
:
"
speculationrules
"
Assert
:
Never
reached.
We
should
consider
whether
we
also
want
to
make
this
execute
even
if
scripting
is
disabled.
We
should
also
incorporate
the
case
where
a
src
attribute
is
set.
We
could
fire
error
and
load
events
if
we
wanted
to.
In
supports(type)
method
steps,
before
Return
false.
add
the
following
step:
If
type
is
"
speculationrules
",
then
return
true.
The
following
steps
are
added
as
the
script
whatwg/html#11426
element’s
HTML
element
removing
steps
,
given
removedNode
and
oldParent
:
If
removedNode
’s
result
is
a
speculation
rule
set
,
then:
Let
document
be
removedNode
’s
node
document
.
Remove
it
from
document
’s
list
of
speculation
rule
sets
whatwg/html#11123
.
Set
removedNode
’s
already
started
flag
to
false.
Set
removedNode
’s
result
to
null.
Consider
speculation
for
document
.
This
means
that
the
rule
set
can
be
reparsed
if
the
script
is
reinserted.
The
following
steps
are
added
as
the
script
element’s
children
changed
steps
for
an
element
scriptElement
.
If
scriptElement
’s
result
is
a
speculation
rule
set
,
then:
Let
document
be
scriptElement
’s
node
document
.
Let
ruleSet
be
scriptElement
’s
result
.
Let
newResult
be
the
result
of
parsing
speculation
rules
given
scriptElement
’s
child
rendered
specification
text
content
,
document
,
and
document
’s
document
base
URL
can
currently
be
found
at
this
PR
preview
.
Set
scriptElement
’s
result
to
newResult
.
Replace
ruleSet
with
newResult
What
remains
in
document
’s
list
of
speculation
rule
sets
.
Consider
speculation
for
this
document
.
This
means
that
the
rule
set
is
reparsed
immediately
if
inline
changes
are
made.
1.3.
Prepare
the
script
element
Inside
the
prepare
the
script
element
algorithm
we
make
the
following
changes:
Insert
the
following
step
after
the
step
that
checks
for
an
ASCII
case-insensitive
match
for
the
string
"
module
":
If
the
script
block’s
type
string
is
an
ASCII
case-insensitive
match
for
the
string
"
speculationrules
",
then
set
el
’s
type
to
"
speculationrules
".
Insert
the
following
case
in
the
switch
on
type
within
the
step
which
begins
"If
el
does
not
have
a
src
content
attribute..."
"
speculationrules
"
Let
document
be
el
’s
node
document
Let
result
be
the
result
of
parsing
speculation
rules
given
source
text,
document
and
base
URL.
If
result
is
not
null,
append
it
to
document
’s
list
of
speculation
rule
sets
.
Mark
as
ready
el
given
result
.
Consider
speculation
for
document
.
Replace
"script"
argument
with
cspType
that
is
set
through
the
following
steps,
and
passed
to
Content
Security
Policy
3
§ 4.2.3
Should
element’s
inline
type
behavior
be
blocked
by
Content
Security
Policy?
algorithm.
Let
cspType
be
"script".
If
type
is
"
speculationrules
",
then
set
cspType
to
"
script
speculationrules
".
1.4.
The
`
Speculation-Rules
`
header
Note:
This
section
contains
modifications
some
additional
patches
to
[HTML]
.
The
`
Speculation-Rules
`
HTTP
response
header
is
a
structured
header
whose
value
must
be
a
list
whose
members
must
be
strings
support
prerendering,
which
are
valid
URL
strings
.
To
process
the
Speculation-Rules
header
given
a
document
document
and
a
response
response
:
Optionally,
return.
The
user
agent
could
ignore
this
header,
for
example,
if
it
upstreamed
version
does
not
intend
to
consider
speculation
for
document
.
Let
parsedList
be
the
result
of
getting
a
structured
field
value
given
`
Speculation-Rules
`
and
"
list
"
from
response
’s
header
list
.
If
parsedList
yet
cover.
Once
prefetch
is
null,
then
return.
Let
baseUrl
be
document
’s
also
upstreamed,
what
remains
in
this
document
base
URL
.
For
each
item
of
parsedList
:
If
item
is
not
a
string
,
then
continue
.
Let
parsedURL
be
the
result
of
parsing
item
with
baseUrl
.
If
parsedURL
is
failure,
then
continue
.
Let
pendingResource
be
a
pending
external
speculation
rule
resource
with
URL
parsedURL
and
controller
null.
Append
pendingResource
will
likely
migrate
to
document
’s
list
of
pending
external
speculation
rule
resources
.
Process
pending
external
speculation
rule
resources
given
document
.
In
create
and
initialize
a
Document
object
,
before
the
step
Return
document
.
add
the
following
step
Process
the
Speculation-Rules
header
given
document
and
navigationParams
’s
response
[PRERENDERING-REVAMPED]
.
1.5.
2.
External
speculation
rule
sets
Parsing
To
process
pending
external
speculation
rule
resources
given
a
document
document
:
Let
pendingResources
be
document
’s
list
of
pending
external
speculation
rule
resources
.
For
each
pendingResource
of
pendingResources
:
Optionally,
cancel
and
discard
pendingResource
given
document
,
then
continue
.
If
pendingResource
’s
controller
is
not
null,
then
continue
.
Optionally,
fetch
pendingResource
given
document
.
The
user
agent
schedules
the
fetch
of
external
speculation
rules
at
its
discretion.
That
is,
if
it
skips
the
fetch
during
this
call
of
process
pending
external
speculation
rule
resources
,
it
might
do
Extend
the
fetch
during
a
later
call.
To
fetch
a
pending
external
speculation
rule
resource
pendingResource
given
a
document
document
:
Let
pendingResources
be
document
’s
list
of
pending
external
speculation
rule
resources
.
Assert
:
pendingResources
contains
pendingResource
.
Assert
:
pendingResource
’s
controller
is
null.
Let
settingsObject
be
document
’s
relevant
settings
object
.
Let
requestURL
be
pendingResource
’s
URL
.
Let
request
be
a
new
request
whose
URL
is
requestURL
,
client
is
settingsObject
,
mode
is
"
cors
",
and
destination
is
"
speculationrules
".
Let
controller
be
the
result
of
fetching
given
request
with
processResponseConsumeBody
set
to
the
following
steps
given
response
response
and
null,
failure,
or
a
byte
sequence
body
:
Remove
struct
pendingResource
from
pendingResources
.
If
any
of
the
following
conditions
are
true,
abort
these
steps:
with
one
additional
item
:
-
body is null. body is failure. response ’s status is not an ok status . The result of extractingprerender rules , aMIME type from response ’s headerlistdoes not have an essence of " application/speculationrules+json ". Otherwise, let text be the result of UTF-8 decoding body . Let ruleSet be the resultofparsingspeculation rulesgiven text , document and response ’s URL ., initially empty
If
ruleSet
is
null,
abort
these
steps.
User
agents
are
encouraged
to
report
failures
of
Extend
the
previous
steps.
Append
ruleSet
to
document
’s
list
of
speculation
rule
sets
.
Set
pendingResource
’s
controller
to
controller
.
To
cancel
and
discard
a
pending
external
speculation
rule
resource
pendingResource
given
a
document
struct
document
:
Let
pendingResources
be
document
’s
list
of
pending
external
speculation
rule
resources
.
Assert
with
one
additional
item
:
pendingResources
contains
pendingResource
.
Let
controller
be
pendingResource
’s
controller
.
If
controller
is
not
null,
abort
controller
.
-
Remove pendingResource from pendingResources . 1.6. Parsing The general principle here is to allow the existence of directives which are not understood, but not to accept into the rule set a rule which the user agent does not fully understand. This reduces the risk of unintended activity by user agents which are unaware of most recently added directives which might limit the scope of a rule. To parse speculation rules giventarget navigable name hint , a stringinput , document document , and a URL baseURL , perform the following steps. They return a speculation rule setornull. Let parsed be the result of parsing a JSON string to an Infra value given input .nullIf parsed is not
-
IfRemove theparsedtypesToTreatAsPrefetch[" tag "] exists , then: Ifconstruct, and instead parse parsed [""]tagprerenderis notinto the prerender rules list, in anASCII string , then return null. Ifidentical manner to what is done for parsed [""]tagprefetchcontains any code points that are not inand therange U+0020 to U+007E inclusive, then return null.prefetch rules . -
Set tag toDiscard rules parsed[" tag "]. Iffrom parsed ["prefetch"]exists and is a list , then for each prefetchRule of parsed [" prefetch "]: If prefetchRule is not a map , then continue . Let rule beif theresult of parsing a speculation rule given prefetchRule , tag , document and baseURL . If rule is null, then continue . If rule ’starget navigable name hint is notnull, then continue . Append rule to result ’s prefetch rules . If parsed [" prerender "] exists and is a list , then for each prerenderRule of parsed [" prerender "]: If prerenderRule is not a map , then continue .null.Let rule
Implementations
will
still
be
the
result
of
parsing
a
speculation
rule
given
prerenderRule
,
tag
,
document
,
and
baseURL
.
If
rule
is
null,
then
continue
.
Append
rule
allowed
to
result
’s
treat
prerender
rules
candidates
as
prefetches,
per
the
modifications
in
§ 3
Processing
model
.
-
If requirement is not the string " anonymous-client-ip-when-cross-origin ", then return null. Append requirement to requirements .Let targetHint be null. -
If input ["
target_hint"] exists :-
If input ["
target_hint"] is not a valid navigable target name or keyword, then return null. Set targetHint to input [" target_hint "]. Let referrerPolicy be the empty string. If input [" referrer_policy "] exists:-
If input [" referrer_policy "] is notThe user agent may report areferrer policy , then return null. Set referrerPolicywarning toinput [" referrer_policy "]. Let eagerness be " immediate " if source is " list ", and " conservative " otherwise. If input [" eagerness "] exists : If input [" eagerness "] is not one ofthevalid eagerness strings , then return null. Set eagerness to input [" eagerness "]. Let noVarySearchHint beconsole indicating that thedefault URL search variance . If input [" expects_no_vary_search "] exists :supplied target hint was invalid. -
If input [" expects_no_vary_search "] is not a string , then returnReturn null.
-
-
Set
noVarySearchHinttargetHint tothe result of obtaining a URL search variance giveninput [""].expects_no_vary_searchtarget_hint
Let tags be an empty ordered set . If rulesetLevelTag is not null, then append rulesetLevelTag to tags . If input [" tag "] exists : If input [" tag "] is not an ASCII string , then return null. Append input [" tag "] to tags . -
If
tags
is
empty,
and
then
append
null
to
tags
.
Assert
:
tags
’s
size
is
either
1
or
2.
Return
updating
the
final
step
which
returns
a
speculation
rule
with
tags
tags
URLs
urls
predicate
predicate
requirements
requirements
to
include
setting
the
target
navigable
name
hint
targetHint
referrer
policy
referrerPolicy
eagerness
eagerness
No-Vary-Search
hint
noVarySearchHint
To
parse
a
document
rule
predicate
given
a
value
input
,
a
document
document
and
URL
baseURL
:
If
input
is
not
a
map
,
then
return
null.
If
input
does
not
contain
exactly
one
of
"
and
",
"
or
",
"
not
",
"
href_matches
"
and
"
selector_matches
",
then
return
null.
Otherwise,
let
predicateType
be
that
key.
This
makes
sure
it
is
unambiguous
what
type
of
predicate
is
being
used.
If
predicateType
is
"
and
"
or
"
or
",
then:
If
input
has
any
key
other
than
predicateType
,
then
return
null.
This,
and
other
similar
checks
below,
make
sure
that
unexpected
extra
options
cause
the
predicate
to
be
invalid.
Let
rawClauses
be
the
input
[
predicateType
].
If
rawClauses
is
not
a
list
,
then
return
null.
Let
clauses
be
an
empty
list
.
For
each
rawClause
of
rawClauses
:
Let
clause
be
the
result
of
parsing
a
document
rule
predicate
given
rawClause
,
document
and
baseURL
.
If
clause
is
null,
then
return
null.
Append
clause
to
clauses
.
If
predicateType
is
"
and
",
then
return
a
document
rule
conjunction
whose
clauses
is
clauses
.
If
predicateType
is
"
or
",
then
return
a
document
rule
disjunction
whose
clauses
is
clauses
.
If
predicateType
is
"
not
",
then:
If
input
has
any
key
other
than
"
not
",
then
return
null.
Let
rawClause
be
the
input
[
predicateType
].
Let
clause
be
the
result
of
parsing
a
document
rule
predicate
given
rawClause
,
document
and
baseURL
.
If
clause
is
null,
then
return
null.
Return
a
document
rule
negation
whose
clause
is
clause
.
If
predicateType
is
"
href_matches
":
If
input
has
any
key
other
than
"
href_matches
"
and
"
relative_to
",
then
return
null.
If
input
["
relative_to
"]
exists
,
then:
Let
relativeTo
be
input
["
relative_to
"].
If
relativeTo
is
neither
the
string
"
ruleset
"
nor
the
string
"
document
",
then
return
null.
If
relativeTo
is
"
document
",
set
baseURL
to
the
document
’s
document
base
URL
.
Let
rawPatterns
be
input
["
href_matches
"].
If
rawPatterns
is
not
a
list
,
then
set
rawPatterns
to
«
rawPatterns
».
Let
patterns
be
an
empty
list
.
For
each
rawPattern
of
rawPatterns
:
Let
pattern
be
the
result
of
building
a
URL
pattern
from
an
Infra
value
rawPattern
given
baseURL
.
If
this
step
throws,
catch
the
exception
and
return
null.
Append
pattern
to
patterns
.
Return
a
document
rule
URL
pattern
predicate
whose
patterns
is
patterns
.
If
predicateType
is
"
selector_matches
":
If
input
has
any
key
other
than
"
selector_matches
",
then
return
null.
Let
rawSelectors
be
input
["
selector_matches
"].
If
rawSelectors
is
not
a
list
,
then
set
rawSelectors
to
«
rawSelectors
».
Let
selectors
be
an
empty
list
.
For
each
rawSelector
of
selectors
:
If
rawSelector
is
not
a
string
,
then
return
null.
Parse
a
selector
from
rawSelector
.
If
the
result
is
failure,
then
return
null.
Otherwise,
let
selector
be
the
result.
Append
selector
to
selectors
.
Return
a
document
rule
CSS
selector
predicate
whose
selectors
is
selectors
targetHint
.
1.7.
3.
Processing
model
A
document
has
a
list
of
speculation
rule
sets
,
which
is
an
initially
empty
list
.
A
document
has
a
list
of
pending
external
speculation
rule
resources
,
which
is
an
initially
empty
list
of
pending
external
speculation
rule
resources
.
Periodically,
for
any
document
document
,
the
user
agent
may
queue
a
global
task
on
the
DOM
manipulation
task
source
with
document
’s
relevant
global
object
to
consider
speculation
for
document
.
The
user
agent
will
likely
do
when
resources
are
idle
and
available,
or
otherwise
the
circumstances
of
its
previous
decision
whether
to
start
a
speculation
could
have
changed.
The
user
agent
might
still
consider
speculation
when
there
are
rule
sets
that
have
not
been
loaded
yet
.
The
user
agent
may
also
queue
a
global
task
on
the
networking
task
source
with
document
’s
relevant
global
object
to
process
pending
external
speculation
rule
resources
given
document
.
A
speculative
load
candidate
is
a
struct
with
the
following
items
:
tags
,
an
ordered
set
of
speculation
rules
tags
URL
,
a
URL
referrer
policy
,
a
referrer
policy
eagerness
,
one
of
the
valid
eagerness
strings
No-Vary-Search
hint
,
a
URL
search
variance
A
prefetch
candidate
is
a
speculative
load
candidate
with
the
following
additional
item
:
anonymization
policy
,
a
prefetch
IP
anonymization
policy
A prerender candidate is a speculative load candidate with the following additional item :
-
target navigable name hint , a valid navigable target name or keyword or null
-
If document is not fully active , then return. It’s likely that we should also handle prerendered documents. Let prefetchCandidates be an empty list .Let prerenderCandidates be an empty list . -
For each ruleSet of document ’s
list ofspeculation rule sets :-
For each rule of ruleSet ’s
prefetchprerender rules :-
Let anonymizationPolicy be null. If rule ’s requirements contains " anonymous-client-ip-when-cross-origin ", set anonymizationPolicy to a cross-origin prefetch IP anonymization policy whose origin is document ’s origin .For each url of rule ’s URLs :-
Let referrerPolicy be the result of computing a speculative
actionload referrer policy given rule and null. -
Append a
prefetchnew prerender candidate with-
tags rule ’s tagsURL -
url
-
anonymization policy anonymizationPolicy referrer policy referrerPolicy eagerness rule ’s eagernessNo-Vary-Search hint -
rule ’s No-Vary-Search hint
to prefetchCandidates . If rule ’s predicate is not null, then: Let links be the result of finding matching links given document and rule ’s predicate . For each link of links : Let url be link ’s url . Let referrerPolicy be the result of computing a speculative action referrer policy given rule and link . Append a prefetch candidate with tags rule ’s tags URL url anonymization policy anonymizationPolicy referrer policy referrerPolicy - eagerness
-
rule ’s eagerness
-
No-Vary-Search hintreferrer policy -
rule ’s No-Vary-Search hint to prefetchCandidates . For each rule of ruleSet ’s prerender rules : For each url of rule ’s URLs : LetreferrerPolicybe the result of computing a speculative action referrer policy given rule and null.Append a prerender candidate with - tags
-
rule ’s tags
-
URL urltarget navigable name hint -
rule ’s target navigable name hint
referrer policy referrerPolicy eagerness rule ’s eagerness No-Vary-Search hint rule ’s No-Vary-Search hint
to prerenderCandidates .
-
-
-
If rule ’s predicate is not null, then:
-
Let links be the result of finding matching links given document and rule ’s predicate .
-
For each link of links :
-
Let
url be the link ’s url . Lettarget be rule ’s target navigable name hint . -
If target is null, set it to the result of getting an element’s target given link .
-
Let referrerPolicy be the result of computing a speculative
actionload referrer policy given rule and link . -
Append a prerender candidate with
-
tagsURL -
rulelink ’stagsurl -
URLNo-Vary-Search hint -
urlrule ’s No-Vary-Search hint -
target navigable name hinteagerness -
targetrule ’s eagerness - referrer policy
-
referrerPolicy
-
eagernesstags -
rule ’s
eagernesstags -
No-Vary-Searchtarget navigable name hint -
ruletarget’s No-Vary-Search hint
to prerenderCandidates .
-
-
-
-
-
-
Let speculativeLoadCandidates be the union of prefetchCandidates and prerenderCandidates .
For
each
prefetchRecord
of
document
’s
Update
subsequent
steps
for
canceling
not-still-being-speculated
prefetch
records
:
If
prefetchRecord
’s
label
is
not
"
speculation-rules
",
then
continue
.
Assert
:
to
operate
on
prefetchRecord
speculativeLoadCandidates
’s
state
is
not
"
canceled
".
instead
of
prefetchCandidates
.
If
prefetchRecord
is
not
still
being
speculated
given
speculativeLoadCandidates
,
then
cancel
and
discard
Replace
the
step
which
performs
the
actual
prefetching
by
looping
over
prefetchRecord
prefetchCandidates
given
document
.
with
the
following:
-
For each
prefetchCandidatecandidate ofprefetchCandidatesspeculativeLoadCandidates :-
The user agent may run the following steps:
-
Let
prefetchAndPrerenderCandidatestagCandidates bean empty list . Extend prefetchAndPrerenderCandidates withprefetchCandidatesspeculativeLoadCandidates . -
ExtendIfprefetchAndPrerenderCandidatescandidatewithis a prerender candidate , then set tagCandidates to prerenderCandidates . -
Let tagsToSend be the result of collecting tags for matching speculative load candidates given
prefetchCandidatecandidate andprefetchAndPrerenderCandidatestagCandidates . -
Let prefetchRecord be a new prefetch record with
-
tagssource -
tagsToSend"speculation rules" - URL
-
prefetchCandidatecandidate ’s URL -
anonymization policyNo-Vary-Search hint -
prefetchCandidatecandidate ’sanonymization policyNo-Vary-Search hint - referrer policy
-
prefetchCandidatecandidate ’s referrer policy -
No-Vary-Search hinttags -
prefetchCandidatetagsToSend’s No-Vary-Search hintlabel " speculation-rules "
-
-
Prefetch givenIfdocumentcandidateandis a prefetch candidate , then set prefetchRecord. For each’s anonymization policy toprerenderCandidatecandidateof prerenderCandidates :’s anonymization policy . -
TheIf candidate is a prerender candidate , then the user agent may run the following steps:-
Let tagsToSend be the result of collecting tags for matching speculative load candidates given prerenderCandidate and prerenderCandidates . LetSet prefetchRecordbe a new prefetch record with tags tagsToSend URL prerenderCandidate’sURL anonymization policy null referrer policy prerenderCandidate ’s referrer policy No-Vary-Search hint prerenderCandidate ’s No-Vary-Search hint label " speculation-rules "prerendering traversable to "to be created" -
Set prefetchRecord ’s prerendering target navigable name hint to
prerenderCandidatecandidate ’s target navigable name hint . -
Start a referrer-initiated
prerenderingnavigational prerender given document and prefetchRecord .
When deciding whether to execute the "may" steps above that enact from among prefetchCandidates and prerenderCandidates , user agents should consider their eagerness , in accordance with the following: " immediate " The author believes this is very likely to be worthwhile, and might also expect it to require significant lead time to complete. User agents should usually enact the candidate as soon as practical, subject only to considerations such as user preferences, device conditions, and resource limits. " eager " User agents should enact the candidate on even a slight suggestion that the user may navigate to this URL in the future. For instance, the user might have moved the cursor toward a link or hovered it, even momentarily, or paused scrolling when the link is one of the more prominent ones in the viewport. The author is seeking to capture as many navigations as possible, as early as possible. " moderate " User agents should enact the candidate if user behavior suggests the user may navigate to this URL in the near future. For instance, the user might have scrolled a link into the viewport and moved the cursor over it for some time. The author is seeking a balance between " eager " and " conservative ". " conservative " User agents should enact the candidate only when the user is very likely to navigate to this URL at any moment. For instance, the user might have begun to interact with a link. The author is seeking to capture some of the benefits of speculative loading with a fairly small tradeoff of resources. -
-
If
a user agent chooses to enact a candidate A , then the user agent should also enact other candidates which are redundant with A and whose eagerness is at least as eager as A ’s eagerness . The first-encountered candidate will win, andtheothers will be ignored by the prefetch or prerender algorithms. This gives deterministic behavior for authors. The following speculation rules generate two redundant candidates: Auser agentwhich follows the above algorithm will enact both candidates. The second call to the prefetch algorithm will end up doing nothing, and so the request will be made with the default referrer policy, instead of using "no-referrer" . However, the collect tags for matching speculative load candidates algorithm will collect tags from both candidates, so the ` Sec-Speculation-Tags ` header will be set to "a", "b" . This indicates to server operators that either rule could have caused the speculative load. Notwithstanding the above, user agents should prioritize user preferences (express and implied, such as a low-data-usage mode) over eagerness expressed by the author. A user agent’s heuristics for enacting non-eager candidates could incorporate a No-Vary-Search hint . For example, a user hovering over a link whose URL and a candidate’s URL are equivalent modulo search variance given the candidate’s No-Vary-Search hint could indicate to the user agent that enacting it would be useful. We should also cancel speculated prerenders. To collect tags for matching speculative load candidates , given a speculative load candidate candidateUnderConsideration and a list of speculative load candidates allCandidates : Let tags be an empty ordered set . For each candidate of allCandidates : If candidate is not redundant with candidateUnderConsideration , then continue . If candidate ’s eagerness is less eager than candidateUnderConsideration ’s eagerness , then continue . Append candidate ’s tags to tags . Sort in ascending order tags , with tagA being less than tagB if tagA is null, or if tagA is code unit less than tagB . Return tags . The intuition here is that the tag for candidate B will be included in a speculative load triggered by candidate A , if and only if, were candidate A no longer present, B would trigger a speculative load that would be used in the same circumstances as A . 1.8. Document rule predicate matching A document rule predicate predicate matches an Element el implementing the HTMLHyperlinkElementUtils mixin if the following steps return true: If predicate is a document rule conjunction , then: For each clause of predicate ’s clauses : If clause doesdid notmatch el , return false. Return true. If predicate is a document rule disjunction , then: For each clause of predicate ’s clauses : If clause matches el , return true. Return false. If predicate is a document rule negation , then: If predicate ’s clause matches el , return false. Return true. If predicate is a document rule URL pattern predicate , then: Let href berun theresult of running el ’s href getter steps. For each pattern of predicate ’s patterns : Performprevious step, then start amatchreferrer-initiated navigational prefetch givenpattern and href . If the result is not null, return true. Return false. If predicate is adocumentrule CSS selector predicate , then: For each selector of predicate ’s selectors : Match selector against el with the scoping root set to el ’s root . If the result is true, return true. During this step, user agents must apply the same privacy restrictions to the :visited pseudo-class as they would to other selector matching logic that could be observed by authors (e.g., querySelector(selectors) ). This is important to prevent this from opening an avenue for attackers to gather information about a user’s browsing history, e.g., by using a selector such as :root:has(.sensitive-site:visited) .report-sensitive-site . See the Privacy Considerations section. Return false. Assert : This step is not reached. 2. Content Security Policy Inline script use is restricted by [CSP] , but there are cases where a developer doesn’t want to permit general inline scripts, but wants to permit inline speculation rules. So, we make the following change that extends [CSP] to support a new source keyword for inline speculation rules. 2.1. Directives In Content Security Policy 3 § 2.3 Directives , we define several associated algorithms, and an inline check algorithm needs a patch to define how to choose the type argument. An inline check , which takes an Element , a type string, a policy, and a source string as arguments, and is executed during Content Security Policy 3 § 4.2.3 Should element’s inline type behavior be blocked by Content Security Policy? and during Content Security Policy 3 § 4.2.4 Should navigation request of type be blocked by Content Security Policy? for javascript: requests. This algorithm returns " Allowed " unless otherwise specified. The type string is set to " script speculationrules " if the Element is HTMLScriptElement and the type attribute is " speculationrules ", or set to " script attribute " for JavaScript event handlers. Otherwise, it is set to " script ". 2.2. Source Lists In Content Security Policy 3 § 2.3.1 Source Lists , we change the following definition to have a new source, inline-speculation-rules . " / "" / "" / " 2.3. Should element’s inline type behavior be blocked by Content Security Policy? Also, we make a following change for a note in Content Security Policy 3 § 4.2.3 Should element’s inline type behavior be blocked by Content Security Policy? . Note: The valid values for type are " script ", " script attribute ", " script speculationrules ", " style ", and " style attribute ". 2.4. script-src Also we make the following change for Content Security Policy 3 § 6.1.10 script-src . Inline script blocks MUST pass through Content Security Policy 3 § 4.2.3 Should element’s inline type behavior be blocked by Content Security Policy? . Their behavior will be blocked unless every policy allows inline script, either implicitly by not specifying a script-src (or default-src ) directive, or explicitly, by specifying " unsafe-inline ", a nonce-source or a hash-source that matches the inline block , or specifying " inline-speculation-rules " on the type attribute being " speculationrules " . 2.5. Does a source list allow all inline behavior for type? The algorithm needs a patch to handle the " script speculationrules " type. For each expression of list: If expression matches the nonce-source or hash-source grammar, return " Does Not Allow ". If type is " script ", " script attribute " or " navigation " and expression matches the keyword-source " 'strict-dynamic' ", return " Does Not Allow ". Note: 'strict-dynamic' only applies to scripts, not other resource types. Usage is explained in more detail in Content Security Policy 3 § 8.2 Usage of "'strict-dynamic'" . If type is " script speculationrules " and expression matches the keyword-source " 'inline-speculation-rules' ", set allow all inline to true . If expression is an ASCII case-insensitive match for the keyword-source " 'unsafe-inline' ", set allow all inline to true . 2.6. Does element match source list for type and source? The algorithm needs patches to handle the " script speculationrules " type at the step 2 and 5. If type is " script ", " script speculationrules ", or " style ", and Content Security Policy 3 § 6.7.3.1 Is element nonceable? returns " Nonceable " when executed upon element : For each expressionof list : If expression matches the nonce-source grammar,andelement has a nonce attribute whose value is expression ’s base64-value part, return " Matches ".prefetchRecord .
-
Note: Nonces only apply to inline script and inline style , not to attributes of either element or to javascript: navigations. Let unsafe-hashes flag be false . For each expression of list : If expression is an ASCII case-insensitive match for the keyword-source " 'unsafe-hashes' ", set unsafe-hashes flag to true . Break out of the loop. -