Skip to content

Commit

Permalink
fix(launch): throw upon page argument when non-persistent (#1144)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Feb 27, 2020
1 parent 9d6aa96 commit dc161df
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/server/chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export class Chromium implements BrowserType {
throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument');
if (args.find(arg => arg.startsWith('--remote-debugging-')))
throw new Error('Playwright manages remote debugging connection itself.');
if (launchType !== 'persistent' && args.find(arg => !arg.startsWith('-')))
throw new Error('Arguments can not specify page to be opened');

const chromeArguments = [...DEFAULT_ARGS];
chromeArguments.push(`--user-data-dir=${userDataDir}`);
Expand Down
14 changes: 8 additions & 6 deletions src/server/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Firefox implements BrowserType {
return browserContext;
}

private async _launchServer(options: LaunchOptions = {}, connectionType: LaunchType, userDataDir?: string, port?: number): Promise<{ browserServer: BrowserServer, transport?: ConnectionTransport }> {
private async _launchServer(options: LaunchOptions = {}, launchType: LaunchType, userDataDir?: string, port?: number): Promise<{ browserServer: BrowserServer, transport?: ConnectionTransport }> {
const {
ignoreDefaultArgs = false,
args = [],
Expand All @@ -107,9 +107,9 @@ export class Firefox implements BrowserType {
}

if (!ignoreDefaultArgs)
firefoxArguments.push(...this._defaultArgs(options, userDataDir!, port || 0));
firefoxArguments.push(...this._defaultArgs(options, launchType, userDataDir!, port || 0));
else if (Array.isArray(ignoreDefaultArgs))
firefoxArguments.push(...this._defaultArgs(options, userDataDir!, port || 0).filter(arg => !ignoreDefaultArgs.includes(arg)));
firefoxArguments.push(...this._defaultArgs(options, launchType, userDataDir!, port || 0).filter(arg => !ignoreDefaultArgs.includes(arg)));
else
firefoxArguments.push(...args);

Expand Down Expand Up @@ -155,8 +155,8 @@ export class Firefox implements BrowserType {
const timeoutError = new TimeoutError(`Timed out after ${timeout} ms while trying to connect to Firefox!`);
const match = await waitForLine(launchedProcess, launchedProcess.stdout, /^Juggler listening on (ws:\/\/.*)$/, timeout, timeoutError);
const browserWSEndpoint = match[1];
browserServer = new BrowserServer(launchedProcess, gracefullyClose, connectionType === 'server' ? browserWSEndpoint : null);
return { browserServer, transport: connectionType === 'server' ? undefined : new platform.WebSocketTransport(browserWSEndpoint) };
browserServer = new BrowserServer(launchedProcess, gracefullyClose, launchType === 'server' ? browserWSEndpoint : null);
return { browserServer, transport: launchType === 'server' ? undefined : new platform.WebSocketTransport(browserWSEndpoint) };
}

async connect(options: ConnectOptions): Promise<FFBrowser> {
Expand All @@ -176,7 +176,7 @@ export class Firefox implements BrowserType {
return { TimeoutError };
}

private _defaultArgs(options: BrowserArgOptions = {}, userDataDir: string, port: number): string[] {
private _defaultArgs(options: BrowserArgOptions = {}, launchType: LaunchType, userDataDir: string, port: number): string[] {
const {
devtools = false,
headless = !devtools,
Expand All @@ -189,6 +189,8 @@ export class Firefox implements BrowserType {
throw new Error('Pass userDataDir parameter instead of specifying -profile argument');
if (args.find(arg => arg.startsWith('-juggler')))
throw new Error('Use the port parameter instead of -juggler argument');
if (launchType !== 'persistent' && args.find(arg => !arg.startsWith('-')))
throw new Error('Arguments can not specify page to be opened');

const firefoxArguments = ['-no-remote'];
if (headless) {
Expand Down
2 changes: 2 additions & 0 deletions src/server/webkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ export class WebKit implements BrowserType {
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');
if (launchType !== 'persistent' && args.find(arg => !arg.startsWith('-')))
throw new Error('Arguments can not specify page to be opened');
const webkitArguments = ['--inspector-pipe'];
if (headless)
webkitArguments.push('--headless');
Expand Down
6 changes: 6 additions & 0 deletions test/launcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
await playwright.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('launchPersistent');
});
it('should throw if page argument is passed', async() => {
let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, { args: ['http://example.com'] });
await playwright.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('can not specify page');
});
it('should reject if executable path is invalid', async({server}) => {
let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});
Expand Down

0 comments on commit dc161df

Please sign in to comment.