Skip to content

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

fix: do not send favicon request to network when interception is on (#33639)

Yury Semikhatsky6d71805f4ac3
diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.ts
index 11aba2b1b2..81f04d94eb 100644
--- a/packages/playwright-core/src/server/frames.ts
+++ b/packages/playwright-core/src/server/frames.ts
@@ -296,7 +296,8 @@ export class FrameManager {
if (request._documentId)
frame.setPendingDocument({ documentId: request._documentId, request });
if (request._isFavicon) {
- route?.continue({ isFallback: true }).catch(() => {});
+ // Abort favicon requests to avoid network access in case of interception.
+ route?.abort('aborted').catch(() => {});
return;
}
this._page.emitOnContext(BrowserContext.Events.Request, request);
diff --git a/tests/page/page-request-intercept.spec.ts b/tests/page/page-request-intercept.spec.ts
index eb9baae47e..0b299ca91b 100644
--- a/tests/page/page-request-intercept.spec.ts
+++ b/tests/page/page-request-intercept.spec.ts
@@ -317,4 +317,26 @@ it('request.postData is not null when fetching FormData with a Blob', {
const postData = await postDataPromise;
expect(postData).toContain('Content-Disposition: form-data; name="file"; filename="blob"');
expect(postData).toContain('\r\nhello\r\n');
-});
\ No newline at end of file
+});
+
+it('should abort favicon requests if interception is enabled', async ({ page, server, browserName }) => {
+ let requestCount = 0;
+ server.setRoute('/favicon.ico', (req, res) => {
+ ++requestCount;
+ res.setHeader('content-type', 'text/plain');
+ res.end('my content');
+ });
+ // Intercept all requests.
+ await page.route('**/*', async route => {
+ await route.fulfill({
+ status: 200,
+ body: 'Hello, world!',
+ });
+ });
+ await page.goto(server.EMPTY_PAGE);
+ const response = await page.evaluate(() => fetch('/favicon.ico').then(r => r.text()).catch(e => 'load failed'));
+ expect(response).toBe('load failed');
+ // Browsers can send favicon requests in the background.
+ await new Promise(f => setTimeout(f, 1000));
+ expect(requestCount).toBe(0);
+});