fix(chromium): do not cancel downloads when intercepting (#27638)

Fixes #27575.
This commit is contained in:
Dmitry Gozman 2023-10-16 15:12:52 -07:00 committed by GitHub
parent fd2fbe9d2f
commit e8b4c03e54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View file

@ -189,12 +189,8 @@ export class CRNetworkManager {
_onRequestPaused(sessionInfo: SessionInfo, event: Protocol.Fetch.requestPausedPayload) {
if (!event.networkId) {
// Fetch without networkId means that request was not recognized by inspector, and
// it will never receive Network.requestWillBeSent. Most likely, this is an internal request
// that we can safely fail.
this._session._sendMayFail('Fetch.failRequest', {
requestId: event.requestId,
errorReason: 'Aborted',
});
// it will never receive Network.requestWillBeSent. Continue the request to not affect it.
this._session._sendMayFail('Fetch.continueRequest', { requestId: event.requestId });
return;
}
if (event.request.url.startsWith('data:'))

View file

@ -714,6 +714,21 @@ it('should download links with data url', async ({ page }) => {
expect(download.suggestedFilename()).toBe('SomeFile.txt');
});
it('should download successfully when routing', async ({ browser, server }) => {
const page = await browser.newPage();
await page.context().route('**/*', route => route.continue());
await page.goto(server.PREFIX + '/empty.html');
await page.setContent(`<a href="${server.PREFIX}/chromium-linux.zip" download="foo.zip">download</a>`);
const [download] = await Promise.all([
page.waitForEvent('download'),
page.click('a')
]);
expect(download.suggestedFilename()).toBe('foo.zip');
expect(download.url()).toBe(`${server.PREFIX}/chromium-linux.zip`);
expect(await download.failure()).toBe(null);
await page.close();
});
async function assertDownloadToPDF(download: Download, filePath: string) {
expect(download.suggestedFilename()).toBe(path.basename(filePath));
const stream = await download.createReadStream();