diff --git a/index.bs b/index.bs
index 252ec840..71bd6594 100644
--- a/index.bs
+++ b/index.bs
@@ -7524,8 +7524,9 @@ TODO: Extend this to scripts in other kinds of realms.
A [=BiDi session=] has a preload script map which is a [=/map=] in
which the keys are [[!RFC9562|UUID]]s, and the values are [=structs=] with an item named function declaration
, which is a string,
-arguments
, contexts
, which is a list or null, and an item named sandbox
which is a string
-or null.
+arguments
, contexts
, which is a list or null,
+an item named sandbox
, which is a string or null,
+and an item named applyToOpeningContexts
, which is a boolean.
Note: If executing a [=preload script=] fails, either due to a syntax error, or
a runtime exception, an [[ECMAScript]] exception is reported in the realm in
@@ -7546,9 +7547,19 @@ To run WebDriver BiDi preload scripts given |environment setti
1. If |preload script|'s contexts
is not null:
- 1. Let |navigable id| be |navigable|’s [=navigable/top-level traversable=]'s id.
+ 1. Let |is script run allowed| be false.
- 1. If |preload script|'s contexts
does not [=list/contains|contain=] |navigable id|, continue.
+ 1. While |navigable| is not null:
+
+ 1. Let |navigable id| be |navigable|’s [=navigable/top-level traversable=]'s id.
+
+ 1. If |preload script|'s contexts
[=list/contains=] |navigable id|,
+ set |is script run allowed| to true and break.
+
+ 1. If |preload script|'s applyToOpeningContexts
is true,
+ set |navigable| to |navigable|'s [=original opener=]. Otherwise, break.
+
+ 1. If |is script run allowed| is false, continue;
1. If |preload script|'s sandbox
is not null, let |realm| be [=get
or create a sandbox realm=] with |preload script|'s sandbox
and
@@ -9479,6 +9490,7 @@ script=].
functionDeclaration: text,
? arguments: [*script.ChannelValue],
? contexts: [+browsingContext.BrowsingContext],
+ ? applyToOpeningContexts: bool .default false,
? sandbox: text
}
@@ -9519,6 +9531,9 @@ The [=remote end steps=] given |session| and |command parameters| are:
1. Let |sandbox| be the value of the "sandbox
" field in |command
parameters|, if present, or null otherwise.
+1. Let |applyToOpeningContexts| be true if |command parameters|["applyToOpeningContexts
"]
+ is true, and false otherwise.
+
1. Let |script| be the string representation of a [[!RFC9562|UUID]].
1. Let |preload script map| be |session|'s [=preload script map=].
@@ -9526,7 +9541,8 @@ The [=remote end steps=] given |session| and |command parameters| are:
1. Set |preload script map|[|script|] to a struct with function
declaration
|function declaration|, arguments
|arguments|, contexts
- |navigables|, and sandbox
|sandbox|.
+ |navigables|, sandbox
|sandbox|, and
+ applyToOpeningContexts
|applyToOpeningContexts|.
1. Return a new [=/map=] matching the script.AddPreloadScriptResult
with the
script
field set to |script|.