Skip to content

Commit

Permalink
Relative User data dir (#241)
Browse files Browse the repository at this point in the history
Fixes #239
  • Loading branch information
xvrh authored Jun 13, 2023
1 parent e1924e4 commit 00899d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 3.1.0
- Update to Chrome 114
- Fix a bug on Windows when a relative directory was passed to `userDataDir`

## 3.0.0
- Download "Chrome for Testing" instead of Chromium.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/puppeteer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ class Puppeteer {

return [
..._defaultArgs,
if (userDataDir != null) '--user-data-dir=$userDataDir',
if (userDataDir != null)
'--user-data-dir=${p.join(Directory.current.path, userDataDir)}',
if (noSandboxFlag) '--no-sandbox',
if (devTools) '--auto-open-devtools-for-tabs',
if (headless) ..._headlessArgs,
Expand Down
23 changes: 18 additions & 5 deletions test/launcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,30 @@ void main() {
} finally {
_tryDeleteDirectory(userDataDir);
}
}, onPlatform: {
'windows': Skip(
'This mysteriously fails on Windows. See https://github.com/GoogleChrome/puppeteer/issues/4111')
});
test('userDataDir with relative path', () async {
for (var headlessMode in [true, false]) {
var dir = '_user_data_dir_${DateTime.now().microsecondsSinceEpoch}';
try {
var browser = await puppeteer.launch(
userDataDir: dir, headless: headlessMode);
await browser.newPage();
await browser.close();
expect(Directory(dir).existsSync(), true);
} finally {
_tryDeleteDirectory(Directory(dir));
}
}
});
test('should return the default arguments', () {
expect(puppeteer.defaultArgs(), contains('--no-first-run'));
expect(puppeteer.defaultArgs(), contains('--headless'));
expect(puppeteer.defaultArgs(headless: false),
isNot(contains('--headless')));
expect(puppeteer.defaultArgs(userDataDir: 'foo'),
contains('--user-data-dir=foo'));
expect(
puppeteer.defaultArgs(userDataDir: 'foo'),
contains(
'--user-data-dir=${Uri.base.resolve('foo').toFilePath()}'));
});
test('should work with no default arguments', () async {
var browser = await puppeteer.launch(ignoreDefaultArgs: true);
Expand Down

0 comments on commit 00899d8

Please sign in to comment.