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.

Bugfix in PuppeteerPool: Pages were sometimes considered closed even though they weren't

Jan Curn21d292f36357
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4e332d07a..65b9f35df 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+xxx
+===================
+- Bugfix in `PuppeteerPool`: Pages were sometimes considered closed even though they weren't
+- Improvements in documentation
+
0.8.14 / 2018-10-11
===================
- Added `Apify.utils.puppeteer.cacheResponses` to enable response caching in headless Chromium.
diff --git a/src/puppeteer_pool.js b/src/puppeteer_pool.js
index be016e675..4f697862e 100644
--- a/src/puppeteer_pool.js
+++ b/src/puppeteer_pool.js
@@ -224,7 +224,11 @@ export default class PuppeteerPool {
});
// This one is done manually in Puppeteerpool.newPage() so that it happens immediately.
// browser.on('targetcreated', () => instance.activePages++);
- browser.on('targetdestroyed', () => {
+ browser.on('targetdestroyed', (target) => {
+ // The event is also called for service workers and Chromium extensions, which must be ignored!
+ const type = target.type();
+ if (type !== 'page' && type !== 'other') return;
+
instance.activePages--;
if (instance.activePages === 0 && this.retiredInstances[id]) {