further fix to stuck on getting new window: (#779)

- set retries back to 3, was set high by mistake
- if will restart, throw exception to restart crawler
- otherwise, attempt to kill browser process that is stalled (appears to
work in testing)
- follow-up to #766
This commit is contained in:
Ilya Kreymer 2025-02-26 12:32:05 -08:00 committed by GitHub
parent e402ddc202
commit 24ca818356
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View file

@ -396,6 +396,18 @@ export class Browser {
}
}
killBrowser() {
// used when main browser process appears to be stalled
// puppeteer should still be able to continue, from initial testing
// and avoids interrupting crawler when not auto-restarting
if (this.browser) {
const proc = this.browser.process();
if (proc) {
proc.kill();
}
}
}
async addInitScript(page: Page, script: string) {
await page.evaluateOnNewDocument(script);
}

View file

@ -231,9 +231,13 @@ export class PageWorker {
break;
}
if (retry >= 1000000000) {
if (retry >= 2) {
this.crawler.markBrowserCrashed();
throw new Error("Unable to load new page, browser needs restart");
if (this.crawler.params.restartsOnError) {
throw new Error("Unable to load new page, browser needs restart");
} else {
this.crawler.browser.killBrowser();
}
}
await sleep(0.5);