Skip to content
119 changes: 117 additions & 2 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,10 +1435,23 @@ 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 bypass=] to false.

1. [=set/Empty=] the [=navigable cache bypass set=].

</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 +2337,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 +4705,8 @@ NetworkCommand = (
network.ContinueWithAuth //
network.FailRequest //
network.ProvideResponse //
network.RemoveIntercept
network.RemoveIntercept //
network.SetCacheBypass //
)

</pre>
Expand All @@ -4716,6 +4733,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 bypass</dfn> which is a boolean. It is
initially false.

A [=remote end=] has a <dfn>navigable cache bypass set</dfn> which is initially an
empty weak set. It's used to track the [=/top-level traversables=] in which
network caches are bypassed.

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

A <dfn>network intercept</dfn> is a mechanism to allow remote ends to intercept
Expand Down Expand Up @@ -4972,7 +4996,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 +6577,98 @@ requests will be affected.

</div>

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

The <dfn export for=commands>network.setCacheBypass</dfn> command bypasses the
network cache for certain requests.

<dl>
<dt>Command Type</dt>
<dd>
<pre class="cddl remote-cddl">
network.SetCacheBypass = (
method: "network.setCacheBypass",
params: network.SetCacheBypassParameters
)

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

<div algorithm>
The <dfn export>WebDriver BiDi bypass cache</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 bypass set=] [=set/contains=]
|context|, return true.

1. Return [=default cache bypass=].

</div>

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

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

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

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

1. If |bypass| is true, perform implementation-defined steps to disable any
implementation-specific resource caches for network requests. Otherwise
re-enable any implementation-specific resource caches for all contexts.

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=]
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|:

1. If |bypass| is true:

1. [=set/append=] |context| to [=navigable cache bypass set=].

1. Perform implementation-defined steps to disable any implementation-specific
resource caches for network requests originating from |context|.

1. Otherwise, if [=navigable cache bypass set=] [=set/contains=]
|context|, [=set/remove=] |context| from [=navigable cache bypass set=] and
re-enable any implementation-specific resource caches for network requests
originating from |context|.
Copy link
Contributor

Choose a reason for hiding this comment

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

So if I understand correctly, default cache bypass and navigable cache bypass set are used to handle regular request caches, and then implementation-specific resource caches covers things such as Memory cache, image cache etc...

One scenario might be a bit buggy here:

  • send setCacheBypass({ bypass: true }), this will set the default cache bypass to true, and will disable implementation specific caches for all contexts.
  • send setCacheBypass({ bypass: true, contexts: ["some-context-id"] }), it will add "some-context-id" to the set and disable (again?) the implementation-specific resource caches for this context.
  • send setCacheBypass({ bypass: false, contexts: ["some-context-id"] }), it will remove "some-context-id" from the set and enable the implementation-specific resource caches for this context.

So at this point, we will have the default cache bypass to true, but for the "some-context-id" context, we will have re-enabled the resource-caches. It seems like a weird setup. Maybe we should throw if you try to setCacheBypass({ bypass: true, contexts }) with contexts != null when default cache bypass is already true? And when we call setCacheBypass({ bypass: true }), maybe we should empty the set? Otherwise it sounds like the global configuration can clash with the context-specific configuration?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if there is a global default state it should apply to newly created contexts as well. Currently, it seems like only the spec-defined caches would be affected but not the implementation-defined caches? Note that for Puppeteer there is currently no use case for bypassing the cache for the whole browser so we can also exclude the global default state for now.


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

</div>

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

Expand Down