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 back the recycleDiskCache option to PuppeteerPool now that the support is coming even in headless Chrome

Jan Curn842d0d2207a9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4d3f442c7..ae1159352 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+next
+===================
+- Added back the `recycleDiskCache` option to `PuppeteerPool` now that it is supported
+ even in headless mode ([read more](https://bugs.chromium.org/p/chromium/issues/detail?id=882431))
+
xxx
===================
- **BREAKING CHANGE:** Reduced default `handlePageTimeoutSecs` for both `CheerioCrawler` and `PuppeteerCrawler` from 300 to 60 seconds,
diff --git a/src/puppeteer_pool.js b/src/puppeteer_pool.js
index 37847bb73..f5b6050c4 100644
--- a/src/puppeteer_pool.js
+++ b/src/puppeteer_pool.js
@@ -149,13 +149,10 @@ class PuppeteerPool {
instanceKillerIntervalMillis,
killInstanceAfterMillis,
launchPuppeteerOptions,
- // recycleDiskCache,
+ recycleDiskCache,
proxyUrls,
} = _.defaults({}, options, DEFAULT_OPTIONS);
- // Disabling the feature since tests started failing.
- // Re-enable once the issues upstream are fixed.
- const recycleDiskCache = false;
// Disabling due to memory leak.
const reusePages = false;
@@ -171,15 +168,6 @@ class PuppeteerPool {
// Enforce non-empty proxyUrls array
if (proxyUrls && !proxyUrls.length) throw new Error('Parameter "options.proxyUrls" of type Array must not be empty');
- // The recycleDiskCache option is only supported in headful mode
- // See https://bugs.chromium.org/p/chromium/issues/detail?id=882431
- if (recycleDiskCache
- && ((!launchPuppeteerOptions
- || (launchPuppeteerOptions && launchPuppeteerOptions.headless)
- || (launchPuppeteerOptions && launchPuppeteerOptions.headless === undefined && !launchPuppeteerOptions.devtools)))) {
- log.warning('PuppeteerPool: The "recycleDiskCache" is currently only supported in headful mode. Disk cache will not be recycled.');
- }
-
// Config.
this.reusePages = reusePages;
this.maxOpenPagesPerInstance = maxOpenPagesPerInstance;
diff --git a/test/puppeteer_pool.js b/test/puppeteer_pool.js
index 8e40102b9..550221b3b 100644
--- a/test/puppeteer_pool.js
+++ b/test/puppeteer_pool.js
@@ -232,16 +232,12 @@ describe('PuppeteerPool', () => {
// Test started failing on 6.10.2018. Probably some change upstream.
// Disabling the feature until resolved.
- xit('supports recycleDiskCache option', async () => {
- // NOTE: This feature only works in headful mode now
- // See https://bugs.chromium.org/p/chromium/issues/detail?id=882431
- const isMacOs = process.platform === 'darwin';
-
+ it('supports recycleDiskCache option', async () => {
const pool = new Apify.PuppeteerPool({
maxOpenPagesPerInstance: 1,
retireInstanceAfterRequestCount: 1,
recycleDiskCache: true,
- launchPuppeteerOptions: { headless: !isMacOs },
+ launchPuppeteerOptions: { headless: true },
});
// log.setLevel(log.LEVELS.DEBUG);
@@ -251,6 +247,8 @@ describe('PuppeteerPool', () => {
const page1 = await pool.newPage();
const dir1 = page1.browser().recycleDiskCacheDir;
+ console.log(dir1);
+
expect(fs.existsSync(dir1)).to.be.eql(true);
// First time, nothing can come from disk cache
@@ -297,9 +295,7 @@ describe('PuppeteerPool', () => {
const cookies2after = await page2.cookies(url);
expect(cookies2after.length).to.be.at.least(1);
- if (isMacOs) {
- expect(fromDiskCache2).to.be.at.least(1);
- }
+ expect(fromDiskCache2).to.be.at.least(1);
// Open third browser while second is still open, it should use a new cache directory
const page3 = await pool.newPage();