tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit ae9c610377718bc0cae69d32519e23eb2daadea4
parent 6ecd342a4f9d147f3e79bc7d0710534aa9639373
Author: Julian Descottes <jdescottes@mozilla.com>
Date:   Thu,  8 Jan 2026 11:05:29 +0000

Bug 2004973 - [remote] Only update the response when full response content has been received r=Sasha

When a response is delivered in chunks the encoded body size used to decode the content no longer matches the actual size because we read the sizes from the first devtools addResponseContent callback.

The implementation is updated to jold onto the responseContent from devtools and only set it when the response is fully ready.

The picture added here is a resize of an already existing picture in the firefox codebase (https://searchfox.org/firefox-main/rev/e61d59b5c9a651fd7bf28043f87c0dc669833496/dom/media/test/reftest/av1hdr2020.png).

This picture is slightly above 1MB and triggers the same issue as the one from the bug report.

Differential Revision: https://phabricator.services.mozilla.com/D277896

Diffstat:
Mremote/shared/listeners/NetworkEventRecord.sys.mjs | 20++++++++++++++++----
Atesting/web-platform/mozilla/tests/webdriver/bidi/network/get_data/big_file.py | 25+++++++++++++++++++++++++
Atesting/web-platform/mozilla/tests/webdriver/bidi/network/get_data/support/big.png | 0
3 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/remote/shared/listeners/NetworkEventRecord.sys.mjs b/remote/shared/listeners/NetworkEventRecord.sys.mjs @@ -24,6 +24,7 @@ ChromeUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get()); */ export class NetworkEventRecord { #decodedBodySizeMap; + #devtoolsResponseContent; #devtoolsResponseSizes; #fromCache; #networkEventsMap; @@ -67,6 +68,7 @@ export class NetworkEventRecord { }); this.#response = null; + this.#devtoolsResponseContent = null; this.#devtoolsResponseSizes = { decodedBodySize: 0, encodedBodySize: 0, @@ -225,11 +227,14 @@ export class NetworkEventRecord { * An object which represents the response content. */ addResponseContent(responseContent) { - if (this.#response) { - this.#response.setResponseContent(responseContent); - } + // Bug 1982252: at the moment we have no way to know which + // addResponseContent call corresponds to the last chunk, and therefore we + // hold on the responseContent and will forward it to the NetworkResponse + // class in addResponseContentComplete. + this.#devtoolsResponseContent = responseContent; + // Bug 1979111: In Bug 1971778 the DevTools NetworkObserver is configured - // to no longer decode responsizes. + // to no longer decode response sizes. // Consequently `responseContent` no longer exposes the decodedBodySize. // Until we can monitor decoded body size in all processes, ServiceWorker // initiated requests will report the encodedBodySize here, which is at @@ -256,6 +261,12 @@ export class NetworkEventRecord { * An object with info for when response content is complete */ addResponseContentComplete(responseInfo) { + // addResponseContentComplete is called when all chunks have been received, + // we can now set the final response content in the response object. + if (this.#response && this.#devtoolsResponseContent) { + this.#response.setResponseContent(this.#devtoolsResponseContent); + } + if ( // Ignore already completed requests. this.#request.alreadyCompleted || @@ -265,6 +276,7 @@ export class NetworkEventRecord { ) { return; } + this.#handleRequestEnd( responseInfo.blockedReason, this.#devtoolsResponseSizes diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/network/get_data/big_file.py b/testing/web-platform/mozilla/tests/webdriver/bidi/network/get_data/big_file.py @@ -0,0 +1,25 @@ +import pytest +from tests.support.asserts import assert_png + +pytestmark = pytest.mark.asyncio + + +PAGE_BIG_IMAGE = "_mozilla/webdriver/bidi/network/get_data/support/big.png" + + +async def test_data_type_response_big_file( + bidi_session, + url, + setup_collected_data, +): + # There is no strict requirement from the spec to support payloads bigger + # than 1MB, so this test remains mozilla-specific. It currently times out on + # chrome. + [request, _] = await setup_collected_data( + fetch_url=url(PAGE_BIG_IMAGE), max_encoded_data_size=2000000 + ) + data = await bidi_session.network.get_data(request=request, data_type="response") + + assert data["type"] == "base64" + assert isinstance(data["value"], str) + assert_png(data["value"]) diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/network/get_data/support/big.png b/testing/web-platform/mozilla/tests/webdriver/bidi/network/get_data/support/big.png Binary files differ.