Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(connect): respect launch options when turning into connect (#20757)

Dmitry Gozman6e5964cccdb0
diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.ts
index 184bbf0089..4c1f6a92c7 100644
--- a/packages/playwright-core/src/client/browserType.ts
+++ b/packages/playwright-core/src/client/browserType.ts
@@ -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.');
if (this._defaultConnectOptions)
- return await this._connectInsteadOfLaunching(this._defaultConnectOptions);
+ return await this._connectInsteadOfLaunching(this._defaultConnectOptions, options);
const logger = options.logger || this._defaultLaunchOptions?.logger;
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({
wsEndpoint: connectOptions.wsEndpoint,
headers: {
- 'x-playwright-launch-options': JSON.stringify(this._defaultLaunchOptions || {}),
+ 'x-playwright-launch-options': JSON.stringify({ ...this._defaultLaunchOptions, ...launchOptions }),
...connectOptions.headers,
},
_exposeNetwork: connectOptions._exposeNetwork,
diff --git a/tests/library/browsertype-launch.spec.ts b/tests/library/browsertype-launch.spec.ts
index fe0f16b738..3596ca47b2 100644
--- a/tests/library/browsertype-launch.spec.ts
+++ b/tests/library/browsertype-launch.spec.ts
@@ -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');
});
-it('should throw if userDataDir is passed as an argument', async ({ mode, browserType }) => {
- it.skip(mode === 'service');
-
+it('should throw if userDataDir is passed as an argument', async ({ browserType }) => {
let waitError = null;
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');
@@ -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.');
});
-it('should throw if page argument is passed', async ({ mode, browserType, browserName }) => {
- it.skip(mode === 'service');
+it('should throw if page argument is passed', async ({ browserType, browserName }) => {
it.skip(browserName === 'firefox');
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');
});
-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');
let waitError = null;
@@ -70,9 +67,7 @@ it('should reject if launched browser fails immediately', async ({ mode, browser
expect(waitError.message).toContain('== logs ==');
});
-it('should reject if executable path is invalid', async ({ browserType, mode }) => {
- it.skip(mode === 'service');
-
+it('should reject if executable path is invalid', async ({ browserType }) => {
let waitError = null;
await browserType.launch({ executablePath: 'random-invalid-path' }).catch(e => waitError = e);
expect(waitError.message).toContain('Failed to launch');
@@ -106,7 +101,9 @@ it('should report launch log', async ({ browserType, mode }) => {
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.
const browser = await browserType.launch({ process });
await browser.close();