tor-browser

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

commit 642917788c4f388b3df5d830d28e3910cf33cb62
parent e6a1a7448dfb70352cf1200027fc3d70b2ad6543
Author: Hubert Boma Manilla <hmanilla@mozilla.com>
Date:   Wed,  5 Nov 2025 18:54:33 +0000

Bug 1995694 - [devtools] Wait for the actual value of the promise returned from getContentFromCache r=devtools-reviewers,nchevobbe

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

Diffstat:
Mdevtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js | 20++++++++++++++++++++
Mdevtools/client/netmonitor/test/browser_net_cause_source_map.js | 7++-----
Mdevtools/client/netmonitor/test/head.js | 1+
Mdevtools/shared/network-observer/NetworkResponseListener.sys.mjs | 11+++++++----
4 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/devtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js b/devtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js @@ -18,12 +18,32 @@ add_task(async function () { info("Starting test... "); + await testWithEnabledCache(); await testSimpleReload(); await testResponseBodyLimits(); await testManyReloads(); await testClearedRequests(); }); +// Test covers a fix (see Bug 1995694) where reloading pages with js sources when the cache is enabled +// throws an error which then causes copy all as har to break (see Bug 1995746). +async function testWithEnabledCache() { + info("Tests multiple reloads of html which contains a JS bundle"); + const { monitor } = await initNetMonitor(SOURCEMAP_URL, { + enableCache: true, + }); + + // Reload the browser at least 4 times to trigger the error + let runs = 4; + while (runs > 0) { + await reloadBrowser(); + --runs; + } + const har = await copyAllAsHARWithContextMenu(monitor); + isnot(har.log, null, "The HAR log must exist"); + await teardown(monitor); +} + async function testSimpleReload() { info("Test with a simple page reload"); const { tab, monitor, toolbox } = await initNetMonitor(HTTPS_SIMPLE_URL, { diff --git a/devtools/client/netmonitor/test/browser_net_cause_source_map.js b/devtools/client/netmonitor/test/browser_net_cause_source_map.js @@ -7,15 +7,12 @@ * Tests if request cause is reported correctly when using source maps. */ -const CAUSE_FILE_NAME = "html_maps-test-page.html"; -const CAUSE_URL = HTTPS_EXAMPLE_URL + CAUSE_FILE_NAME; - const N_EXPECTED_REQUESTS = 4; add_task(async function () { // the initNetMonitor function clears the network request list after the // page is loaded. That's why we first load a bogus page from SIMPLE_URL, - // and only then load the real thing from CAUSE_URL - we want to catch + // and only then load the real thing from SOURCEMAP_URL - we want to catch // all the requests the page is making, not only the XHRs. // We can't use about:blank here, because initNetMonitor checks that the // page has actually made at least one request. @@ -26,7 +23,7 @@ add_task(async function () { store.dispatch(Actions.batchEnable(false)); let waitPromise = waitForNetworkEvents(monitor, N_EXPECTED_REQUESTS); - await navigateTo(CAUSE_URL); + await navigateTo(SOURCEMAP_URL); await waitPromise; info("Clicking item and waiting for details panel to open"); diff --git a/devtools/client/netmonitor/test/head.js b/devtools/client/netmonitor/test/head.js @@ -127,6 +127,7 @@ const CSP_RESEND_URL = EXAMPLE_URL + "html_csp-resend-test-page.html"; const IMAGE_CACHE_URL = HTTPS_EXAMPLE_URL + "html_image-cache.html"; const STYLESHEET_CACHE_URL = HTTPS_EXAMPLE_URL + "html_stylesheet-cache.html"; const SCRIPT_CACHE_URL = HTTPS_EXAMPLE_URL + "html_script-cache.html"; +const SOURCEMAP_URL = HTTPS_EXAMPLE_URL + "html_maps-test-page.html"; const MODULE_SCRIPT_CACHE_URL = HTTPS_EXAMPLE_URL + "html_module-script-cache.html"; const SLOW_REQUESTS_URL = EXAMPLE_URL + "html_slow-requests-test-page.html"; diff --git a/devtools/shared/network-observer/NetworkResponseListener.sys.mjs b/devtools/shared/network-observer/NetworkResponseListener.sys.mjs @@ -341,9 +341,8 @@ export class NetworkResponseListener { * https://developer.mozilla.org/En/NsIRequestObserver * * @param nsIRequest request - * @param nsISupports context */ - onStartRequest(request) { + async onStartRequest(request) { request = request.QueryInterface(Ci.nsIChannel); // Converter will call this again, we should just ignore that. if (this.#request) { @@ -373,7 +372,7 @@ export class NetworkResponseListener { // Accessing `alternativeDataType` for some SW requests throws. } if (isOptimizedContent) { - const data = this.#getContentFromCache(); + const data = await this.#getContentFromCache(); this.#getResponseContent(data); this.#getResponseContentComplete(); return; @@ -653,7 +652,11 @@ export class NetworkResponseListener { this.#onSecurityInfo.then(() => this.#destroy()); } - async #getContentFromCache() { + /** + * Loads the content from the cache + * @returns Promise + */ + #getContentFromCache() { return new Promise(resolve => { // Response is cached, so we load it from cache. let charset;