Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add network.setCacheBehavior command #721

Merged
merged 10 commits into from
Jul 3, 2024
147 changes: 145 additions & 2 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,10 +1435,27 @@ To <dfn>cleanup the session</dfn> given |session|:

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

1. If [=active sessions=] is [=list/empty=], [=cleanup remote end state=].

1. Perform any implementation-specific cleanup steps.

</div>

<div algorithm>
To <dfn>cleanup remote end state</dfn>.

1. [=map/Clear=] the [=before request sent map=].

1. Set the [=default cache behavior=] to "<code>default</code>".

1. [=map/Clear=] the [=navigable cache behavior map=].

1. 1. Perform implementation-defined steps to enable any
implementation-specific resource caches that are usually enabled in the
current [=remote end=] configuration.

</div>

<div algorithm>
To <dfn>update the event map</dfn>, given
|session|, |requested event names|, |browsing contexts|, and |enabled|:
Expand Down Expand Up @@ -2324,6 +2341,9 @@ BrowsingContextEvent = (
A [=remote end=] has a <dfn>device pixel ratio overrides</dfn> which is a weak map
between [=navigables=] and device pixel ratio overrides. It is initially empty.

Note: this map is not cleared when the final session ends i.e. device pixel
ratio overrides outlive any WebDriver session.

### Types ### {#module-browsingcontext-types}

#### The browsingContext.BrowsingContext Type #### {#type-browsingContext-Browsingcontext}
Expand Down Expand Up @@ -4689,7 +4709,8 @@ NetworkCommand = (
network.ContinueWithAuth //
network.FailRequest //
network.ProvideResponse //
network.RemoveIntercept
network.RemoveIntercept //
network.SetCacheBehavior
)

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

A [=remote end=] has a <dfn>default cache behavior</dfn> which is a string. It is
initially "<code>default</code>".

A [=remote end=] has a <dfn>navigable cache behavior map</dfn> which is a weak
map between [=/top-level traversables=] and strings representing cache
behavior. It is initially empty.

### Network Intercepts ### {#network-intercepts}

A <dfn>network intercept</dfn> is a mechanism to allow remote ends to intercept
Expand Down Expand Up @@ -4972,7 +5000,6 @@ request in addition to the context.
<div algorithm>
To <dfn>process a network event</dfn> given |session|, |event|, and |request|:


1. Let |request data| be the result of [=get the request data=] with |request|.

<!-- TODO: update this to "[=request/navigation id=] once the fetch parts land-->
Expand Down Expand Up @@ -6554,6 +6581,122 @@ requests will be affected.

</div>

#### The network.setCacheBehavior Command #### {#command-network-setCacheBehavior}

The <dfn export for=commands>network.setCacheBehavior</dfn> command configures
the network cache behavior for certain requests.

<dl>
<dt>Command Type</dt>
<dd>
<pre class="cddl remote-cddl">
network.SetCacheBehavior = (
method: "network.setCacheBehavior",
params: network.SetCacheBehaviorParameters
)

network.SetCacheBehaviorParameters = {
cacheBehavior: "default" / "bypass",
? contexts: [+browsingContext.BrowsingContext]
}
</pre>
</dd>
<dt>Return Type</dt>
<dd>
<pre class="cddl">
EmptyResult
</pre>
</dd>
</dl>

<div algorithm>
The <dfn export>WebDriver BiDi cache behavior</dfn> steps given |request| are:

1. Let |context| be null.

1. If |request|'s [=request/window=] is an [=environment settings object=]:

1. Let |environment settings| be |request|'s [=request/window=]

1. If there is a [=/browsing context=] whose [=active window=] is |environment
settings|' [=environment settings object/global object=], set |context| to
the [=top-level browsing context=] for that browsing context.

1. If |context| is not null and [=navigable cache behavior map=] [=set/contains=]
|context|, return [=navigable cache behavior map=][|context|].

1. Return [=default cache behavior=].

</div>

<div algorithm="remote end steps for network.setCacheBehavior">
The [=remote end steps=] given <var ignore>session</var> and |command parameters| are:

1. Let |behavior| be |command parameters|["<code>cacheBehavior</code>"].

1. If |command parameters| does not [=map/contain=] "<code>contexts</code>":

1. Set the [=default cache behavior=] to |behavior|.

1. [=map/Clear=] [=navigable cache behavior map=].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: the global cache behavior erases all the specific browsing context's cache behavior previously set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that's the same as the way that enabling an event globally works; if you subscribe for a specific context and then subscribe for all contexts and then unsubscribe for all contexts you don't end up with the event subscription for the original set of contexts.


1. Switch on the value of behavior:
<dl>
<dt>"<code>bypass</code>"
whimboo marked this conversation as resolved.
Show resolved Hide resolved
<dd>Perform implementation-defined steps to disable any
implementation-specific resource caches.
<dt>"<code>default</code>"
<dd>Perform implementation-defined steps to enable any
implementation-specific resource caches that are usually enabled in the
current [=remote end=] configuration.
</dl>

1. Return [=success=] with data null.

1. Let |contexts| be an empty [=/set=].

1. For each |context id| of |command parameters|["<code>contexts</code>"]:

1. Let |context| be the result of [=trying=] to [=get a browsing context=]
jgraham marked this conversation as resolved.
Show resolved Hide resolved
with |context id|.

1. If |context| is not a [=top-level browsing context=], return [=error=]
with [=error code=] [=invalid argument=].

1. [=list/Append=] |context| to |contexts|.

1. For each |context| in |contexts|:
whimboo marked this conversation as resolved.
Show resolved Hide resolved

1. If [=navigable cache behavior map=] [=map/contains=] |context|, and
[=navigable cache behavior map=][|context|] is equal to |behavior| then
continue.

1. Switch on the value of behavior:
<dl>
<dt>"<code>bypass</code>"
<dd>Perform implementation-defined steps to disable any implementation-specific
resource caches for network requests originating from any browsing
context for which |context| is the [=top-level browsing context=].
<dt>"<code>default</code>"
<dd>Perform implementation-defined steps to enable any
implementation-specific resource caches that are usually enabled in the
current [=remote end=] configuration for network requests
originating from any browsing context for which |context| is the
[=top-level browsing context=].
whimboo marked this conversation as resolved.
Show resolved Hide resolved
</dl>

1. If |behavior| is equal to [=default cache behavior=]:

1. If [=navigable cache behavior map=] [=map/contains=] |context|,
[=map/remove=] [=navigable cache behavior map=][|context|].

1. Otherwise:

1. Set [=navigable cache behavior map=][|context|] to |behavior|.

1. Return [=success=] with data null.

</div>

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

Expand Down
Loading