mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-13 17:14:02 +03:00
fix(launch): throw upon page argument when non-persistent (#1144)
This commit is contained in:
parent
9d6aa967f3
commit
dc161df063
@ -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}`);
|
||||
|
@ -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 = [],
|
||||
@ -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);
|
||||
|
||||
@ -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> {
|
||||
@ -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,
|
||||
@ -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) {
|
||||
|
@ -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');
|
||||
|
@ -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'});
|
||||
|
Loading…
Reference in New Issue
Block a user