Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pageOrError): throw in launchPersistentContext if context page errors #5868

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider creating a new error and chaining it with page init error for better stack trace

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