fix: do not crash upon download in unknown page (#22774)

Fixes #22551.
This commit is contained in:
Dmitry Gozman 2023-05-02 18:49:04 -07:00 committed by GitHub
parent dee0f2791e
commit 3c724c2498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -243,7 +243,12 @@ export class CRBrowser extends Browser {
_onDownloadWillBegin(payload: Protocol.Browser.downloadWillBeginPayload) {
const page = this._findOwningPage(payload.frameId);
assert(page, 'Download started in unknown page: ' + JSON.stringify(payload));
if (!page) {
// There might be no page when download originates from something unusual, like
// a DevTools window or maybe an extension page.
// See https://github.com/microsoft/playwright/issues/22551.
return;
}
page.willBeginDownload();
let originPage = page._initializedPage;

View File

@ -118,8 +118,7 @@ export class FFBrowser extends Browser {
}
_onDownloadCreated(payload: Protocol.Browser.downloadCreatedPayload) {
const ffPage = this._ffPages.get(payload.pageTargetId)!;
assert(ffPage);
const ffPage = this._ffPages.get(payload.pageTargetId);
if (!ffPage)
return;