feat(fetch): send Playwright as default user-agent for global fetch (#9195)
This commit is contained in:
parent
ed9b42a92d
commit
64657c3b65
|
|
@ -23,7 +23,7 @@ import zlib from 'zlib';
|
||||||
import { HTTPCredentials } from '../../types/types';
|
import { HTTPCredentials } from '../../types/types';
|
||||||
import { NameValue, NewRequestOptions } from '../common/types';
|
import { NameValue, NewRequestOptions } from '../common/types';
|
||||||
import { TimeoutSettings } from '../utils/timeoutSettings';
|
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 { BrowserContext } from './browserContext';
|
||||||
import { MultipartFormData } from './formData';
|
import { MultipartFormData } from './formData';
|
||||||
import { SdkObject } from './instrumentation';
|
import { SdkObject } from './instrumentation';
|
||||||
|
|
@ -352,7 +352,7 @@ export class GlobalFetchRequest extends FetchRequest {
|
||||||
}
|
}
|
||||||
this._options = {
|
this._options = {
|
||||||
baseURL: options.baseURL,
|
baseURL: options.baseURL,
|
||||||
userAgent: options.userAgent || '',
|
userAgent: options.userAgent || `Playwright/${getPlaywrightVersion()}`,
|
||||||
extraHTTPHeaders: options.extraHTTPHeaders,
|
extraHTTPHeaders: options.extraHTTPHeaders,
|
||||||
ignoreHTTPSErrors: !!options.ignoreHTTPSErrors,
|
ignoreHTTPSErrors: !!options.ignoreHTTPSErrors,
|
||||||
httpCredentials: options.httpCredentials,
|
httpCredentials: options.httpCredentials,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
|
import { getPlaywrightVersion } from '../lib/utils/utils';
|
||||||
import { expect, playwrightTest as it } from './config/browserTest';
|
import { expect, playwrightTest as it } from './config/browserTest';
|
||||||
|
|
||||||
it.skip(({ mode }) => mode !== 'default');
|
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);
|
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());
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue