Skip to content

Commit

Permalink
Merge pull request #374 from amtrack/fix/close-tab
Browse files Browse the repository at this point in the history
fix: close tab on retry
  • Loading branch information
amtrack authored Jan 12, 2021
2 parents 0bd0ae8 + f75b1bd commit ec08abd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/browserforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ export default class Browserforce {

// path instead of url
public async openPage(urlPath, options?) {
let page;
const result = await pRetry(
async () => {
await this.resolveDomains();
const page = await this.browser.newPage();
page = await this.browser.newPage();
page.setDefaultNavigationTimeout(
parseInt(process.env.BROWSERFORCE_NAVIGATION_TIMEOUT_MS, 10) || 90000
);
Expand Down Expand Up @@ -140,12 +141,19 @@ export default class Browserforce {
return page;
},
{
onFailedAttempt: error => {
onFailedAttempt: async error => {
if (this.logger) {
this.logger.warn(
`retrying ${error.retriesLeft} more time(s) because of "${error}"`
);
}
if (page) {
try {
await page.close();
} catch (e) {
// not handled
}
}
},
retries: process.env.BROWSERFORCE_RETRY_MAX_RETRIES
? parseInt(process.env.BROWSERFORCE_RETRY_MAX_RETRIES, 10)
Expand Down

0 comments on commit ec08abd

Please sign in to comment.