fix: do not report errored pages after context closure (#4346)

Consider the following sequence:
- page opens a popup;
- popup target is attached, we start initializing it;
- user calls browser.close();
- browser is closed, and popup initialization fails;
- we report "errored page" on the already closed context;
- RPC client cannot make sense of this:
  "Cannot find parent object BrowserContext@guid to create Frame@guid"

This issue was revealed during Firefox pipe migration.
This commit is contained in:
Dmitry Gozman 2020-11-04 16:23:38 -08:00 committed by GitHub
parent 4cb52144b5
commit e942138913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 3 deletions

View File

@ -267,6 +267,10 @@ export abstract class BrowserContext extends EventEmitter {
await this._doUpdateRequestInterception();
}
isClosingOrClosed() {
return this._closedStatus !== 'open';
}
async close() {
if (this._closedStatus === 'open') {
this._closedStatus = 'closing';

View File

@ -164,8 +164,13 @@ export class CRBrowser extends Browser {
this._crPages.set(targetInfo.targetId, crPage);
crPage.pageOrError().then(pageOrError => {
const page = crPage._page;
if (pageOrError instanceof Error)
if (pageOrError instanceof Error) {
// Initialization error could have happened because of
// context/browser closure. Just ignore the page.
if (context!.isClosingOrClosed())
return;
page._setIsError();
}
context!.emit(BrowserContext.Events.Page, page);
if (opener) {
opener.pageOrError().then(openerPage => {

View File

@ -108,8 +108,13 @@ export class FFBrowser extends Browser {
ffPage.pageOrError().then(async pageOrError => {
const page = ffPage._page;
if (pageOrError instanceof Error)
if (pageOrError instanceof Error) {
// Initialization error could have happened because of
// context/browser closure. Just ignore the page.
if (context.isClosingOrClosed())
return;
page._setIsError();
}
context.emit(BrowserContext.Events.Page, page);
if (!opener)
return;

View File

@ -156,8 +156,13 @@ export class WKBrowser extends Browser {
wkPage.pageOrError().then(async pageOrError => {
const page = wkPage._page;
if (pageOrError instanceof Error)
if (pageOrError instanceof Error) {
// Initialization error could have happened because of
// context/browser closure. Just ignore the page.
if (context!.isClosingOrClosed())
return;
page._setIsError();
}
context!.emit(BrowserContext.Events.Page, page);
if (!opener)
return;