From 4781b3c3a8d71aa509e139e66090dbc080667c0a Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 28 Mar 2024 10:25:37 -0700 Subject: [PATCH] fix(firefox): disable cache when request interception is enabled (#30113) Fixes #30000 --- packages/playwright-core/src/server/firefox/ffBrowser.ts | 5 ++++- .../playwright-core/src/server/firefox/ffNetworkManager.ts | 5 ++++- tests/page/page-network-response.spec.ts | 6 ++---- tests/page/page-route.spec.ts | 7 +++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/playwright-core/src/server/firefox/ffBrowser.ts b/packages/playwright-core/src/server/firefox/ffBrowser.ts index df591066c0..0519ff8307 100644 --- a/packages/playwright-core/src/server/firefox/ffBrowser.ts +++ b/packages/playwright-core/src/server/firefox/ffBrowser.ts @@ -366,7 +366,10 @@ export class FFBrowserContext extends BrowserContext { } async doUpdateRequestInterception(): Promise { - await this._browser.session.send('Browser.setRequestInterception', { browserContextId: this._browserContextId, enabled: !!this._requestInterceptor }); + await Promise.all([ + this._browser.session.send('Browser.setRequestInterception', { browserContextId: this._browserContextId, enabled: !!this._requestInterceptor }), + this._browser.session.send('Browser.setCacheDisabled', { browserContextId: this._browserContextId, cacheDisabled: !!this._requestInterceptor }), + ]); } onClosePersistent() {} diff --git a/packages/playwright-core/src/server/firefox/ffNetworkManager.ts b/packages/playwright-core/src/server/firefox/ffNetworkManager.ts index 2fdc8850b5..081a1c9480 100644 --- a/packages/playwright-core/src/server/firefox/ffNetworkManager.ts +++ b/packages/playwright-core/src/server/firefox/ffNetworkManager.ts @@ -50,7 +50,10 @@ export class FFNetworkManager { } async setRequestInterception(enabled: boolean) { - await this._session.send('Network.setRequestInterception', { enabled }); + await Promise.all([ + this._session.send('Network.setRequestInterception', { enabled }), + this._session.send('Page.setCacheDisabled', { cacheDisabled: enabled }), + ]); } _onRequestWillBeSent(event: Protocol.Network.requestWillBeSentPayload) { diff --git a/tests/page/page-network-response.spec.ts b/tests/page/page-network-response.spec.ts index a4754f5f6e..ecae86987a 100644 --- a/tests/page/page-network-response.spec.ts +++ b/tests/page/page-network-response.spec.ts @@ -348,9 +348,8 @@ it('should return body for prefetch script', async ({ page, server, browserName expect(body.toString()).toBe('// Scripts will be pre-fetched'); }); -it('should bypass disk cache when page interception is enabled', async ({ page, server, browserName }) => { +it('should bypass disk cache when page interception is enabled', async ({ page, server }) => { it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30000' }); - it.fixme(browserName === 'firefox', 'Returns cached response.'); await page.goto(server.PREFIX + '/frames/one-frame.html'); await page.route('**/api*', route => route.continue()); { @@ -400,9 +399,8 @@ it('should bypass disk cache when page interception is enabled', async ({ page, } }); -it('should bypass disk cache when context interception is enabled', async ({ page, server, browserName }) => { +it('should bypass disk cache when context interception is enabled', async ({ page, server }) => { it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30000' }); - it.fixme(browserName === 'firefox', 'Returns cached response.'); await page.context().route('**/api*', route => route.continue()); await page.goto(server.PREFIX + '/frames/one-frame.html'); { diff --git a/tests/page/page-route.spec.ts b/tests/page/page-route.spec.ts index 828bd4a9e2..a90eaae4db 100644 --- a/tests/page/page-route.spec.ts +++ b/tests/page/page-route.spec.ts @@ -739,7 +739,7 @@ it('should respect cors overrides', async ({ page, server, browserName, isAndroi } }); -it('should not auto-intercept non-preflight OPTIONS', async ({ page, server, isAndroid }) => { +it('should not auto-intercept non-preflight OPTIONS', async ({ page, server, isAndroid, browserName }) => { it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/20469' }); it.fixme(isAndroid); @@ -793,7 +793,10 @@ it('should not auto-intercept non-preflight OPTIONS', async ({ page, server, isA expect.soft(text1).toBe('Hello'); expect.soft(text2).toBe('World'); // Preflight for OPTIONS is auto-fulfilled, then OPTIONS, then GET without preflight. - expect.soft(requests).toEqual(['OPTIONS:/something', 'GET:/something']); + if (browserName === 'firefox') + expect.soft(requests).toEqual(['OPTIONS:/something', 'OPTIONS:/something', 'GET:/something']); + else + expect.soft(requests).toEqual(['OPTIONS:/something', 'GET:/something']); } });