From cde8750516b5a5b4e56dfc9962fc7691d1f775b4 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 20 Feb 2025 20:05:50 +0100 Subject: [PATCH] Only use network.SetBodyCollectorConfiguration, introduce max size per navigable, check navigation id to evict responses --- index.bs | 377 ++++++++++++++++++++++--------------------------------- 1 file changed, 153 insertions(+), 224 deletions(-) diff --git a/index.bs b/index.bs index b0ef8b3c..05b4009e 100644 --- a/index.bs +++ b/index.bs @@ -621,9 +621,6 @@ with the following additional codes:
no such history entry
Tried to havigate to an unknown [=session history entry=]. -
no such collector -
Tried to remove an unknown [=network body collector=]. -
no such intercept
Tried to remove an unknown [=network intercept=]. @@ -670,7 +667,6 @@ ErrorCode = "invalid argument" / "no such frame" / "no such handle" / "no such history entry" / - "no such collector" / "no such intercept" / "no such node" / "no such request" / @@ -4945,7 +4941,7 @@ the WebDriver BiDi navigable destroyed steps given |navigable| if that is not null, or an empty [=/set=] otherwise. 1. For each |session| in [=active BiDi sessions=], [=delete collected response bodies=] - with |session| and |navigable|. + with |session|, |navigable| and null. 1. For each |session| in the [=set of sessions for which an event is enabled=] given "browsingContext.contextDestroyed" and |related navigables|: @@ -5276,7 +5272,7 @@ given |navigable| and |navigation status|: 1. [=Resume=] with "navigation committed", |navigation id|, and |navigation status|. 1. For each |session| in [=active BiDi sessions=], [=delete collected response bodies=] - with |session| and |navigable|. + with |session|, |navigable| and |navigation id|. 1. For each |session| in the [=set of sessions for which an event is enabled=] given "browsingContext.navigationCommitted" and |related navigables|: @@ -5448,7 +5444,6 @@ relating to network requests. NetworkCommand = ( network.AddIntercept // - network.AddBodyCollector // network.ContinueRequest // network.ContinueResponse // network.ContinueWithAuth // @@ -5456,7 +5451,6 @@ NetworkCommand = ( network.GetResponseBody // network.ProvideResponse // network.RemoveIntercept // - network.RemoveBodyCollector // network.SetBodyCollectorConfiguration // network.SetCacheBehavior ) @@ -5654,76 +5648,67 @@ To update the response given |session|, |command| and |command parame ### Network Responses ### {#network-responses} -A network body collector is a mechanism to allow remote ends to collect -the content of network request and response bodies. +A network body collector configuration is a struct which defines how +a navigable should collect the content of network request and response bodies. -A [=BiDi session=] has a network body collector map which is a [=/map=] between -network body collector id and a [=struct=] with fields url patterns, -contexts and user contexts that define the properties -of active network body collectors. It is initially empty. +A [=BiDi session=] has navigable network collector configurations which is a weak map between [=navigables=] and [=network body collector configuration=]. It is initially empty. -A [=BiDi session=] has a response map which is a [=/map=] between -request id and a [=struct=] with fields context and response -that define the collected network response bodies for the current session. It is initially empty. +A [=BiDi session=] has user context network collector configurations +which is a weak map between [=user contexts=] and [=network body collector configuration=]. +It is initially empty. -A [=BiDi session=] has a network maximum body size which is a number defining -the maximum size (in bytes) that should be collected for a single network body. It is -initially null. +A [=BiDi session=] has a global network collector configuration map which is a [=network body collector configuration=]. It is initially null. +A [=BiDi session=] has collected responses which is a list of +[=struct=] with fields navigable id, navigation, +request id and response that contains the collected +network responses for the current session. It is initially empty.
-To match body collector given |request|, |navigable| and |collector|: - -1. Let |url patterns| be |collector|'s url patterns. - -1. Let |contexts| be |collector|'s contexts. - -1. Let |user contexts| be |collector|'s user contexts. - -1. Let |url| be the result of running the [=URL serializer=] with |request|'s - [=request/URL=]. - -1. If |url patterns| is not [=list/empty=]: - - 1. Let |match| be false. +To get network body collector configuration given |session| and +|navigable|: - 1. For each |url pattern| in |url patterns|: +1. Let |top-level navigable| be [=/top-level traversable=] for |navigable|. - 1. If [=match URL pattern=] with |url pattern| and |url|: +1. If |session|'s [=navigable network collector configurations=] + [=map/contains=] |top-level navigable|: - 1. Set |match| to true. + 1. Return |session|'s [=navigable network collector configurations=][|top-level navigable|]. - 1. Break. +1. Let |user context| be |navigable|'s [=associated user context=]. - 1. If |match| is false, return false. +1. If |session|'s [=user context network collector configurations=] + [=map/contains=] |user context|: -1. If |contexts| is not [=list/empty=]: + 1. Return |session|'s [=user context network collector configurations=][|user context|]. - 1. Let |top-level navigable id| be [=/top-level traversable=]'s [=navigable id=] for |navigable|. +1. Return |session|'s [=global network collector configuration=]. - 1. If |contexts| does not [=set/contains|contain=] |top-level navigable id|, return false. +
-1. If |user contexts| is not [=list/empty=]: +
+To get available collector size given |session|, |navigable| and |max total body size|: - 1. Let |match| be false. +1. Let |available size| be |max total body size|. - 1. For each |user context id| in |user contexts|: +1. Let |collected responses| be |session|'s [=collected responses=]. - 1. Set |user context| to [=get user context=] with |user context id|. +1. For each |collected response| of |collected responses|: - 1. If |navigable|'s [=associated user context=] is |user context|: + 1. If the response field of |collected response| is null, + continue. - 1. Set |match| to true. + 1. If the navigable field of |collected response| is not + |navigable|, continue. - 1. Break. + 1. Let response be the response field of |collected response|. - 1. If |match| is false, return false. + 1. Remove |response|'s [=response body info=]'s [=decoded size=] from |available size|. -1. Return true. +1. Return |available size|.
-
To maybe collect the response body given |session|, |request| and |response|: @@ -5739,42 +5724,72 @@ To maybe collect the response body given |session|, |request| and |re 1. If |navigable| is null, return. -1. For each |collector| in |session|'s [=network body collector map=]: +1. Let |collected responses| be |session|'s [=collected responses=]. - 1. If the result of [=match body collector=] with |request|, |navigable| and |collector| is true: +1. Let |network body collector configuration| be the result of [=get network body collector configuration=] with |session| and |navigable|. - 1. Let |response map| be |session|'s [=response map=]. +1. If |network body collector configuration| is not null: - 1. Let |request id| be request's [=request id=]. + 1. Let |document| be |navigable|'s [=active document=] - 1. Let |navigable id| be the [=navigable id=] for |navigable|. + 1. Let |max total body size| be |network body collector configuration|'s + max total body size. + + 1. Let |max resource body size| be |network body collector configuration|'s + max resource body size. + + 1. Let |response size| be |response|'s [=response body info=]'s + [=decoded size=]. + + 1. Let |response to collect| be null. + + 1. Let |request id| be request's [=request id=]. - 1. Let |response size| be |response|'s [=response body info=]'s [=decoded size=] + 1. If |response size| is less than or equal to |max resource body size|: - 1. Let |response to collect| be null. + 1. Set |response to collect| to |response|. - 1. Let |maximum size| be |session|'s [=network maximum body size=]. + 1. If |response size| is greater than [=get available collector size=] with + |session|, |navigable| and |max total body size|: - 1. If |maximum size| is not null and |response size| - is smaller than or equal to |maximum size|: + 1. For each |collected response| of |collected responses|: - 1. Set |response to collect| to |response|. + 1. If the response field of |collected response| is null, + continue. - 1. Set |response map|[|request id|] to a struct with response - |response to collect| and context |navigable id|. + 1. If the navigable field of |collected response| is not + |navigable|, continue. - 1. Break. + 1. Set the response field of |collected response| to null. + + 1. If [=get available collector size=] with |session|, |navigable| and + |max total body size| is greater than |response size|, break. + + 1. [=list/Add=] a struct with navigation |navigable|'s + [=ongoing navigation=], navigable id |navigable|'s + [=navigable id=], request id |request id|, + response |response to collect| to |collected responses|.
-To delete collected response bodies given |session| and |navigable|: +To delete collected response bodies given |session|, |navigable| and +|navigation|: + +1. For each |collected response| in |session|'s [=collected responses=]: + + 1. Let |response navigation| be collected response|'s navigation + field. + + 1. Let |response navigable id| be collected response|'s navigable id + field. + + 1. If |response navigable id| is not |navigable|'s [=navigable id=], continue. -1. For each |collected response| in |session|'s [=response map=]: + 1. If |navigation| is not null, |response navigation| is |navigation|, continue. - 1. If |collected response|'s [=navigable=] is |navigabke id|, set - |collected response|'s response field to null. + 1. Set |collected response|'s response field to null.
@@ -7048,116 +7063,6 @@ The [=remote end steps=] given |session| and |command parameters| are: -#### The network.addBodyCollector Command #### {#command-network-addBodyCollector} - -The network.addBodyCollector command adds a -[=network body collector=]. - -
-
Command Type
-
-
-      network.AddBodyCollector = (
-        method: "network.addBodyCollector",
-        params: network.AddBodyCollectorParameters
-      )
-
-      network.AddBodyCollectorParameters = {
-        ? contexts: [+browsingContext.BrowsingContext],
-        ? urlPatterns: [*network.UrlPattern],
-        ? userContexts: [+browser.UserContext],
-      }
-      
-
-
Return Type
-
-
-      network.AddBodyCollectorResult = {
-        collector: network.Collector
-      }
-    
-
-
- -
-The [=remote end steps=] given |session| and |command parameters| are: - -1. Let |collector| be the string representation of a [[!RFC9562|UUID]]. - -1. Let |url patterns| be the urlPatterns field of |command - parameters| if present, or an empty [=/list=] otherwise. - -1. Let |input user context ids| be [=set/create|create a set=] with |command parameters|[userContexts]. - -1. Let |input context ids| be [=set/create|create a set=] with |command parameters|[contexts]. - -1. If |input user context ids| is not empty and |input context ids| is not empty, - return [=error=] with [=error code=] [=invalid argument=]. - -1. Let |top-level traversable context ids| be a [=/set=]. - -1. If |input context ids| is not empty: - - 1. Let |navigables| be [=get navigables by ids=] with |input context ids|. - - 1. If [=list/size=] of |navigables| does not equal [=list/size=] of |input context ids|: - - 1. Return [=error=] with [=error code=] [=invalid argument=]. - - 1. Set |subscription navigables| be [=get top-level traversables=] with |navigables|. - - 1. For each |navigable| in |subscription navigables|: - - 1. [=set/Append=] |navigable|'s [=navigable id=] to |top-level traversable context ids|. - -1. Otherwise, if |input user context ids| is not empty: - - 1. [=list/For each=] |user context id| of |input user context ids|: - - 1. Let |user context| be [=get user context=] with |user context id|. - - 1. If |user context| is null, return [=error=] with [=error code=] [=invalid argument=]. - - -1. If the contexts field of |command parameters| is present: - - 1. Set |navigables| to an empty [=/set=]. - - 1. For each |navigable id| of |command parameters|["contexts"] - - 1. Let |navigable| be the result of [=trying=] to [=get a navigable=] - with |navigable id|. - - 1. If |navigable| is not a [=/top-level traversable=], return [=error=] - with [=error code=] [=invalid argument=]. - - 1. Append |navigable| to |navigables|. - - 1. If |navigables| is an empty [=/set=], return [=error=] with [=error code=] - [=invalid argument=]. - -1. Let |collector map| be |session|'s [=network body collector map=]. - -1. Let |parsed patterns| be an empty [=/list=]. - -1. For each |url pattern| in |url patterns|: - - 1. Let |parsed| be the result of [=trying=] to [=parse url pattern=] with |url - pattern|. - - 1. [=list/Append=] |parsed| to |parsed patterns|. - -1. Set |collector map|[|collector|] to a struct with url patterns - |parsed patterns|, userContexts - |input user context ids| and contexts - |top-level traversable context ids|. - -1. Return a new [=/map=] matching the - network.AddBodyCollectorResult production with the - collector field set to |collector|. - -
- #### The network.continueRequest Command #### {#command-network-continueRequest} The network.continueRequest command continues a request @@ -7635,22 +7540,25 @@ requests will be affected. -#### The network.removeBodyCollector Command #### {#command-network-removeBodyCollector} +#### The network.setBodyCollectorConfiguration Command #### {#command-network-setBodyCollectorConfiguration} -The network.removeBodyCollector command removes a -[=network body collector=]. +The network.setBodyCollectorConfiguration command configures +the network body collectors.
Command Type
-      network.RemoveBodyCollector = (
-        method: "network.removeBodyCollector",
-        params: network.RemoveBodyCollectorParameters
+      network.SetBodyCollectorConfiguration = (
+        method: "network.setBodyCollectorConfiguration",
+        params: network.SetBodyCollectorConfigurationParameters
       )
 
-      network.RemoveBodyCollectorParameters = {
-        collector: network.Collector
+      network.SetBodyCollectorConfigurationParameters = {
+        ? contexts: [+browsingContext.BrowsingContext],
+        maxTotalBodySize: js-uint,
+        ?maxResourceBodySize: js-uint,
+        ? userContexts: [+browser.UserContext],
       }
     
@@ -7662,56 +7570,77 @@ The network.removeBodyCollector command removes a
-
+
The [=remote end steps=] given |session| and |command parameters| are: -1. Let |collector| be the value of the "collector" field in |command - parameters|. +1. Let |input context ids| be [=set/create|create a set=] with + |command parameters|[contexts]. -1. Let |collector map| be |session|'s [=network body collector map=]. +1. Let |max total body size| be |command parameters| + ["maxTotalBodySize"]. -1. If |collector map| does not [=map/contain=] |collector|, return - [=error=] with [=error code=] [=no such collector=]. +1. Let |max resource body size| be |command parameters| + ["maxResourceBodySize"]. -1. [=map/Remove=] |collector| from |collector map|. +1. Let |input user context ids| be [=set/create|create a set=] with + |command parameters|[userContexts]. -1. Return [=success=] with data [=null=]. +1. If |input user context ids| is not empty and |input context ids| is not + empty, return [=error=] with [=error code=] [=invalid argument=]. -
+1. If |input user context ids| is not empty and |input context ids| is not + empty, return [=error=] with [=error code=] [=invalid argument=]. -#### The network.setBodyCollectorConfiguration Command #### {#command-network-setBodyCollectorConfiguration} +1. Let |body collector configuration| be a struct with max total body size + |max total body size| and max resource body size |max resource body size|. -The network.setBodyCollectorConfiguration command configures -the network body collectors. +1. If |input context ids| is not empty: -
-
Command Type
-
-
-      network.SetBodyCollectorConfiguration = (
-        method: "network.setBodyCollectorConfiguration",
-        params: network.SetBodyCollectorConfigurationParameters
-      )
+   1. Let |navigables| be [=get navigables by ids=] with |input context ids|.
 
-      network.SetBodyCollectorConfigurationParameters = {
-        maximumBodySize: js-uint,
-      }
-    
-
-
Return Type
-
- - EmptyResult - -
-
+ 1. If [=list/size=] of |navigables| does not equal [=list/size=] of + |input context ids|: -
-The [=remote end steps=] given |session| and |command parameters| are: + 1. Return [=error=] with [=error code=] [=invalid argument=]. + + 1. Set |collector navigables| to [=get top-level traversables=] with + |navigables|. + + 1. For each |navigable| in |collector navigables|: + + 1. Let |navigable configurations| be |session|'s + [=navigable network collector configurations=]. + + 1. [=map/Set=] |navigable configurations|[|navigable|] to |body collector configuration|. + +1. Otherwise, if |input user context ids| is not empty: + + 1. [=list/For each=] |user context id| of |input user context ids|: + + 1. Let |user context| be [=get user context=] with |user context id|. + + 1. If |user context| is null, return [=error=] with [=error code=] + [=invalid argument=]. + + 1. For each |traversable| in remote end's [=/top-level traversables=]: + + 1. If |traversable|'s [=associated user context=] is |user context|, + [=map/Remove=] |session|'s [=navigable network collector configurations=][|traversable|]. + + 1. Let |user context configurations| be |session|'s + [=user context network collector configurations=]. + + 1. [=map/Set=] |user context configurations|[|user context|] to |body collector configuration|. + +1. Otherwise: + + 1. Set |session|'s [=user context network collector configurations=] to an + empty [=/map=]. -1. Let |size| be |command parameters|["maximumBodySize"]. + 1. Set |session|'s [=navigable network collector configurations=] to an empty + [=/map=]. -1. Set |session|'s [=network maximum body size=] to |size|. + 1. Set |session|'s [=global network collector configuration=] to |body collector configuration|. 1. Return [=success=] with data null.