Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse cache between launches in headless mode #2497

Closed
blackdeman opened this issue May 3, 2018 · 9 comments
Closed

Reuse cache between launches in headless mode #2497

blackdeman opened this issue May 3, 2018 · 9 comments
Labels
bug chromium Issues with Puppeteer-Chromium upstream

Comments

@blackdeman
Copy link

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.

@andrewsezko
Copy link

@blackdeman If that case is critical for you, you can simply clear cache and cookies before opening the same page in a new browser instance.

@korya
Copy link

korya commented Jun 6, 2018

We are experiencing the same issue with puppeteer@1.4.0.

@JohnBruce
Copy link

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.

@aslushnikov aslushnikov added the chromium Issues with Puppeteer-Chromium label Dec 6, 2018
@yegor211
Copy link

yegor211 commented Mar 2, 2019

so is this still not possible in headless?

@wtip
Copy link

wtip commented Mar 29, 2019

This seems to be working on v1.14.0 based on my own tests. It wasn't working on 1.9.0

@aslushnikov
Copy link
Contributor

Indeed; works for me on v1.14.0.

@Supamiu
Copy link

Supamiu commented May 16, 2019

I managed to reproduce the issue with v1.16.0 using the following code:

const puppeteer = require('puppeteer');

async function test() {
    const browser = await puppeteer.launch({headless: true, args: ['--no-sandbox']});
    const page = await browser.newPage();
    const response = await page.goto('https://example.org');

    console.log(response.fromCache());

    await browser.close();
}

test();
  • Puppeteer version: 1.16.0
  • Platform / OS version: Windows 10 Pro v1803 - Build #17134.765
  • Node.js version: 10.15.3

Edit: Same on v1.14.0.

@blackdeman
Copy link
Author

blackdeman commented 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
});

@blackdeman
Copy link
Author

Similar questions are being asked in #4620

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug chromium Issues with Puppeteer-Chromium upstream
Projects
None yet
Development

No branches or pull requests

8 participants