From 947bb8e1265e4bc86cd17592e59b48dcd35d9950 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Mon, 27 May 2024 13:06:33 +0200 Subject: [PATCH] fix: expose the override data to the request events (#2241) This PR make sure that updates via interception to the Request are properly show in the `request` property of `responseStarted` and `responseCompleted` events. This should only be applicable to the request part as we get the update data from the `responseRecived` CDP events. --- .../modules/network/NetworkRequest.ts | 61 ++++++--- .../modules/network/NetworkUtils.ts | 19 ++- .../network/continue_request/headers.py.ini | 9 -- .../network/continue_request/method.py.ini | 126 ------------------ .../network/continue_request/headers.py.ini | 9 -- .../network/continue_request/method.py.ini | 126 ------------------ .../network/continue_request/headers.py.ini | 9 -- .../network/continue_request/method.py.ini | 126 ------------------ 8 files changed, 62 insertions(+), 423 deletions(-) delete mode 100644 wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/continue_request/method.py.ini delete mode 100644 wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/continue_request/method.py.ini delete mode 100644 wpt-metadata/mapper/headless/webdriver/tests/bidi/network/continue_request/method.py.ini diff --git a/src/bidiMapper/modules/network/NetworkRequest.ts b/src/bidiMapper/modules/network/NetworkRequest.ts index 3d1af63595..31d170f6bb 100644 --- a/src/bidiMapper/modules/network/NetworkRequest.ts +++ b/src/bidiMapper/modules/network/NetworkRequest.ts @@ -39,6 +39,7 @@ import { computeHeadersSize, bidiNetworkHeadersFromCdpNetworkHeaders, cdpToBiDiCookie, + bidiNetworkHeadersFromCdpNetworkHeadersEntries, } from './NetworkUtils.js'; const REALM_REGEX = /(?<=realm=").*(?=")/; @@ -72,6 +73,7 @@ export class NetworkRequest { info?: Protocol.Network.RequestWillBeSentEvent; extraInfo?: Protocol.Network.RequestWillBeSentExtraInfoEvent; paused?: Protocol.Fetch.RequestPausedEvent; + overrides?: Omit; auth?: Protocol.Fetch.AuthRequiredEvent; } = {}; @@ -136,6 +138,7 @@ export class NetworkRequest { const url = this.#response.info?.url ?? this.#response.paused?.request.url ?? + this.#request.overrides?.url ?? this.#request.auth?.request.url ?? this.#request.info?.request.url ?? this.#request.paused?.request.url ?? @@ -146,6 +149,7 @@ export class NetworkRequest { get method(): string { return ( + this.#request.overrides?.method ?? this.#request.info?.request.method ?? this.#request.paused?.request.method ?? this.#request.auth?.request.method ?? @@ -405,21 +409,24 @@ export class NetworkRequest { } /** @see https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#method-continueRequest */ - async continueRequest({ - url, - method, - headers, - postData, - }: Omit = {}) { + async continueRequest( + overrides: Omit = {} + ) { assert(this.#fetchId, 'Network Interception not set-up.'); await this.cdpClient.sendCommand('Fetch.continueRequest', { requestId: this.#fetchId, - url, - method, - headers, - postData, + url: overrides.url, + method: overrides.method, + headers: overrides.headers, + postData: overrides.postData, }); + // TODO: Store postData's size only + this.#request.overrides = { + url: overrides.url, + method: overrides.method, + headers: overrides.headers, + }; this.#interceptPhase = undefined; } @@ -560,10 +567,16 @@ export class NetworkRequest { this.#response.extraInfo = undefined; } - // TODO: get headers from Fetch.requestPaused - const headers = bidiNetworkHeadersFromCdpNetworkHeaders( - this.#response.info?.headers - ); + const headers = [ + ...bidiNetworkHeadersFromCdpNetworkHeaders(this.#response.info?.headers), + ...bidiNetworkHeadersFromCdpNetworkHeaders( + this.#response.extraInfo?.headers + ), + // TODO: Verify how to dedupe these + // ...bidiNetworkHeadersFromCdpNetworkHeadersEntries( + // this.#response.paused?.responseHeaders + // ), + ]; // TODO: get headers from Fetch.requestPaused const authChallenges = this.#authChallenges( @@ -615,9 +628,23 @@ export class NetworkRequest { ? NetworkRequest.#getCookies(this.#request.extraInfo.associatedCookies) : []; - const headers = bidiNetworkHeadersFromCdpNetworkHeaders( - this.#request.info?.request.headers - ); + let headers: Network.Header[] = []; + if (this.#request.overrides?.headers) { + headers = [ + ...bidiNetworkHeadersFromCdpNetworkHeadersEntries( + this.#request.overrides?.headers + ), + ]; + } else { + headers = [ + ...bidiNetworkHeadersFromCdpNetworkHeaders( + this.#request.info?.request.headers + ), + ...bidiNetworkHeadersFromCdpNetworkHeaders( + this.#request.extraInfo?.headers + ), + ]; + } return { request: this.#id, diff --git a/src/bidiMapper/modules/network/NetworkUtils.ts b/src/bidiMapper/modules/network/NetworkUtils.ts index d45b6f4d1e..b9f67a39f8 100644 --- a/src/bidiMapper/modules/network/NetworkUtils.ts +++ b/src/bidiMapper/modules/network/NetworkUtils.ts @@ -35,7 +35,7 @@ export function computeHeadersSize(headers: Network.Header[]): number { return new TextEncoder().encode(requestHeaders).length; } -/** Converts from CDP Network domain headers to Bidi network headers. */ +/** Converts from CDP Network domain headers to BiDi network headers. */ export function bidiNetworkHeadersFromCdpNetworkHeaders( headers?: Protocol.Network.Headers ): Network.Header[] { @@ -52,6 +52,23 @@ export function bidiNetworkHeadersFromCdpNetworkHeaders( })); } +/** Converts from CDP Fetch domain headers to BiDi network headers. */ +export function bidiNetworkHeadersFromCdpNetworkHeadersEntries( + headers?: Protocol.Fetch.HeaderEntry[] +): Network.Header[] { + if (!headers) { + return []; + } + + return headers.map(({name, value}) => ({ + name, + value: { + type: 'string', + value, + }, + })); +} + /** Converts from Bidi network headers to CDP Network domain headers. */ export function cdpNetworkHeadersFromBidiNetworkHeaders( headers?: Network.Header[] diff --git a/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/continue_request/headers.py.ini b/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/continue_request/headers.py.ini index aed01368c1..68d0c72cb0 100644 --- a/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/continue_request/headers.py.ini +++ b/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/continue_request/headers.py.ini @@ -1,12 +1,3 @@ [headers.py] - [test_modify_headers[request_headers1-modified_headers1\]] - expected: FAIL - - [test_modify_headers[request_headers2-modified_headers2\]] - expected: FAIL - - [test_modify_headers[request_headers3-modified_headers3\]] - expected: FAIL - [test_override_cookies] expected: FAIL diff --git a/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/continue_request/method.py.ini b/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/continue_request/method.py.ini deleted file mode 100644 index da760fa1c9..0000000000 --- a/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/continue_request/method.py.ini +++ /dev/null @@ -1,126 +0,0 @@ -[method.py] - [test_request_method[DELETE-GET\]] - expected: FAIL - - [test_request_method[DELETE-HEAD\]] - expected: FAIL - - [test_request_method[DELETE-OPTIONS\]] - expected: FAIL - - [test_request_method[DELETE-PATCH\]] - expected: FAIL - - [test_request_method[DELETE-POST\]] - expected: FAIL - - [test_request_method[DELETE-PUT\]] - expected: FAIL - - [test_request_method[GET-DELETE\]] - expected: FAIL - - [test_request_method[GET-HEAD\]] - expected: FAIL - - [test_request_method[GET-OPTIONS\]] - expected: FAIL - - [test_request_method[GET-PATCH\]] - expected: FAIL - - [test_request_method[GET-POST\]] - expected: FAIL - - [test_request_method[GET-PUT\]] - expected: FAIL - - [test_request_method[HEAD-DELETE\]] - expected: FAIL - - [test_request_method[HEAD-GET\]] - expected: FAIL - - [test_request_method[HEAD-OPTIONS\]] - expected: FAIL - - [test_request_method[HEAD-PATCH\]] - expected: FAIL - - [test_request_method[HEAD-POST\]] - expected: FAIL - - [test_request_method[HEAD-PUT\]] - expected: FAIL - - [test_request_method[OPTIONS-DELETE\]] - expected: FAIL - - [test_request_method[OPTIONS-GET\]] - expected: FAIL - - [test_request_method[OPTIONS-HEAD\]] - expected: FAIL - - [test_request_method[OPTIONS-PATCH\]] - expected: FAIL - - [test_request_method[OPTIONS-POST\]] - expected: FAIL - - [test_request_method[OPTIONS-PUT\]] - expected: FAIL - - [test_request_method[PATCH-DELETE\]] - expected: FAIL - - [test_request_method[PATCH-GET\]] - expected: FAIL - - [test_request_method[PATCH-HEAD\]] - expected: FAIL - - [test_request_method[PATCH-OPTIONS\]] - expected: FAIL - - [test_request_method[PATCH-POST\]] - expected: FAIL - - [test_request_method[PATCH-PUT\]] - expected: FAIL - - [test_request_method[POST-DELETE\]] - expected: FAIL - - [test_request_method[POST-GET\]] - expected: FAIL - - [test_request_method[POST-HEAD\]] - expected: FAIL - - [test_request_method[POST-OPTIONS\]] - expected: FAIL - - [test_request_method[POST-PATCH\]] - expected: FAIL - - [test_request_method[POST-PUT\]] - expected: FAIL - - [test_request_method[PUT-DELETE\]] - expected: FAIL - - [test_request_method[PUT-GET\]] - expected: FAIL - - [test_request_method[PUT-HEAD\]] - expected: FAIL - - [test_request_method[PUT-OPTIONS\]] - expected: FAIL - - [test_request_method[PUT-PATCH\]] - expected: FAIL - - [test_request_method[PUT-POST\]] - expected: FAIL diff --git a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/continue_request/headers.py.ini b/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/continue_request/headers.py.ini index aed01368c1..68d0c72cb0 100644 --- a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/continue_request/headers.py.ini +++ b/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/continue_request/headers.py.ini @@ -1,12 +1,3 @@ [headers.py] - [test_modify_headers[request_headers1-modified_headers1\]] - expected: FAIL - - [test_modify_headers[request_headers2-modified_headers2\]] - expected: FAIL - - [test_modify_headers[request_headers3-modified_headers3\]] - expected: FAIL - [test_override_cookies] expected: FAIL diff --git a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/continue_request/method.py.ini b/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/continue_request/method.py.ini deleted file mode 100644 index da760fa1c9..0000000000 --- a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/continue_request/method.py.ini +++ /dev/null @@ -1,126 +0,0 @@ -[method.py] - [test_request_method[DELETE-GET\]] - expected: FAIL - - [test_request_method[DELETE-HEAD\]] - expected: FAIL - - [test_request_method[DELETE-OPTIONS\]] - expected: FAIL - - [test_request_method[DELETE-PATCH\]] - expected: FAIL - - [test_request_method[DELETE-POST\]] - expected: FAIL - - [test_request_method[DELETE-PUT\]] - expected: FAIL - - [test_request_method[GET-DELETE\]] - expected: FAIL - - [test_request_method[GET-HEAD\]] - expected: FAIL - - [test_request_method[GET-OPTIONS\]] - expected: FAIL - - [test_request_method[GET-PATCH\]] - expected: FAIL - - [test_request_method[GET-POST\]] - expected: FAIL - - [test_request_method[GET-PUT\]] - expected: FAIL - - [test_request_method[HEAD-DELETE\]] - expected: FAIL - - [test_request_method[HEAD-GET\]] - expected: FAIL - - [test_request_method[HEAD-OPTIONS\]] - expected: FAIL - - [test_request_method[HEAD-PATCH\]] - expected: FAIL - - [test_request_method[HEAD-POST\]] - expected: FAIL - - [test_request_method[HEAD-PUT\]] - expected: FAIL - - [test_request_method[OPTIONS-DELETE\]] - expected: FAIL - - [test_request_method[OPTIONS-GET\]] - expected: FAIL - - [test_request_method[OPTIONS-HEAD\]] - expected: FAIL - - [test_request_method[OPTIONS-PATCH\]] - expected: FAIL - - [test_request_method[OPTIONS-POST\]] - expected: FAIL - - [test_request_method[OPTIONS-PUT\]] - expected: FAIL - - [test_request_method[PATCH-DELETE\]] - expected: FAIL - - [test_request_method[PATCH-GET\]] - expected: FAIL - - [test_request_method[PATCH-HEAD\]] - expected: FAIL - - [test_request_method[PATCH-OPTIONS\]] - expected: FAIL - - [test_request_method[PATCH-POST\]] - expected: FAIL - - [test_request_method[PATCH-PUT\]] - expected: FAIL - - [test_request_method[POST-DELETE\]] - expected: FAIL - - [test_request_method[POST-GET\]] - expected: FAIL - - [test_request_method[POST-HEAD\]] - expected: FAIL - - [test_request_method[POST-OPTIONS\]] - expected: FAIL - - [test_request_method[POST-PATCH\]] - expected: FAIL - - [test_request_method[POST-PUT\]] - expected: FAIL - - [test_request_method[PUT-DELETE\]] - expected: FAIL - - [test_request_method[PUT-GET\]] - expected: FAIL - - [test_request_method[PUT-HEAD\]] - expected: FAIL - - [test_request_method[PUT-OPTIONS\]] - expected: FAIL - - [test_request_method[PUT-PATCH\]] - expected: FAIL - - [test_request_method[PUT-POST\]] - expected: FAIL diff --git a/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/continue_request/headers.py.ini b/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/continue_request/headers.py.ini index aed01368c1..68d0c72cb0 100644 --- a/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/continue_request/headers.py.ini +++ b/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/continue_request/headers.py.ini @@ -1,12 +1,3 @@ [headers.py] - [test_modify_headers[request_headers1-modified_headers1\]] - expected: FAIL - - [test_modify_headers[request_headers2-modified_headers2\]] - expected: FAIL - - [test_modify_headers[request_headers3-modified_headers3\]] - expected: FAIL - [test_override_cookies] expected: FAIL diff --git a/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/continue_request/method.py.ini b/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/continue_request/method.py.ini deleted file mode 100644 index da760fa1c9..0000000000 --- a/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/continue_request/method.py.ini +++ /dev/null @@ -1,126 +0,0 @@ -[method.py] - [test_request_method[DELETE-GET\]] - expected: FAIL - - [test_request_method[DELETE-HEAD\]] - expected: FAIL - - [test_request_method[DELETE-OPTIONS\]] - expected: FAIL - - [test_request_method[DELETE-PATCH\]] - expected: FAIL - - [test_request_method[DELETE-POST\]] - expected: FAIL - - [test_request_method[DELETE-PUT\]] - expected: FAIL - - [test_request_method[GET-DELETE\]] - expected: FAIL - - [test_request_method[GET-HEAD\]] - expected: FAIL - - [test_request_method[GET-OPTIONS\]] - expected: FAIL - - [test_request_method[GET-PATCH\]] - expected: FAIL - - [test_request_method[GET-POST\]] - expected: FAIL - - [test_request_method[GET-PUT\]] - expected: FAIL - - [test_request_method[HEAD-DELETE\]] - expected: FAIL - - [test_request_method[HEAD-GET\]] - expected: FAIL - - [test_request_method[HEAD-OPTIONS\]] - expected: FAIL - - [test_request_method[HEAD-PATCH\]] - expected: FAIL - - [test_request_method[HEAD-POST\]] - expected: FAIL - - [test_request_method[HEAD-PUT\]] - expected: FAIL - - [test_request_method[OPTIONS-DELETE\]] - expected: FAIL - - [test_request_method[OPTIONS-GET\]] - expected: FAIL - - [test_request_method[OPTIONS-HEAD\]] - expected: FAIL - - [test_request_method[OPTIONS-PATCH\]] - expected: FAIL - - [test_request_method[OPTIONS-POST\]] - expected: FAIL - - [test_request_method[OPTIONS-PUT\]] - expected: FAIL - - [test_request_method[PATCH-DELETE\]] - expected: FAIL - - [test_request_method[PATCH-GET\]] - expected: FAIL - - [test_request_method[PATCH-HEAD\]] - expected: FAIL - - [test_request_method[PATCH-OPTIONS\]] - expected: FAIL - - [test_request_method[PATCH-POST\]] - expected: FAIL - - [test_request_method[PATCH-PUT\]] - expected: FAIL - - [test_request_method[POST-DELETE\]] - expected: FAIL - - [test_request_method[POST-GET\]] - expected: FAIL - - [test_request_method[POST-HEAD\]] - expected: FAIL - - [test_request_method[POST-OPTIONS\]] - expected: FAIL - - [test_request_method[POST-PATCH\]] - expected: FAIL - - [test_request_method[POST-PUT\]] - expected: FAIL - - [test_request_method[PUT-DELETE\]] - expected: FAIL - - [test_request_method[PUT-GET\]] - expected: FAIL - - [test_request_method[PUT-HEAD\]] - expected: FAIL - - [test_request_method[PUT-OPTIONS\]] - expected: FAIL - - [test_request_method[PUT-PATCH\]] - expected: FAIL - - [test_request_method[PUT-POST\]] - expected: FAIL