Skip to content

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

feat(remote): send 'x-playwright-browser' header (#12556)

Dmitry Gozmand836ed41d352
diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.ts
index 2ed3cb4186..84eec92d4c 100644
--- a/packages/playwright-core/src/client/browserType.ts
+++ b/packages/playwright-core/src/client/browserType.ts
@@ -128,7 +128,8 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
return await this._wrapApiCall(async () => {
const deadline = params.timeout ? monotonicTime() + params.timeout : 0;
let browser: Browser;
- const connectParams: channels.BrowserTypeConnectParams = { wsEndpoint, headers: params.headers, slowMo: params.slowMo, timeout: params.timeout };
+ const headers = { 'x-playwright-browser': this.name(), ...params.headers };
+ const connectParams: channels.BrowserTypeConnectParams = { wsEndpoint, headers, slowMo: params.slowMo, timeout: params.timeout };
if ((params as any).__testHookRedirectPortForwarding)
connectParams.socksProxyRedirectPortForTest = (params as any).__testHookRedirectPortForwarding;
const { pipe } = await this._channel.connect(connectParams);
diff --git a/tests/browsertype-connect.spec.ts b/tests/browsertype-connect.spec.ts
index 2458bb7a6d..08aba2a8f9 100644
--- a/tests/browsertype-connect.spec.ts
+++ b/tests/browsertype-connect.spec.ts
@@ -134,7 +134,7 @@ test('should send extra headers with connect request', async ({ browserType, sta
expect(request.headers['foo']).toBe('bar');
});
-test('should send default User-Agent header with connect request', async ({ browserType, startRemoteServer, server }) => {
+test('should send default User-Agent and X-Playwright-Browser headers with connect request', async ({ browserType, browserName, server }) => {
const [request] = await Promise.all([
server.waitForWebSocketConnectionRequest(),
browserType.connect({
@@ -146,6 +146,7 @@ test('should send default User-Agent header with connect request', async ({ brow
}).catch(() => {})
]);
expect(request.headers['user-agent']).toBe(getUserAgent());
+ expect(request.headers['x-playwright-browser']).toBe(browserName);
expect(request.headers['foo']).toBe('bar');
});