Skip to content

Commit d735de5

Browse files
authored
feat: do not let users pass userDataDir to browserType.launch() (#974)
We now have a separate method for this - `browserType.launchPersistent`. This will probably save our users quite some time.
1 parent b7f48f4 commit d735de5

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

src/server/chromium.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export class Chromium implements BrowserType {
5050
}
5151

5252
async launch(options?: LaunchOptions & { slowMo?: number }): Promise<CRBrowser> {
53+
if (options && (options as any).userDataDir)
54+
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead');
5355
const { browserServer, transport } = await this._launchServer(options, 'local');
5456
const browser = await CRBrowser.connect(transport!, options && options.slowMo);
5557
// Hack: for typical launch scenario, ensure that close waits for actual process termination.

src/server/firefox.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export class Firefox implements BrowserType {
6060
}
6161

6262
async launch(options?: LaunchOptions & { slowMo?: number }): Promise<FFBrowser> {
63+
if (options && (options as any).userDataDir)
64+
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead');
6365
const { browserServer, transport } = await this._launchServer(options, 'local');
6466
const browser = await FFBrowser.connect(transport!, options && options.slowMo);
6567
// Hack: for typical launch scenario, ensure that close waits for actual process termination.

src/server/webkit.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export class WebKit implements BrowserType {
6262
}
6363

6464
async launch(options?: LaunchOptions & { slowMo?: number }): Promise<WKBrowser> {
65+
if (options && (options as any).userDataDir)
66+
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead');
6567
const { browserServer, transport } = await this._launchServer(options, 'local');
6668
const browser = await WKBrowser.connect(transport!, options && options.slowMo);
6769
// Hack: for typical launch scenario, ensure that close waits for actual process termination.

test/launcher.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
3939
await neverResolves;
4040
expect(error.message).toContain('Protocol error');
4141
});
42+
it('should throw if userDataDir option is passed', async() => {
43+
let waitError = null;
44+
const options = Object.assign({}, defaultBrowserOptions, {userDataDir: 'random-path'});
45+
await playwright.launch(options).catch(e => waitError = e);
46+
expect(waitError.message).toContain('launchPersistent');
47+
});
4248
it('should reject if executable path is invalid', async({server}) => {
4349
let waitError = null;
4450
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});

0 commit comments

Comments
 (0)