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

This commit is contained in:
Dmitry Gozman 2022-03-07 10:30:53 -08:00 committed by GitHub
parent 5ca7858ace
commit d836ed41d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -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);

View File

@ -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');
});