-
Notifications
You must be signed in to change notification settings - Fork 288
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 invalid connect options, when using browserURL #212
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ class PuppeteerEnvironment extends NodeEnvironment { | |
this.global.browser = await puppeteer.connect({ | ||
...config.connect, | ||
...config.launch, | ||
browserURL: undefined, | ||
browserWSEndpoint: wsEndpoint, | ||
}) | ||
|
||
|
@@ -114,16 +115,23 @@ class PuppeteerEnvironment extends NodeEnvironment { | |
} | ||
|
||
async teardown() { | ||
const config = await readConfig() | ||
this.global.page.removeListener('pageerror', handleError) | ||
const { page, context, browser, puppeteerConfig } = this.global | ||
|
||
if (config.browserContext === 'incognito') { | ||
await this.global.context.close() | ||
} else { | ||
await this.global.page.close() | ||
if (page) { | ||
page.removeListener('pageerror', handleError) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be done always, if page is set. Independant of what we want to close. |
||
|
||
await this.global.browser.disconnect() | ||
if (puppeteerConfig.browserContext === 'incognito') { | ||
if (context) { | ||
await context.close() | ||
} | ||
} else if (page) { | ||
await page.close() | ||
} | ||
|
||
if (browser) { | ||
await browser.disconnect() | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh logic would stay the same if you will change lines L120-L132 to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is different: If browserContent === 'incognito' && context, then page.removeListener, wont be called, but that call should only depend on existance of page.
So we must move the page.removeListener call into its own block, leaving us with this:
Normally this also changes the logic of the original block i posted, but since page and context depend on each other, so when browserContent === 'incognito' && context === undefined (because error in setup), it must be page === undefined, because there cant be a page without context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To expand on this: You must have knowledge about the dependency between context & page, to correctly understand the minified if/else you propose, which makes it harder to reason about what happens.