Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

Added await to fix the target closed error.

Petr Patek60a85c744e16
diff --git a/src/puppeteer_pool.js b/src/puppeteer_pool.js
index 6e3634bf2..58e717cf3 100644
--- a/src/puppeteer_pool.js
+++ b/src/puppeteer_pool.js
@@ -512,7 +512,7 @@ class PuppeteerPool {
this.puppeteerOperationTimeoutMillis,
'PuppeteerPool: browser.newPage() timed out.',
);
- this._focusOldestTab(browser).catch(() => log.debug('Could not focus oldest tab.'));
+ await this._focusOldestTab(browser).catch(() => log.debug('Could not focus oldest tab.'));
this.pagesToInstancesMap.set(page, instance);
return this._decoratePage(page);
} catch (err) {