Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: update error message when using userDataDir arg (#5814)

E095ad6339c6e
diff --git a/src/server/chromium/chromium.ts b/src/server/chromium/chromium.ts
index e9bb4e0671..d2eaf238b5 100644
--- a/src/server/chromium/chromium.ts
+++ b/src/server/chromium/chromium.ts
@@ -119,7 +119,7 @@ export class Chromium extends BrowserType {
const { args = [], proxy } = options;
const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));
if (userDataDirArg)
- throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument');
+ throw new Error('Pass userDataDir parameter to `browserType.launchPersistentContext(userDataDir, ...)` instead of specifying --user-data-dir argument');
if (args.find(arg => arg.startsWith('--remote-debugging-pipe')))
throw new Error('Playwright manages remote debugging connection itself.');
if (args.find(arg => !arg.startsWith('-')))
diff --git a/src/server/firefox/firefox.ts b/src/server/firefox/firefox.ts
index 93fa665a3d..109a2d7a07 100644
--- a/src/server/firefox/firefox.ts
+++ b/src/server/firefox/firefox.ts
@@ -60,7 +60,7 @@ export class Firefox extends BrowserType {
console.warn('devtools parameter is not supported as a launch argument in Firefox. You can launch the devtools window manually.');
const userDataDirArg = args.find(arg => arg.startsWith('-profile') || arg.startsWith('--profile'));
if (userDataDirArg)
- throw new Error('Pass userDataDir parameter instead of specifying -profile argument');
+ throw new Error('Pass userDataDir parameter to `browserType.launchPersistentContext(userDataDir, ...)` instead of specifying --profile argument');
if (args.find(arg => arg.startsWith('-juggler')))
throw new Error('Use the port parameter instead of -juggler argument');
const firefoxUserPrefs = isPersistent ? undefined : options.firefoxUserPrefs;
diff --git a/src/server/webkit/webkit.ts b/src/server/webkit/webkit.ts
index 689edf911b..dbf7bc13f1 100644
--- a/src/server/webkit/webkit.ts
+++ b/src/server/webkit/webkit.ts
@@ -49,9 +49,9 @@ export class WebKit extends BrowserType {
const { args = [], proxy, devtools, headless } = options;
if (devtools)
console.warn('devtools parameter as a launch argument in WebKit is not supported. Also starting Web Inspector manually will terminate the execution in WebKit.');
- const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir='));
+ const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));
if (userDataDirArg)
- throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument');
+ throw new Error('Pass userDataDir parameter to `browserType.launchPersistentContext(userDataDir, ...)` instead of specifying --user-data-dir argument');
if (args.find(arg => !arg.startsWith('-')))
throw new Error('Arguments can not specify page to be opened');
const webkitArguments = ['--inspector-pipe'];
diff --git a/test/browsertype-launch.spec.ts b/test/browsertype-launch.spec.ts
index 2c9fc7c253..92246e26d4 100644
--- a/test/browsertype-launch.spec.ts
+++ b/test/browsertype-launch.spec.ts
@@ -36,6 +36,13 @@ it('should throw if userDataDir option is passed', async ({browserType, browserO
expect(waitError.message).toContain('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
});
+it('should throw if userDataDir is passed as an argument', async ({browserType, browserOptions}) => {
+ let waitError = null;
+ const options = Object.assign({}, browserOptions, {args: ['--user-data-dir=random-path', '--profile=random-path']});
+ await browserType.launch(options).catch(e => waitError = e);
+ expect(waitError.message).toContain('Pass userDataDir parameter to `browserType.launchPersistentContext');
+});
+
it('should throw if port option is passed', async ({browserType, browserOptions}) => {
const options = Object.assign({}, browserOptions, {port: 1234});
const error = await browserType.launch(options).catch(e => e);