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

This commit is contained in:
Yury Semikhatsky 2024-11-18 11:01:39 -08:00 committed by GitHub
parent 150092438f
commit 6d71805f4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 2 deletions

View file

@ -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);

View file

@ -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');
});
});
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);
});