fix: regression in --user-data-dir handling (#8060)

This commit is contained in:
Alex Rudenko 2022-02-23 20:21:17 +01:00 committed by GitHub
parent 7e1794cdb2
commit 85decdc28d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -123,10 +123,6 @@ class ChromeLauncher implements ProductLauncher {
if (userDataDirIndex !== -1) {
userDataDir = chromeArguments[userDataDirIndex].split('=')[1];
if (!fs.existsSync(userDataDir)) {
throw new Error(`Chrome user data dir not found at '${userDataDir}'`);
}
isTempUserDataDir = false;
} else {
userDataDir = await mkdtempAsync(

View File

@ -276,6 +276,31 @@ describe('Launcher specs', function () {
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
await rmAsync(userDataDir).catch(() => {});
});
itChromeOnly('userDataDir argument with non-existent dir', async () => {
const { isChrome, puppeteer, defaultBrowserOptions } = getTestState();
const userDataDir = await mkdtempAsync(TMP_FOLDER);
await rmAsync(userDataDir);
const options = Object.assign({}, defaultBrowserOptions);
if (isChrome) {
options.args = [
...(defaultBrowserOptions.args || []),
`--user-data-dir=${userDataDir}`,
];
} else {
options.args = [
...(defaultBrowserOptions.args || []),
'-profile',
userDataDir,
];
}
const browser = await puppeteer.launch(options);
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
await browser.close();
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
await rmAsync(userDataDir).catch(() => {});
});
it('userDataDir option should restore state', async () => {
const { server, puppeteer, defaultBrowserOptions } = getTestState();