Skip to content

Commit a46d71b

Browse files
jgrahamLightning00BladewhimbooOrKoN
authored
Add network.setCacheBehavior command (#721)
Allow setting the cache behavior so that network caches can be disabled either globally or for specific browsing contexts. This can be useful in testing situations as caches represent global shared state that can leak between tests, and may prevent certain issues from reproducing (e.g. race conditions that depend on network). When the cache behavior is updated globally this removes any per-context settings. --------- Co-authored-by: Nikolay Vitkov <[email protected]> Co-authored-by: Henrik Skupin <[email protected]> Co-authored-by: Alex Rudenko <[email protected]>
1 parent 0c366b0 commit a46d71b

File tree

1 file changed

+161
-2
lines changed

1 file changed

+161
-2
lines changed

index.bs

+161-2
Original file line numberDiff line numberDiff line change
@@ -1435,10 +1435,27 @@ To <dfn>cleanup the session</dfn> given |session|:
14351435

14361436
1. [=Close the WebSocket connections=] with |session|.
14371437

1438+
1. If [=active sessions=] is [=list/empty=], [=cleanup remote end state=].
1439+
14381440
1. Perform any implementation-specific cleanup steps.
14391441

14401442
</div>
14411443

1444+
<div algorithm>
1445+
To <dfn>cleanup remote end state</dfn>.
1446+
1447+
1. [=map/Clear=] the [=before request sent map=].
1448+
1449+
1. Set the [=default cache behavior=] to "<code>default</code>".
1450+
1451+
1. [=map/Clear=] the [=navigable cache behavior map=].
1452+
1453+
1. Perform implementation-defined steps to enable any
1454+
implementation-specific resource caches that are usually enabled in the
1455+
current [=remote end=] configuration.
1456+
1457+
</div>
1458+
14421459
<div algorithm>
14431460
To <dfn>update the event map</dfn>, given
14441461
|session|, |requested event names|, |browsing contexts|, and |enabled|:
@@ -2333,6 +2350,9 @@ BrowsingContextEvent = (
23332350
A [=remote end=] has a <dfn>device pixel ratio overrides</dfn> which is a weak map
23342351
between [=navigables=] and device pixel ratio overrides. It is initially empty.
23352352

2353+
Note: this map is not cleared when the final session ends i.e. device pixel
2354+
ratio overrides outlive any WebDriver session.
2355+
23362356
### Types ### {#module-browsingcontext-types}
23372357

23382358
#### The browsingContext.BrowsingContext Type #### {#type-browsingContext-Browsingcontext}
@@ -4230,6 +4250,10 @@ the <dfn export>WebDriver BiDi navigable created</dfn> steps given
42304250

42314251
1. Let |context| be |navigable|'s [=active browsing context=].
42324252

4253+
1. If the [=context cache behavior=] with |context| is "<code>bypass</code>",
4254+
then perform implementation-defined steps to disable any implementation-specific
4255+
resource caches for network requests originating from |context|.
4256+
42334257
1. Set |context|'s [=original opener=] to |opener navigable|'s [=active browsing context=],
42344258
if |opener navigable| is provided.
42354259

@@ -4698,7 +4722,8 @@ NetworkCommand = (
46984722
network.ContinueWithAuth //
46994723
network.FailRequest //
47004724
network.ProvideResponse //
4701-
network.RemoveIntercept
4725+
network.RemoveIntercept //
4726+
network.SetCacheBehavior
47024727
)
47034728

47044729
</pre>
@@ -4725,6 +4750,13 @@ A [=remote end=] has a <dfn>before request sent map</dfn> which is initially an
47254750
empty map. It's used to track the network events for which a
47264751
<code>network.beforeRequestSent</code> event has already been sent.
47274752

4753+
A [=remote end=] has a <dfn>default cache behavior</dfn> which is a string. It is
4754+
initially "<code>default</code>".
4755+
4756+
A [=remote end=] has a <dfn>navigable cache behavior map</dfn> which is a weak
4757+
map between [=/top-level traversables=] and strings representing cache
4758+
behavior. It is initially empty.
4759+
47284760
### Network Intercepts ### {#network-intercepts}
47294761

47304762
A <dfn>network intercept</dfn> is a mechanism to allow remote ends to intercept
@@ -4981,7 +5013,6 @@ request in addition to the context.
49815013
<div algorithm>
49825014
To <dfn>process a network event</dfn> given |session|, |event|, and |request|:
49835015

4984-
49855016
1. Let |request data| be the result of [=get the request data=] with |request|.
49865017

49875018
<!-- TODO: update this to "[=request/navigation id=] once the fetch parts land-->
@@ -6563,6 +6594,134 @@ requests will be affected.
65636594

65646595
</div>
65656596

6597+
#### The network.setCacheBehavior Command #### {#command-network-setCacheBehavior}
6598+
6599+
The <dfn export for=commands>network.setCacheBehavior</dfn> command configures
6600+
the network cache behavior for certain requests.
6601+
6602+
<dl>
6603+
<dt>Command Type</dt>
6604+
<dd>
6605+
<pre class="cddl remote-cddl">
6606+
network.SetCacheBehavior = (
6607+
method: "network.setCacheBehavior",
6608+
params: network.SetCacheBehaviorParameters
6609+
)
6610+
6611+
network.SetCacheBehaviorParameters = {
6612+
cacheBehavior: "default" / "bypass",
6613+
? contexts: [+browsingContext.BrowsingContext]
6614+
}
6615+
</pre>
6616+
</dd>
6617+
<dt>Return Type</dt>
6618+
<dd>
6619+
<pre class="cddl">
6620+
EmptyResult
6621+
</pre>
6622+
</dd>
6623+
</dl>
6624+
6625+
<div algorithm>
6626+
The <dfn export>WebDriver BiDi cache behavior</dfn> steps given |request| are:
6627+
6628+
1. Let |context| be null.
6629+
6630+
1. If |request|'s [=request/window=] is an [=environment settings object=]:
6631+
6632+
1. Let |environment settings| be |request|'s [=request/window=]
6633+
6634+
1. If there is a [=/browsing context=] whose [=active window=] is |environment
6635+
settings|' [=environment settings object/global object=], set |context| to
6636+
the [=top-level browsing context=] for that browsing context.
6637+
6638+
1. If |context| is not null and [=navigable cache behavior map=] [=set/contains=]
6639+
|context|, return [=navigable cache behavior map=][|context|].
6640+
6641+
1. Return [=default cache behavior=].
6642+
6643+
</div>
6644+
6645+
<div algorithm>
6646+
The <dfn>context cache behavior</dfn> steps given |context| are:
6647+
6648+
1. Set |top-level context| to the [=top-level browsing context=] for |context|.
6649+
6650+
1. If [=navigable cache behavior map=] [=map/contains=] |top-level context|, return
6651+
[=navigable cache behavior map=][|top-level context|].
6652+
6653+
1. Return [=default cache behavior=].
6654+
6655+
</div>
6656+
6657+
<div algorithm="remote end steps for network.setCacheBehavior">
6658+
The [=remote end steps=] given <var ignore>session</var> and |command parameters| are:
6659+
6660+
1. Let |behavior| be |command parameters|["<code>cacheBehavior</code>"].
6661+
6662+
1. If |command parameters| does not [=map/contain=] "<code>contexts</code>":
6663+
6664+
1. Set the [=default cache behavior=] to |behavior|.
6665+
6666+
1. [=map/Clear=] [=navigable cache behavior map=].
6667+
6668+
1. Switch on the value of behavior:
6669+
<dl>
6670+
<dt>"<code>bypass</code>"
6671+
<dd>Perform implementation-defined steps to disable any
6672+
implementation-specific resource caches.
6673+
<dt>"<code>default</code>"
6674+
<dd>Perform implementation-defined steps to enable any
6675+
implementation-specific resource caches that are usually enabled in the
6676+
current [=remote end=] configuration.
6677+
</dl>
6678+
6679+
1. Return [=success=] with data null.
6680+
6681+
1. Let |contexts| be an empty [=/set=].
6682+
6683+
1. For each |context id| of |command parameters|["<code>contexts</code>"]:
6684+
6685+
1. Let |context| be the result of [=trying=] to [=get a browsing context=]
6686+
with |context id|.
6687+
6688+
1. If |context| is not a [=top-level browsing context=], return [=error=]
6689+
with [=error code=] [=invalid argument=].
6690+
6691+
1. [=list/Append=] |context| to |contexts|.
6692+
6693+
1. For each |context| in |contexts|:
6694+
6695+
1. If [=navigable cache behavior map=] [=map/contains=] |context|, and
6696+
[=navigable cache behavior map=][|context|] is equal to |behavior| then
6697+
continue.
6698+
6699+
1. Switch on the value of behavior:
6700+
<dl>
6701+
<dt>"<code>bypass</code>"
6702+
<dd>Perform implementation-defined steps to disable any implementation-specific
6703+
resource caches for network requests originating from any browsing
6704+
context for which |context| is the [=top-level browsing context=].
6705+
<dt>"<code>default</code>"
6706+
<dd>Perform implementation-defined steps to enable any
6707+
implementation-specific resource caches that are usually enabled in the
6708+
current [=remote end=] configuration for network requests
6709+
originating from any browsing context for which |context| is the
6710+
[=top-level browsing context=].
6711+
</dl>
6712+
6713+
1. If |behavior| is equal to [=default cache behavior=]:
6714+
6715+
1. If [=navigable cache behavior map=] [=map/contains=] |context|,
6716+
[=map/remove=] [=navigable cache behavior map=][|context|].
6717+
6718+
1. Otherwise:
6719+
6720+
1. Set [=navigable cache behavior map=][|context|] to |behavior|.
6721+
6722+
1. Return [=success=] with data null.
6723+
6724+
</div>
65666725

65676726
### Events ### {#module-network-event}
65686727

0 commit comments

Comments
 (0)