fix(connect): respect launch options when turning into connect (#20757)
This commit is contained in:
parent
7a093329fa
commit
6e5964cccd
|
|
@ -72,7 +72,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
|
||||||
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
|
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
|
||||||
|
|
||||||
if (this._defaultConnectOptions)
|
if (this._defaultConnectOptions)
|
||||||
return await this._connectInsteadOfLaunching(this._defaultConnectOptions);
|
return await this._connectInsteadOfLaunching(this._defaultConnectOptions, options);
|
||||||
|
|
||||||
const logger = options.logger || this._defaultLaunchOptions?.logger;
|
const logger = options.logger || this._defaultLaunchOptions?.logger;
|
||||||
options = { ...this._defaultLaunchOptions, ...options };
|
options = { ...this._defaultLaunchOptions, ...options };
|
||||||
|
|
@ -90,11 +90,11 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _connectInsteadOfLaunching(connectOptions: ConnectOptions): Promise<Browser> {
|
private async _connectInsteadOfLaunching(connectOptions: ConnectOptions, launchOptions: LaunchOptions): Promise<Browser> {
|
||||||
return this._connect({
|
return this._connect({
|
||||||
wsEndpoint: connectOptions.wsEndpoint,
|
wsEndpoint: connectOptions.wsEndpoint,
|
||||||
headers: {
|
headers: {
|
||||||
'x-playwright-launch-options': JSON.stringify(this._defaultLaunchOptions || {}),
|
'x-playwright-launch-options': JSON.stringify({ ...this._defaultLaunchOptions, ...launchOptions }),
|
||||||
...connectOptions.headers,
|
...connectOptions.headers,
|
||||||
},
|
},
|
||||||
_exposeNetwork: connectOptions._exposeNetwork,
|
_exposeNetwork: connectOptions._exposeNetwork,
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,7 @@ it('should throw if userDataDir option is passed', async ({ browserType }) => {
|
||||||
expect(waitError.message).toContain('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
|
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 ({ mode, browserType }) => {
|
it('should throw if userDataDir is passed as an argument', async ({ browserType }) => {
|
||||||
it.skip(mode === 'service');
|
|
||||||
|
|
||||||
let waitError = null;
|
let waitError = null;
|
||||||
await browserType.launch({ args: ['--user-data-dir=random-path', '--profile=random-path'] } as any).catch(e => waitError = e);
|
await browserType.launch({ args: ['--user-data-dir=random-path', '--profile=random-path'] } as any).catch(e => waitError = e);
|
||||||
expect(waitError.message).toContain('Pass userDataDir parameter to `browserType.launchPersistentContext');
|
expect(waitError.message).toContain('Pass userDataDir parameter to `browserType.launchPersistentContext');
|
||||||
|
|
@ -53,8 +51,7 @@ it('should throw if port option is passed for persistent context', async ({ brow
|
||||||
expect(error.message).toContain('Cannot specify a port without launching as a server.');
|
expect(error.message).toContain('Cannot specify a port without launching as a server.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if page argument is passed', async ({ mode, browserType, browserName }) => {
|
it('should throw if page argument is passed', async ({ browserType, browserName }) => {
|
||||||
it.skip(mode === 'service');
|
|
||||||
it.skip(browserName === 'firefox');
|
it.skip(browserName === 'firefox');
|
||||||
|
|
||||||
let waitError = null;
|
let waitError = null;
|
||||||
|
|
@ -62,7 +59,7 @@ it('should throw if page argument is passed', async ({ mode, browserType, browse
|
||||||
expect(waitError.message).toContain('can not specify page');
|
expect(waitError.message).toContain('can not specify page');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject if launched browser fails immediately', async ({ mode, browserType, asset }) => {
|
it('should reject if launched browser fails immediately', async ({ mode, browserType, asset }) => {
|
||||||
it.skip(mode === 'service');
|
it.skip(mode === 'service');
|
||||||
|
|
||||||
let waitError = null;
|
let waitError = null;
|
||||||
|
|
@ -70,9 +67,7 @@ it('should reject if launched browser fails immediately', async ({ mode, browser
|
||||||
expect(waitError.message).toContain('== logs ==');
|
expect(waitError.message).toContain('== logs ==');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject if executable path is invalid', async ({ browserType, mode }) => {
|
it('should reject if executable path is invalid', async ({ browserType }) => {
|
||||||
it.skip(mode === 'service');
|
|
||||||
|
|
||||||
let waitError = null;
|
let waitError = null;
|
||||||
await browserType.launch({ executablePath: 'random-invalid-path' }).catch(e => waitError = e);
|
await browserType.launch({ executablePath: 'random-invalid-path' }).catch(e => waitError = e);
|
||||||
expect(waitError.message).toContain('Failed to launch');
|
expect(waitError.message).toContain('Failed to launch');
|
||||||
|
|
@ -106,7 +101,9 @@ it('should report launch log', async ({ browserType, mode }) => {
|
||||||
expect(error.message).toContain('<launching>');
|
expect(error.message).toContain('<launching>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should accept objects as options', async ({ browserType }) => {
|
it('should accept objects as options', async ({ mode, browserType }) => {
|
||||||
|
it.skip(mode === 'service');
|
||||||
|
|
||||||
// @ts-expect-error process is not a real option.
|
// @ts-expect-error process is not a real option.
|
||||||
const browser = await browserType.launch({ process });
|
const browser = await browserType.launch({ process });
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue