@@ -289,16 +289,6 @@ ErrorResponse = {
289
289
Extensible
290
290
}
291
291
292
- ErrorCode = {
293
- "invalid argument" /
294
- "no such alert" /
295
- "no such frame" /
296
- "session not created" /
297
- "unknown command" /
298
- "unknown error" /
299
- "unsupported operation"
300
- }
301
-
302
292
ResultData = (
303
293
EmptyResult //
304
294
SessionResult //
@@ -424,6 +414,28 @@ The <dfn export for=command>set of all command names</dfn> is a set containing
424
414
all the defined [=command names=] , including any belonging to [=extension
425
415
modules=] .
426
416
417
+ ## Errors ## {#errors}
418
+
419
+ WebDriver BiDi extends the set of [=error codes=] from [[WEBDRIVER|WebDriver]]
420
+ with the following additional codes:
421
+
422
+ <dl>
423
+ <dt> <dfn>No such script</dfn>
424
+ <dd> Tried to remove an unknown [=preload script=] .
425
+ </dl>
426
+
427
+ <pre class="cddl local-cddl">
428
+ ErrorCode = ("invalid argument" /
429
+ "invalid session id" /
430
+ "no such alert" /
431
+ "no such frame" /
432
+ "no such script" /
433
+ "session not created" /
434
+ "unknown command" /
435
+ "unknown error" /
436
+ "unsupported operation")
437
+ </pre>
438
+
427
439
## Events ## {#events}
428
440
429
441
An <dfn export>event</dfn> is a notification, sent by the [=remote
@@ -3792,17 +3804,20 @@ relating to script realms and execution.
3792
3804
3793
3805
<pre class="cddl remote-cddl">
3794
3806
ScriptCommand = (
3807
+ script.AddPreloadScriptCommand //
3795
3808
script.CallFunction //
3796
3809
script.Disown //
3797
3810
script.Evaluate //
3798
3811
script.GetRealms
3812
+ script.RemovePreloadScriptCommand
3799
3813
)
3800
3814
</pre>
3801
3815
3802
3816
[=local end definition=]
3803
3817
3804
3818
<pre class="cddl local-cddl">
3805
3819
ScriptResult = (
3820
+ script.AddPreloadScriptResult //
3806
3821
script.EvaluateResult //
3807
3822
script.GetRealmsResult
3808
3823
)
@@ -3813,6 +3828,55 @@ ScriptEvent = (
3813
3828
)
3814
3829
</pre>
3815
3830
3831
+ ### Preload Scripts ### {#preload-scripts}
3832
+
3833
+ A <dfn>Preload script</dfn> is one which runs on creation of a new {{Window}} ,
3834
+ before any author-defined script have run.
3835
+
3836
+ TODO: Extend this to scripts in other kinds of realms.
3837
+
3838
+ A [=BiDi session=] has a <dfn>preload script map</dfn> which is a map in which the
3839
+ keys are [[!RFC4122|UUID]] s, and the values are [=structs=] with an <a
3840
+ for=struct> item</a> named <code> expression</code> , which is a string, and an
3841
+ item named <code> sandbox</code> which is a string or null.
3842
+
3843
+ <div algorithm>
3844
+ To <dfn export>run WebDriver BiDi preload scripts</dfn> given |environment settings|:
3845
+
3846
+ 1. Let |document| be |environment settings|' [=relevant global object=]' s
3847
+ <a>associated <code>Document</code></a> .
3848
+
3849
+ 1. Let |browsing context| be |document|'s [=/browsing context=] .
3850
+
3851
+ 1. For each |session| in [=active BiDi sessions=] :
3852
+
3853
+ 1. For each |preload script| in |session|'s [=preload script map=]' s
3854
+ [=values=] :
3855
+
3856
+ 1. If |preload script|'s <code> sandbox</code> is not null, let |realm| be [=get
3857
+ or create a sandbox realm=] with |preload script|'s <code> sandbox</code> and
3858
+ |browsing context|. Otherwise let |realm| be |environment settings|'
3859
+ [=realm execution context=] 's Realm component.
3860
+
3861
+ 1. Let |source| be |preload script|'s <code> expression</code> .
3862
+
3863
+ 1. Let |options| be the [=default classic script fetch options=] .
3864
+
3865
+ 1. Let |base URL| be the [=API base URL=] of |environment settings|.
3866
+
3867
+ 1. Let |script| be the result of [=create a classic script=] with |source|,
3868
+ |environment settings|, |base URL|, and |options|.
3869
+
3870
+ 1. [=Prepare to run script=] with |environment settings|.
3871
+
3872
+ 1. Let |evaluation status| be [=ScriptEvaluation=] (|script|'s record).
3873
+
3874
+ 1. If |evaluation status| is an [=abrupt completion=] , then [=report the
3875
+ exception=] given by |evaluation status|.\[[Value]] for |script|.
3876
+
3877
+ 1. [=Clean up after running script=] with |environment settings|.
3878
+
3879
+ </div>
3816
3880
3817
3881
### Types ### {#module-script-types}
3818
3882
@@ -3867,6 +3931,17 @@ To <dfn>get exception details</dfn> given a |realm|, a [=completion record=]
3867
3931
3868
3932
</div>
3869
3933
3934
+ #### The script.PreloadScript type #### {#type-script-PreloadScript}
3935
+
3936
+ [=Remote end definition=]
3937
+
3938
+ <pre class="cddl remote-cddl local-cddl">
3939
+ script.PreloadScript = text;
3940
+ </pre>
3941
+
3942
+ The <code> script.PreloadScript</code> type represents a handle to a script that will run
3943
+ on realm creation.
3944
+
3870
3945
#### The script.Realm type #### {#type-script-Realm}
3871
3946
3872
3947
[=Remote end definition=] and [=local end definition=]
@@ -4323,6 +4398,57 @@ Issue: This has the wrong error code
4323
4398
4324
4399
### Commands ### {#module-script-commands}
4325
4400
4401
+ #### The script.addPreloadScript Command #### {#command-script-addPreloadScript}
4402
+
4403
+ The <dfn export for=commands>script.addPreloadScript</dfn> command adds a [=preload
4404
+ script=] .
4405
+
4406
+ <dl>
4407
+ <dt> Command Type</dt>
4408
+ <dd>
4409
+ <pre class="cddl remote-cddl">
4410
+ script.AddPreloadScriptCommand = {
4411
+ method: "script.addPreloadScript",
4412
+ params: script.AddPreloadScriptParameters
4413
+ }
4414
+
4415
+ script.AddPreloadScriptParameters = {
4416
+ expression: text;
4417
+ ?sandbox: text
4418
+ }
4419
+ </pre>
4420
+ </dd>
4421
+ <dt> Return Type</dt>
4422
+ <dd>
4423
+ <pre class="cddl local-cddl">
4424
+ script.AddPreloadScriptResult = {
4425
+ script: script.PreloadScript
4426
+ }
4427
+ </pre>
4428
+ </dd>
4429
+ </dl>
4430
+
4431
+ <div algorithm="remote end steps for script.addPreloadScript">
4432
+ The [=remote end steps=] given |session| and |command parameters| are:
4433
+
4434
+ 1. Let |expression| be the <code> expression</code> field of |command
4435
+ parameters|.
4436
+
4437
+ 1. Let |script| be the string representation of a [[!RFC4122|UUID]] .
4438
+
4439
+ 1. Let |sandbox| be the value of the "<code> sandbox</code> " field in |command
4440
+ parameters|, if present, or null otherwise.
4441
+
4442
+ 1. Let |preload script map| be |session|'s [=preload script map=] .
4443
+
4444
+ 1. Set |preload script map|[|script|] to a struct with <code> expression</code>
4445
+ |expression| and <code> sandbox</code> |sandbox|.
4446
+
4447
+ 1. Return a new map matching the <code> script.AddPreloadScriptResult</code> with the
4448
+ <code> script</code> field set to |script|.
4449
+
4450
+ </div>
4451
+
4326
4452
#### The script.disown Command #### {#command-script-disown}
4327
4453
4328
4454
The <dfn export for=commands>script.disown</dfn> command disowns the given handles.
@@ -4714,6 +4840,51 @@ Issue: We might want to have a more sophisticated filter system than just a
4714
4840
4715
4841
</div>
4716
4842
4843
+ #### The script.removePreloadScript Command #### {#command-script-removePreloadScript}
4844
+
4845
+ The <dfn export for=commands>script.removePreloadScript</dfn> command removes a
4846
+ [=preload script=] .
4847
+
4848
+ <dl>
4849
+ <dt> Command Type</dt>
4850
+ <dd>
4851
+ <pre class="cddl remote-cddl">
4852
+ script.RemovePreloadScriptCommand = {
4853
+ method: "script.removePreloadScript",
4854
+ params: script.RemovePreloadScriptParameters
4855
+ }
4856
+
4857
+ script.RemovePreloadScriptParameters = {
4858
+ script: script.PreloadScript
4859
+ }
4860
+ </pre>
4861
+ </dd>
4862
+ <dt> Return Type</dt>
4863
+ <dd>
4864
+ <pre class="cddl">
4865
+ EmptyResult
4866
+ </pre>
4867
+ </dd>
4868
+ </dl>
4869
+
4870
+ <div algorithm="remote end steps for script.removePreloadScript">
4871
+ The [=remote end steps=] given |session| and |command parameters| are:
4872
+
4873
+ 1. Let |script| be the value of the "<code> script</code> " field in |command
4874
+ parameters|.
4875
+
4876
+ 1. Let |preload script map| be |session|'s [=preload script map=] .
4877
+
4878
+ 1. If |preload script map| does not <a for=map>contain</a> |script|, return
4879
+ [=error=] with [=error code=] [=no such script=] .
4880
+
4881
+ 1. <a for=set>Remove</a> |script| from |preload script map|.
4882
+
4883
+ 1. Return null
4884
+
4885
+ </div>
4886
+
4887
+
4717
4888
### Events ### {#module-script-events}
4718
4889
4719
4890
#### The script.realmCreated Event #### {#event-script-realmCreated}
0 commit comments