From 233c9dbc9ab7293b81db8fe298f72d0b83ae77d5 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 29 May 2024 11:00:59 +0100 Subject: [PATCH 01/10] Add network.setCacheMode command This currently only allows setting the request cache mode to 'no-store' which bypasses the cache entirely. If we have future use cases for setting different cache modes, this appraoch would be extensible to those use cases. --- index.bs | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index e016de98..0e6777c1 100644 --- a/index.bs +++ b/index.bs @@ -4689,7 +4689,8 @@ NetworkCommand = ( network.ContinueWithAuth // network.FailRequest // network.ProvideResponse // - network.RemoveIntercept + network.RemoveIntercept // + network.SetCacheMode // ) @@ -4716,6 +4717,13 @@ A [=remote end=] has a before request sent map which is initially an empty map. It's used to track the network events for which a network.beforeRequestSent event has already been sent. +A [=remote end=] has a default cache mode override which is null or a +string. It is initially null. + +A [=remote end=] has a cache mode override map which is initially an +empty weak map. It's used to track the cache mode to use for requests from +specific browsing contexts. + ### Network Intercepts ### {#network-intercepts} A network intercept is a mechanism to allow remote ends to intercept @@ -4972,7 +4980,6 @@ request in addition to the context.
To process a network event given |session|, |event|, and |request|: - 1. Let |request data| be the result of [=get the request data=] with |request|. @@ -6554,6 +6561,90 @@ requests will be affected.
+#### The network.setCacheMode Command #### {#command-network-setCacheMode} + +The network.removeSetCacheMode command overrides +the network cache behaviour for certain requests. + +
+
Command Type
+
+
+      network.SetCacheMode = (
+        method: "network.setCacheMode",
+        params: network.SetCacheModeParameters
+      )
+
+      network.SetCacheModeParameters = {
+        mode: "no-store" / null,
+        ? contexts: [browsingContext.BrowsingContext]
+      }
+    
+
+
Return Type
+
+
+      EmptyResult
+    
+
+
+ +
+The WebDriver BiDi update request cache mode 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 context. + +1. If |context| is not null: + + 1. If [=cache mode override map=] [=map/contains=] |context|, set + |request|'s [=request/cache mode=] to [=cache mode override + map=][|context|] and return. + +1. If [=default cache mode override=] is not null, set + |request|'s [=request/cache mode=] to [=default cache mode override=]. + +
+ +
+The [=remote end steps=] given session and |command parameters| are: + +1. Let |mode| be |command parameters|["mode"]. + +1. If |command parameters| does not [=map/contain=] "contexts", set + the [=default cache mode override=] to |mode| and return [=success=] with + data null. + +1. Let |contexts| be an empty [=/list=]. + +1. For each |context id| of |command parameters|["contexts"]: + + 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 |mode| is null and [=cache mode override map=] [=map/contains=] + |context| [=map/remove=] |context| from [=cache mode override map=]. + + 1. Otherwise, set [=cache mode override map=][|context|] to |mode|. + +1. Return [=success=] with data null. + +
### Events ### {#module-network-event} From b8494a66bed4fa8e38f5f6e34c12244e96591f43 Mon Sep 17 00:00:00 2001 From: jgraham Date: Wed, 29 May 2024 13:52:49 +0100 Subject: [PATCH 02/10] Update index.bs Co-authored-by: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 0e6777c1..862faf6a 100644 --- a/index.bs +++ b/index.bs @@ -6577,7 +6577,7 @@ the network cache behaviour for certain requests. network.SetCacheModeParameters = { mode: "no-store" / null, - ? contexts: [browsingContext.BrowsingContext] + ? contexts: [+browsingContext.BrowsingContext] } From 29dd853332fbbb961fc3c47bb687a58f5382acf8 Mon Sep 17 00:00:00 2001 From: jgraham Date: Thu, 30 May 2024 12:24:05 +0100 Subject: [PATCH 03/10] Apply suggestions from code review Co-authored-by: Henrik Skupin --- index.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 862faf6a..add97994 100644 --- a/index.bs +++ b/index.bs @@ -6563,7 +6563,7 @@ requests will be affected. #### The network.setCacheMode Command #### {#command-network-setCacheMode} -The network.removeSetCacheMode command overrides +The network.setCacheMode command overrides the network cache behaviour for certain requests.
@@ -6606,11 +6606,11 @@ The WebDriver BiDi update request cache mode steps given 1. If |context| is not null: 1. If [=cache mode override map=] [=map/contains=] |context|, set - |request|'s [=request/cache mode=] to [=cache mode override + |request|'s [=request/cache mode=] to [=cache mode override map=][|context|] and return. 1. If [=default cache mode override=] is not null, set - |request|'s [=request/cache mode=] to [=default cache mode override=]. + |request|'s [=request/cache mode=] to [=default cache mode override=]. From d6213b3756e419c99d6a1cd9190f6d07b1311c7a Mon Sep 17 00:00:00 2001 From: James Graham Date: Tue, 18 Jun 2024 10:07:27 +0100 Subject: [PATCH 04/10] Replace setCacheMode with setCacheBypass This just takes a single true/false value for whether to bypass the cache. --- index.bs | 84 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/index.bs b/index.bs index add97994..4cdd816a 100644 --- a/index.bs +++ b/index.bs @@ -4690,7 +4690,7 @@ NetworkCommand = ( network.FailRequest // network.ProvideResponse // network.RemoveIntercept // - network.SetCacheMode // + network.SetCacheBypass // ) @@ -4717,12 +4717,12 @@ A [=remote end=] has a before request sent map which is initially an empty map. It's used to track the network events for which a network.beforeRequestSent event has already been sent. -A [=remote end=] has a default cache mode override which is null or a -string. It is initially null. +A [=remote end=] has a default cache bypass which is a boolean. It is +initially false. -A [=remote end=] has a cache mode override map which is initially an -empty weak map. It's used to track the cache mode to use for requests from -specific browsing contexts. +A [=remote end=] has a navigable cache bypass set 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} @@ -6561,22 +6561,22 @@ requests will be affected. -#### The network.setCacheMode Command #### {#command-network-setCacheMode} +#### The network.setCacheBypass Command #### {#command-network-setCacheBypass} -The network.setCacheMode command overrides -the network cache behaviour for certain requests. +The network.setCacheBypass command bypasses the +network cache for certain requests.
Command Type
-      network.SetCacheMode = (
-        method: "network.setCacheMode",
-        params: network.SetCacheModeParameters
+      network.SetCacheBypass = (
+        method: "network.setCacheBypass",
+        params: network.SetCacheBypassParameters
       )
 
-      network.SetCacheModeParameters = {
-        mode: "no-store" / null,
+      network.SetCacheBypassParameters = {
+        bypass: bool,
         ? contexts: [+browsingContext.BrowsingContext]
       }
     
@@ -6590,8 +6590,7 @@ the network cache behaviour for certain requests.
-The WebDriver BiDi update request cache mode steps given -|request| are: +The WebDriver BiDi bypass cache steps given |request| are: 1. Let |context| be null. @@ -6601,46 +6600,55 @@ The WebDriver BiDi update request cache mode steps given 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 context. + the [=top-level browsing context=] for that browsing context. -1. If |context| is not null: +1. If |context| is not null and [=navigable cache bypass set=] [=set/contains=] + |context|, return true. - 1. If [=cache mode override map=] [=map/contains=] |context|, set - |request|'s [=request/cache mode=] to [=cache mode override - map=][|context|] and return. - -1. If [=default cache mode override=] is not null, set - |request|'s [=request/cache mode=] to [=default cache mode override=]. +1. Return [=default cache bypass=].
-
+
The [=remote end steps=] given session and |command parameters| are: -1. Let |mode| be |command parameters|["mode"]. +1. Let |bypass| be |command parameters|["bypass"]. -1. If |command parameters| does not [=map/contain=] "contexts", set - the [=default cache mode override=] to |mode| and return [=success=] with - data null. +1. If |command parameters| does not [=map/contain=] "contexts": -1. Let |contexts| be an empty [=/list=]. + 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|["contexts"]: - 1. Let |context| be the result of [=trying=] to [=get a browsing context=] - with |context id|. + 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. If |context| is not a [=top-level browsing context=], return [=error=] + with [=error code=] [=invalid argument=]. - 1. [=list/Append=] |context| to |contexts|. + 1. [=list/Append=] |context| to |contexts|. 1. For each |context| in |contexts|: - 1. If |mode| is null and [=cache mode override map=] [=map/contains=] - |context| [=map/remove=] |context| from [=cache mode override map=]. + 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, set [=cache mode override map=][|context|] to |mode|. + 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|. 1. Return [=success=] with data null. From fb9e9ee1f108072b2acf500c4c1fdfcdc1dd02bd Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 24 Jun 2024 17:49:14 +0100 Subject: [PATCH 05/10] Define cleanup of remote end state --- index.bs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.bs b/index.bs index 4cdd816a..cc131aab 100644 --- a/index.bs +++ b/index.bs @@ -1435,10 +1435,23 @@ To cleanup the session 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.
+
+To cleanup remote end state. + +1. [=map/Clear=] the [=before request sent map=]. + +1. Set the [=default cache bypass=] to false. + +1. [=set/Empty=] the [=navigable cache bypass set=]. + +
+
To update the event map, given |session|, |requested event names|, |browsing contexts|, and |enabled|: @@ -2324,6 +2337,9 @@ BrowsingContextEvent = ( A [=remote end=] has a device pixel ratio overrides 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} From e35f5e750e20ac4d32d1ef005ae26ad7fa08e286 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 3 Jul 2024 10:18:53 +0100 Subject: [PATCH 06/10] Replace setCacheBypass with setCacheBehavior Also correctly specify how to handle mixed per-navigable and global settings, so that: * Updating the global setting always overrides any per-navigable settings. * Per-navigable settings are only stored where they're different to the global setting. This should match the behavior of subscribing to events. --- index.bs | 101 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 38 deletions(-) diff --git a/index.bs b/index.bs index cc131aab..3c65b448 100644 --- a/index.bs +++ b/index.bs @@ -1446,9 +1446,9 @@ To cleanup remote end state. 1. [=map/Clear=] the [=before request sent map=]. -1. Set the [=default cache bypass=] to false. +1. Set the [=default cache behavior=] to "default". -1. [=set/Empty=] the [=navigable cache bypass set=]. +1. [=map/Clear=] the [=navigable cache behavior map=].
@@ -4733,12 +4733,12 @@ A [=remote end=] has a before request sent map which is initially an empty map. It's used to track the network events for which a network.beforeRequestSent event has already been sent. -A [=remote end=] has a default cache bypass which is a boolean. It is -initially false. +A [=remote end=] has a default cache behavior which is a string. It is +initially "default". -A [=remote end=] has a navigable cache bypass set which is initially an -empty weak set. It's used to track the [=/top-level traversables=] in which -network caches are bypassed. +A [=remote end=] has a navigable cache behavior map which is a weak +map between [=/top-level traversables=] and strings representing cache +behavior. It is initially empty. ### Network Intercepts ### {#network-intercepts} @@ -6577,22 +6577,22 @@ requests will be affected.
-#### The network.setCacheBypass Command #### {#command-network-setCacheBypass} +#### The network.setCacheBehavior Command #### {#command-network-setCacheBehavior} -The network.setCacheBypass command bypasses the -network cache for certain requests. +The network.setCacheBehavior command configures +the network cache behavior for certain requests.
Command Type
-      network.SetCacheBypass = (
-        method: "network.setCacheBypass",
-        params: network.SetCacheBypassParameters
+      network.SetCacheBehavior = (
+        method: "network.setCacheBehavior",
+        params: network.SetCacheBehaviorParameters
       )
 
-      network.SetCacheBypassParameters = {
-        bypass: bool,
+      network.SetCacheBehaviorParameters = {
+        cacheBehavior: "default" / "bypass",
         ? contexts: [+browsingContext.BrowsingContext]
       }
     
@@ -6606,7 +6606,7 @@ network cache for certain requests.
-The WebDriver BiDi bypass cache steps given |request| are: +The WebDriver BiDi cache behavior steps given |request| are: 1. Let |context| be null. @@ -6618,53 +6618,78 @@ The WebDriver BiDi bypass cache steps given |request| are: 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. If |context| is not null and [=navigable cache behavior map=] [=set/contains=] + |context|, return [=navigable cache behavior map=][|context|]. -1. Return [=default cache bypass=]. +1. Return [=default cache behavior=].
-
+
The [=remote end steps=] given session and |command parameters| are: -1. Let |bypass| be |command parameters|["bypass"]. +1. Let |behavior| be |command parameters|["cacheBehavior"]. 1. If |command parameters| does not [=map/contain=] "contexts": - 1. Set the [=default cache bypass=] to |bypass|. + 1. Set the [=default cache behavior=] to |behavior|. - 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. [=map/Clear=] [=navigable cache behavior map=]. - 1. Return [=success=] with data null. + 1. Switch on the value of behavior: +
+
"bypass" +
Perform implementation-defined steps to disable any + implementation-specific resource caches for all future + network requests. +
"default" +
Perform implementation-defined steps to enable any + implementation-specific resource caches that are usually enabled in the + current [=remote end=] configuration for all future network requests. +
+ + 1. Return [=success=] with data null. 1. Let |contexts| be an empty [=/set=]. 1. For each |context id| of |command parameters|["contexts"]: - 1. Let |context| be the result of [=trying=] to [=get a browsing context=] + 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. If |context| is not a [=top-level browsing context=], return [=error=] + with [=error code=] [=invalid argument=]. - 1. [=list/Append=] |context| to |contexts|. + 1. [=list/Append=] |context| to |contexts|. 1. For each |context| in |contexts|: - 1. If |bypass| is true: + 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: +
+
"bypass" +
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=]. +
"default" +
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=]. +
+ + 1. If |behavior| is equal to [=default cache behavior=]: - 1. [=set/append=] |context| to [=navigable cache bypass set=]. + 1. If [=navigable cache behavior map=] [=map/contains=] |context|, + [=map/remove=] [=navigable cache behavior map=][|context|]. - 1. Perform implementation-defined steps to disable any implementation-specific - resource caches for network requests originating from |context|. + 1. Otherwise: - 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|. + 1. Set [=navigable cache behavior map=][|context|] to |behavior|. 1. Return [=success=] with data null. From 3aa68c58bb6454c977d788ce985c0ca85c98ed22 Mon Sep 17 00:00:00 2001 From: jgraham Date: Wed, 3 Jul 2024 11:44:36 +0100 Subject: [PATCH 07/10] Update index.bs Co-authored-by: Alex Rudenko --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 3c65b448..460b6332 100644 --- a/index.bs +++ b/index.bs @@ -4706,7 +4706,7 @@ NetworkCommand = ( network.FailRequest // network.ProvideResponse // network.RemoveIntercept // - network.SetCacheBypass // + network.SetCacheBehavior // ) From e39132f5e291fe3f3326816667d2c955f9058676 Mon Sep 17 00:00:00 2001 From: jgraham Date: Wed, 3 Jul 2024 14:54:42 +0100 Subject: [PATCH 08/10] Update index.bs Co-authored-by: Henrik Skupin --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 460b6332..6fa2da26 100644 --- a/index.bs +++ b/index.bs @@ -4706,7 +4706,7 @@ NetworkCommand = ( network.FailRequest // network.ProvideResponse // network.RemoveIntercept // - network.SetCacheBehavior // + network.SetCacheBehavior ) From d30d8647794d3cbc40d4573f70915bdd93b58099 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 3 Jul 2024 15:45:55 +0100 Subject: [PATCH 09/10] Remove 'for all future network requests' --- index.bs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 6fa2da26..5ec53d6a 100644 --- a/index.bs +++ b/index.bs @@ -1450,6 +1450,10 @@ To cleanup remote end state. 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. +
@@ -6640,12 +6644,11 @@ The [=remote end steps=] given session and |command parameters
"bypass"
Perform implementation-defined steps to disable any - implementation-specific resource caches for all future - network requests. + implementation-specific resource caches.
"default"
Perform implementation-defined steps to enable any implementation-specific resource caches that are usually enabled in the - current [=remote end=] configuration for all future network requests. + current [=remote end=] configuration.
1. Return [=success=] with data null. From 331e65f92772a7f8c0777f211babfbe789f766b5 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 3 Jul 2024 19:08:07 +0100 Subject: [PATCH 10/10] Explictly handle network cache settings during context creation. --- index.bs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 5ec53d6a..64b8b2b0 100644 --- a/index.bs +++ b/index.bs @@ -1450,7 +1450,7 @@ To cleanup remote end state. 1. [=map/Clear=] the [=navigable cache behavior map=]. -1. 1. Perform implementation-defined steps to enable any +1. Perform implementation-defined steps to enable any implementation-specific resource caches that are usually enabled in the current [=remote end=] configuration. @@ -4241,6 +4241,10 @@ the WebDriver BiDi navigable created steps given 1. Let |context| be |navigable|'s [=active browsing context=]. +1. If the [=context cache behavior=] with |context| is "bypass", + then perform implementation-defined steps to disable any implementation-specific + resource caches for network requests originating from |context|. + 1. Set |context|'s [=original opener=] to |opener navigable|'s [=active browsing context=], if |opener navigable| is provided. @@ -6629,6 +6633,18 @@ The WebDriver BiDi cache behavior steps given |request| are:
+
+The context cache behavior steps given |context| are: + +1. Set |top-level context| to the [=top-level browsing context=] for |context|. + +1. If [=navigable cache behavior map=] [=map/contains=] |top-level context|, return + [=navigable cache behavior map=][|top-level context|]. + +1. Return [=default cache behavior=]. + +
+
The [=remote end steps=] given session and |command parameters| are: