question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reuse cache between launches in headless mode

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.3.0
  • Platform / OS version: Linux / CentOS 7.4.1708
  • Node.js version: 8.11.1

What steps will reproduce the problem?

  1. Run the script (userDataDir is expected to be empty)
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    userDataDir: '/tmp/user-data-dir',
    headless: true,
    args: ['--no-sandbox'],
  });

  const page = await browser.newPage();
  const response = await page.goto('https://example.com/');
  console.log(response.fromCache());

  await browser.close();
})();

Console:

false
  1. Run the script for the second time

What is the expected result?

true

What happens instead?

false

Puppeteer works as expected in headfull mode, though.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
blackdemancommented, Jul 10, 2019

The initial script works for me on v1.18.1. But it doesn’t work when request interception is on.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    userDataDir: '/tmp/user-data-dir',
    headless: true,
    args: ['--no-sandbox'],
  });

  const page = await browser.newPage();

  // enable request interception
  await page.setRequestInterception(true);
  page.on('request', request => {
    request.continue();
  });

  const response = await page.goto('https://example.com/');
  console.log(response.fromCache());

  await browser.close();
})();

I have found out that page.setRequestInterception(true) method disables cache. Indeed; there is a test in puppeteer (page.spec.js) which says that page cache ‘should stay disabled when toggling request interception on/off’. @aslushnikov, can you please explain the idea behind that test? Is it safe to manually enable cache when request interception is on?

await page._client.send('Network.setCacheDisabled', {
  cacheDisabled: false
});
10reactions
JohnBrucecommented, Aug 22, 2018

fwiw, still seeing this on puppeteer@1.7.0

Its not the end of the world, but there are use cases where reusing/sharing a cache across multiple browser instances makes sense, so it would be cool if this could be addressed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caching in headless server-side rendering mode
Implement caching in the JavaScript layer. For example, you can: Add memory caching to the Node server to save JSON for a route...
Read more >
Improving Puppeteer Performance - browserless docs
We've found that when using this option you can significantly speed up your existing sessions by having a full cache of all asset...
Read more >
Automatically disable browser cache in chrome while running ...
I am trying to run tests using protractor but ...
Read more >
Web Scraping with a Headless Browser: A Puppeteer Tutorial
We can force Puppeteer to use a custom path for storing data like cookies and cache, which will be reused every time we...
Read more >
Getting Started with Headless Chrome - Chrome Developers
# Starting Headless (CLI). The easiest way to get started with headless mode is to open the Chrome binary from the command line....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found