Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(firefox): disable cache when request interception is enabled (#30113)

Andrey Lushnikov4781b3c3a8d7
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<void> {
- 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']);
}
});