feat: do not let users pass userDataDir to browserType.launch()

We now have a separate method for this - `browserType.launchPersistent`.
This commit is contained in:
Andrey Lushnikov 2020-02-12 19:12:54 -08:00
parent b188f397cf
commit 7850a70e19
4 changed files with 12 additions and 0 deletions

View file

@ -50,6 +50,8 @@ export class Chromium implements BrowserType {
}
async launch(options?: LaunchOptions & { slowMo?: number }): Promise<CRBrowser> {
if (options && options.userDataDir)
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead');
const { browserServer, transport } = await this._launchServer(options, 'local');
const browser = await CRBrowser.connect(transport!, options && options.slowMo);
// Hack: for typical launch scenario, ensure that close waits for actual process termination.

View file

@ -60,6 +60,8 @@ export class Firefox implements BrowserType {
}
async launch(options?: LaunchOptions & { slowMo?: number }): Promise<FFBrowser> {
if (options && options.userDataDir)
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead');
const { browserServer, transport } = await this._launchServer(options, 'local');
const browser = await FFBrowser.connect(transport!, options && options.slowMo);
// Hack: for typical launch scenario, ensure that close waits for actual process termination.

View file

@ -62,6 +62,8 @@ export class WebKit implements BrowserType {
}
async launch(options?: LaunchOptions & { slowMo?: number }): Promise<WKBrowser> {
if (options && options.userDataDir)
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead');
const { browserServer, transport } = await this._launchServer(options, 'local');
const browser = await WKBrowser.connect(transport!, options && options.slowMo);
// Hack: for typical launch scenario, ensure that close waits for actual process termination.

View file

@ -39,6 +39,12 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
await neverResolves;
expect(error.message).toContain('Protocol error');
});
it('should throw if userDataDir option is passed', async() => {
let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {userDataDir: 'random-path'});
await playwright.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('launchPersistent');
});
it('should reject if executable path is invalid', async({server}) => {
let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});