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.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
refactored.
Petr Patek8e29d234479b
diff --git a/src/puppeteer_pool.js b/src/puppeteer_pool.jsindex c4dd4bc8a..852ddf4e8 100644--- a/src/puppeteer_pool.js+++ b/src/puppeteer_pool.js@@ -339,16 +339,6 @@ class PuppeteerPool {});// This one is done manually in Puppeteerpool.newPage() so that it happens immediately.// browser.on('targetcreated', () => instance.activePages++);- browser.on('targetdestroyed', () => {- if (instance.activePages === 0 && this.retiredInstances[id]) {- // Run this with a delay, otherwise page.close() that initiated this 'targetdestroyed' event- // might fail with "Protocol error (Target.closeTarget): Target closed."- setTimeout(() => {- log.debug('PuppeteerPool: Killing retired browser because it has no active pages', { id });- this._killInstance(instance);- }, PAGE_CLOSE_KILL_TIMEOUT_MILLIS);- }- });}/**@@ -572,6 +562,7 @@ class PuppeteerPool {page.once('close', () => {instance.activePages--;+ this._killInstanceWithNoPages(instance);});return page;@@ -749,6 +740,18 @@ class PuppeteerPool {}}}++ _killInstanceWithNoPages(instance) {+ const { id } = instance;+ if (instance.activePages === 0 && this.retiredInstances[id]) {+ // Run this with a delay, otherwise page.close() that initiated this 'targetdestroyed' event+ // might fail with "Protocol error (Target.closeTarget): Target closed."+ setTimeout(() => {+ log.debug('PuppeteerPool: Killing retired browser because it has no active pages', { id });+ this._killInstance(instance);+ }, PAGE_CLOSE_KILL_TIMEOUT_MILLIS);+ }+ }}export default PuppeteerPool;