Navigation Menu

Skip to content

Commit

Permalink
fix: regression in --user-data-dir handling (#8060)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Feb 23, 2022
1 parent 7e1794c commit 85decdc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/node/Launcher.ts
Expand Up @@ -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(
Expand Down
25 changes: 25 additions & 0 deletions test/launcher.spec.ts
Expand Up @@ -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();

Expand Down

0 comments on commit 85decdc

Please sign in to comment.