Skip to content

Commit 8043429

Browse files
Support preload scripts per user context (#862)
* Allow applying preload scripts to opened contexts * rename * Update index.bs Co-authored-by: Julian Descottes <[email protected]> * Update index.bs Co-authored-by: Julian Descottes <[email protected]> * fix navigable check * Update index.bs * add quotes * or semantic * add validation --------- Co-authored-by: Julian Descottes <[email protected]>
1 parent 374e7ba commit 8043429

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

index.bs

+40-9
Original file line numberDiff line numberDiff line change
@@ -7797,10 +7797,12 @@ before any author-defined script have run.
77977797
TODO: Extend this to scripts in other kinds of realms.
77987798

77997799
A [=BiDi session=] has a <dfn>preload script map</dfn> which is a [=/map=] in
7800-
which the keys are [[!RFC9562|UUID]]s, and the values are [=structs=] with an <a
7801-
for=struct>item</a> named <code>function declaration</code>, which is a string,
7802-
<code>arguments</code>, <code>contexts</code>, which is a list or null, and an item named <code>sandbox</code> which is a string
7803-
or null.
7800+
which the keys are [[!RFC9562|UUID]]s, and the values are [=structs=] with
7801+
an [=struct/item=] named <code>function declaration</code>, which is a string,
7802+
an [=struct/item=] named <code>arguments</code>, which is a list,
7803+
an [=struct/item=] named <code>contexts</code>, which is a list or null,
7804+
an [=struct/item=] named <code>sandbox</code>, which is a string or null,
7805+
and an [=struct/item=] named <code>user contexts</code>, which is a [=/set=].
78047806

78057807
Note: If executing a [=preload script=] fails, either due to a syntax error, or
78067808
a runtime exception, an [[ECMAScript]] exception is reported in the realm in
@@ -7814,16 +7816,26 @@ To <dfn export>run WebDriver BiDi preload scripts</dfn> given |environment setti
78147816

78157817
1. Let |navigable| be |document|'s [=/navigable=].
78167818

7819+
1. Let |user context| be |navigable|'s [=associated user context=].
7820+
7821+
1. Let |user context id| be |user context|'s [=user context id=].
7822+
78177823
1. For each |session| in [=active BiDi sessions=]:
78187824

78197825
1. For each |preload script| in |session|'s [=preload script map=]'s
78207826
[=values=]:
78217827

7828+
1. If |preload script|'s <code>user contexts</code>'s [=set/size=] is not zero:
7829+
7830+
1. If |preload script|'s <code>user contexts</code> does not [=list/contain=] |user context id|,
7831+
[=continue=].
7832+
78227833
1. If |preload script|'s <code>contexts</code> is not null:
78237834

78247835
1. Let |navigable id| be |navigable|’s [=navigable/top-level traversable=]'s id.
78257836

7826-
1. If |preload script|'s <code>contexts</code> does not [=list/contains|contain=] |navigable id|, continue.
7837+
1. If |preload script|'s <code>contexts</code> does not [=list/contain=] |navigable id|,
7838+
[=continue=].
78277839

78287840
1. If |preload script|'s <code>sandbox</code> is not null, let |realm| be [=get
78297841
or create a sandbox realm=] with |preload script|'s <code>sandbox</code> and
@@ -9754,6 +9766,7 @@ script=].
97549766
functionDeclaration: text,
97559767
? arguments: [*script.ChannelValue],
97569768
? contexts: [+browsingContext.BrowsingContext],
9769+
? userContexts: [+browser.UserContext],
97579770
? sandbox: text
97589771
}
97599772
</pre>
@@ -9771,12 +9784,18 @@ script=].
97719784
<div algorithm="remote end steps for script.addPreloadScript">
97729785
The [=remote end steps=] given |session| and |command parameters| are:
97739786

9787+
1. If |command parameters| [=map/contains=] "<code>userContexts</code>"
9788+
and |command parameters| [=map/contains=] "<code>contexts</code>",
9789+
return [=error=] with [=error code=] [=invalid argument=].
9790+
97749791
1. Let |function declaration| be the <code>functionDeclaration</code> field of |command
97759792
parameters|.
97769793

97779794
1. Let |arguments| be the <code>arguments</code> field of |command
97789795
parameters| if present, or an empty [=/list=] otherwise.
97799796

9797+
1. Let |user contexts| to be a [=/set=].
9798+
97809799
1. Let |navigables| be null.
97819800

97829801
1. If the <code>contexts</code> field of |command parameters| is present:
@@ -9791,17 +9810,29 @@ The [=remote end steps=] given |session| and |command parameters| are:
97919810

97929811
1. Append |navigable| to |navigables|.
97939812

9813+
1. Otherwise, if |command parameters| [=map/contains=] <code>userContexts</code>:
9814+
9815+
1. Set |user contexts| to [=set/create|create a set=] with |command parameters|["<code>userContexts</code>"].
9816+
9817+
1. For each |user context id| of |user contexts|:
9818+
9819+
1. Set |user context| to [=get user context=] with |user context id|.
9820+
9821+
1. If |user context| is null, return [=error=] with [=error code=] [=no such user context=].
9822+
97949823
1. Let |sandbox| be the value of the "<code>sandbox</code>" field in |command
97959824
parameters|, if present, or null otherwise.
97969825

97979826
1. Let |script| be the string representation of a [[!RFC9562|UUID]].
97989827

97999828
1. Let |preload script map| be |session|'s [=preload script map=].
98009829

9801-
1. Set |preload script map|[|script|] to a struct with <code>function
9802-
declaration</code> |function declaration|, <code>arguments</code>
9803-
|arguments|, <code>contexts</code>
9804-
|navigables|, and <code>sandbox</code> |sandbox|.
9830+
1. Set |preload script map|[|script|] to a struct with
9831+
<code>function declaration</code> |function declaration|,
9832+
<code>arguments</code> |arguments|,
9833+
<code>contexts</code> |navigables|,
9834+
<code>sandbox</code> |sandbox|, and
9835+
<code>user contexts</code> |user contexts|.
98059836

98069837
1. Return a new [=/map=] matching the <code>script.AddPreloadScriptResult</code> with the
98079838
<code>script</code> field set to |script|.

0 commit comments

Comments
 (0)