New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 882431 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Last visit 28 days ago
Closed: Dec 3
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug

Blocking:
issue 705916



Sign in to add a comment

Disk cache doesn't work in headless mode

Reported by jan.c...@gmail.com, Sep 10

Issue description

Chrome Version       : Version 71.0.3542.0 (Developer Build) (64-bit) 
URLs (if applicable) : N/A
Other browsers tested: N/A

The --disk-cache-dir option only works in headful mode, not in headless mode. Even if you use --user-data-dir, the "Cache" directory is not created. This is problematic if you want to use headless Chrome for web crawling or large website, e.g. for SEO analysis.

What steps will reproduce the problem?

Run the following code in Node.js with Puppeteer:

const puppeteer = require('puppeteer');
const rimraf = require('rimraf');
const childProcess = require('child_process');

const showDir = (path) => {
    try {
        childProcess.execSync(`find ${path} -type f`, { stdio: [0, 1, 2] });
    } catch (e) {
        console.error(`Command failed: ${e}`);
    }
};

(async () => {
    // Test in HEADFUL mode
    rimraf.sync('./cache1');
    const browser1 = await puppeteer.launch({
        args: ['--disk-cache-dir=./cache1'],
        headless: false,
    });
    const page1 = await browser1.newPage();
    console.log('\nHEADFUL BROWSER (BEFORE LOAD):');
    showDir('./cache1');
    await page1.goto('https://www.wikipedia.org');
    console.log('\nHEADFUL BROWSER (AFTER LOAD):');
    showDir('./cache1');
    await browser1.close();

    // Test in HEADLESS mode
    rimraf.sync('./cache2');
    const browser2 = await puppeteer.launch({
        args: ['--disk-cache-dir=./cache2'],
        headless: true,
    });
    const page2 = await browser2.newPage();
    console.log('\nHEADLESS BROWSER (BEFORE LOAD):');
    showDir('./cache2');
    await page2.goto('https://www.wikipedia.org');
    console.log('\nHEADLESS BROWSER (AFTER LOAD):');
    showDir('./cache2');
    await browser2.close();
})();


What is the expected result?

Both headless and headful browser should create and use a directory with disk cache data.

What happens instead?

The disk cache directory is only created in headful mode. The above script prints the following info:

HEADFUL BROWSER (BEFORE LOAD):
./cache1/Default/Cache/index
./cache1/Default/Cache/index-dir/the-real-index

HEADFUL BROWSER (AFTER LOAD):
./cache1/Default/Cache/01e4be952e168d09_0
./cache1/Default/Cache/01e4be952e168d09_1
./cache1/Default/Cache/1069d28c82a80b2b_0
./cache1/Default/Cache/335013cf3c4ddcdc_0
./cache1/Default/Cache/3a8cf1a5b9c24c08_0
./cache1/Default/Cache/40d117288ba98572_0
./cache1/Default/Cache/58c17ba051c7f219_0
./cache1/Default/Cache/74aea27da05a7b9c_0
./cache1/Default/Cache/c5c3241e7f822146_0
./cache1/Default/Cache/f19b3fc2ab4ce672_0
./cache1/Default/Cache/index
./cache1/Default/Cache/index-dir/the-real-index

HEADLESS BROWSER (BEFORE LOAD):
find: ./cache2: No such file or directory
Command failed: Error: Command failed: find ./cache2 -type f

HEADLESS BROWSER (AFTER LOAD):
find: ./cache2: No such file or directory
Command failed: Error: Command failed: find ./cache2 -type f


 
Labels: Needs-Triage-M71
Any update?
Owner: lushnikov@chromium.org
Status: Assigned (was: Unconfirmed)
Turns out disk cache is not enabled in headless default profile at all - this will be fixed with https://chromium-review.googlesource.com/c/chromium/src/+/1350881/

If disk cache flag is required, we can plumb it through as well.
Project Member

Comment 5 by bugdroid1@chromium.org, Nov 27

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/455e608c34ac81478c758e5be65eba370ea75220

commit 455e608c34ac81478c758e5be65eba370ea75220
Author: Andrey Lushnikov <lushnikov@chromium.org>
Date: Tue Nov 27 18:56:02 2018

Headless: enable disk cache for default profile

Start using disk cache directory for default headless profile.

Bug:  882431 
Change-Id: I1790a58fa2da6cb0fd114897d082e289d7a01bc5
Reviewed-on: https://chromium-review.googlesource.com/c/1350881
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611230}
[modify] https://crrev.com/455e608c34ac81478c758e5be65eba370ea75220/headless/lib/browser/headless_request_context_manager.cc

Project Member

Comment 6 by bugdroid1@chromium.org, Dec 3

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/f43d70bee5a774be70f990aeed47bd254d866546

commit f43d70bee5a774be70f990aeed47bd254d866546
Author: Andrey Lushnikov <lushnikov@chromium.org>
Date: Mon Dec 03 22:41:50 2018

headless: support --disk-cache-dir flag

The --disk-cache-dir flag allows to use custom disk cache folder instead
of using the one inferred from user data directory.

BUG= 882431 
R=caseq

Change-Id: I2da7e1c4b72eda32bccf6851c66ce44c1aaa837d
Reviewed-on: https://chromium-review.googlesource.com/c/1359038
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613297}
[modify] https://crrev.com/f43d70bee5a774be70f990aeed47bd254d866546/headless/app/headless_shell_switches.cc
[modify] https://crrev.com/f43d70bee5a774be70f990aeed47bd254d866546/headless/app/headless_shell_switches.h
[modify] https://crrev.com/f43d70bee5a774be70f990aeed47bd254d866546/headless/lib/browser/headless_request_context_manager.cc

Status: Fixed (was: Assigned)

Comment 8 Deleted

Sign in to add a comment