Disk cache doesn't work in headless mode
Reported by
ayudaage...@gmail.com,
Jan 3
|
||
Issue description
UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
Steps to reproduce the problem:
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
What is the expected behavior?
What went wrong?
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
Did this work before? N/A
Chrome version: 72.0.3626.28 Channel: beta
OS Version: 10.0
Flash Version: beta Versión 72.0.3626.28 (Build oficial) beta (64 bits)
,
Jan 4
The issue seems to be related to Node JS with Puppeteer which is out of scope for TE, hence adding TE-NeedsTriageHelp label and requesting someone from the dev team to look into the issue and help us in further triaging. Thanks.! |
||
►
Sign in to add a comment |
||
Comment 1 by vamshi.kommuri@chromium.org
, Jan 4