feat(fetch): send Playwright as default user-agent for global fetch (#9195)

This commit is contained in:
Yury Semikhatsky 2021-09-28 13:01:35 -07:00 committed by GitHub
parent ed9b42a92d
commit 64657c3b65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -23,7 +23,7 @@ import zlib from 'zlib';
import { HTTPCredentials } from '../../types/types';
import { NameValue, NewRequestOptions } from '../common/types';
import { TimeoutSettings } from '../utils/timeoutSettings';
import { createGuid, isFilePayload, monotonicTime } from '../utils/utils';
import { createGuid, getPlaywrightVersion, isFilePayload, monotonicTime } from '../utils/utils';
import { BrowserContext } from './browserContext';
import { MultipartFormData } from './formData';
import { SdkObject } from './instrumentation';
@ -352,7 +352,7 @@ export class GlobalFetchRequest extends FetchRequest {
}
this._options = {
baseURL: options.baseURL,
userAgent: options.userAgent || '',
userAgent: options.userAgent || `Playwright/${getPlaywrightVersion()}`,
extraHTTPHeaders: options.extraHTTPHeaders,
ignoreHTTPSErrors: !!options.ignoreHTTPSErrors,
httpCredentials: options.httpCredentials,

View file

@ -15,6 +15,7 @@
*/
import http from 'http';
import { getPlaywrightVersion } from '../lib/utils/utils';
import { expect, playwrightTest as it } from './config/browserTest';
it.skip(({ mode }) => mode !== 'default');
@ -143,3 +144,11 @@ it('should resolve url relative to gobal baseURL option', async ({ playwright, s
expect(response.url()).toBe(server.EMPTY_PAGE);
});
it('should set playwright as user-agent', async ({ playwright, server }) => {
const request = await playwright._newRequest();
const [serverRequest] = await Promise.all([
server.waitForRequest('/empty.html'),
request.get(server.EMPTY_PAGE)
]);
expect(serverRequest.headers['user-agent']).toBe('Playwright/' + getPlaywrightVersion());
});