From ab3931ad56f6f3c2f5207089132b95c120dc9056 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 16 Mar 2023 14:01:03 +0000 Subject: [PATCH] Bug 1806794 - Support "network.response" events for cached responses r=webdriver-reviewers,whimboo,devtools-reviewers,ochameau This fixes two issues: - the transferred size was missing from cached responseStarted events - the fromCache flag needs to be read on the initial network event payload from devtools, because relying on the isFromCache logic used to build the addResponseStart payload does not properly detect all cached responses (eg for a cached 301) Differential Revision: https://phabricator.services.mozilla.com/D171508 --- devtools/shared/network-observer/NetworkObserver.sys.mjs | 1 + remote/shared/listeners/NetworkEventRecord.sys.mjs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/devtools/shared/network-observer/NetworkObserver.sys.mjs b/devtools/shared/network-observer/NetworkObserver.sys.mjs index fc5e3ddbeb7f..62065961cd6c 100644 --- a/devtools/shared/network-observer/NetworkObserver.sys.mjs +++ b/devtools/shared/network-observer/NetworkObserver.sys.mjs @@ -481,6 +481,7 @@ export class NetworkObserver { statusText, bodySize: 0, headersSize: 0, + transferredSize: 0, waitingTime: 0, }, "", diff --git a/remote/shared/listeners/NetworkEventRecord.sys.mjs b/remote/shared/listeners/NetworkEventRecord.sys.mjs index 321112251503..28a392729613 100644 --- a/remote/shared/listeners/NetworkEventRecord.sys.mjs +++ b/remote/shared/listeners/NetworkEventRecord.sys.mjs @@ -19,6 +19,7 @@ ChromeUtils.defineESModuleGetters(lazy, { */ export class NetworkEventRecord { #channel; + #fromCache; #networkListener; #redirectCount; #requestData; @@ -38,6 +39,8 @@ export class NetworkEventRecord { */ constructor(networkEvent, channel, networkListener) { this.#channel = channel; + this.#fromCache = networkEvent.fromCache; + this.#wrappedChannel = ChannelWrapper.get(channel); this.#networkListener = networkListener; @@ -115,7 +118,7 @@ export class NetworkEventRecord { ...this.#responseData, bodySize: response.bodySize, bytesReceived: response.transferredSize, - fromCache: response.fromCache, + fromCache: this.#fromCache || response.fromCache, // Note: at this point we only have access to the headers size. Parsed // headers will be added in addResponseHeaders. headersSize: response.headersSize,