Skip to content

Commit

Permalink
fix(pageOrError): throw in launchPersistentContext if context page ha…
Browse files Browse the repository at this point in the history
…s errors (#5868)
  • Loading branch information
pavelfeldman authored Mar 18, 2021
1 parent bb21faf commit d53cea7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/server/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ export abstract class BrowserContext extends SdkObject {
if (!this.pages().length) {
const waitForEvent = helper.waitForEvent(progress, this, BrowserContext.Events.Page);
progress.cleanupWhenAborted(() => waitForEvent.dispose);
await waitForEvent.promise;
const page = (await waitForEvent.promise) as Page;
if (page._pageIsError)
throw page._pageIsError;
}
const pages = this.pages();
if (pages[0]._pageIsError)
throw pages[0]._pageIsError;
await pages[0].mainFrame()._waitForLoadState(progress, 'load');
return pages;
}
Expand Down
6 changes: 4 additions & 2 deletions src/server/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export class Page extends SdkObject {
readonly selectors: Selectors;
_video: Video | null = null;
readonly uniqueId: string;
_pageIsError: Error | undefined;

constructor(delegate: PageDelegate, browserContext: BrowserContext) {
super(browserContext);
Expand Down Expand Up @@ -187,7 +188,7 @@ export class Page extends SdkObject {
// context/browser closure. Just ignore the page.
if (this._browserContext.isClosingOrClosed())
return;
this._setIsError();
this._setIsError(pageOrError);
}
this._browserContext.emit(BrowserContext.Events.Page, this);
const openerDelegate = this._delegate.openerDelegate();
Expand Down Expand Up @@ -444,7 +445,8 @@ export class Page extends SdkObject {
await this._ownedContext.close(metadata);
}

private _setIsError() {
private _setIsError(error: Error) {
this._pageIsError = error;
if (!this._frameManager.mainFrame())
this._frameManager.frameAttached('<dummy>', null);
}
Expand Down
1 change: 0 additions & 1 deletion test/page-event-popup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,3 @@ it('should not treat navigations as new popups', async ({context, server}) => {
await context.close();
expect(badSecondPopup).toBe(false);
});

0 comments on commit d53cea7

Please sign in to comment.