chore: move setting PW User-Agent on connectOverCDP to the server side (#10899)
This commit is contained in:
parent
a82a3f1128
commit
67b16497cc
|
|
@ -23,7 +23,7 @@ import { Connection } from './connection';
|
|||
import { Events } from './events';
|
||||
import { ChildProcess } from 'child_process';
|
||||
import { envObjectToArray } from './clientHelper';
|
||||
import { assert, headersObjectToArray, getUserAgent, monotonicTime } from '../utils/utils';
|
||||
import { assert, headersObjectToArray, monotonicTime } from '../utils/utils';
|
||||
import * as api from '../../types/types';
|
||||
import { kBrowserClosedError } from '../utils/errors';
|
||||
import { raceAgainstDeadline } from '../utils/async';
|
||||
|
|
@ -205,9 +205,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
|
|||
async _connectOverCDP(endpointURL: string, params: api.ConnectOverCDPOptions = {}): Promise<Browser> {
|
||||
if (this.name() !== 'chromium')
|
||||
throw new Error('Connecting over CDP is only supported in Chromium.');
|
||||
const logger = params.logger;
|
||||
const paramsHeaders = Object.assign({ 'User-Agent': getUserAgent() }, params.headers);
|
||||
const headers = paramsHeaders ? headersObjectToArray(paramsHeaders) : undefined;
|
||||
const headers = params.headers ? headersObjectToArray(params.headers) : undefined;
|
||||
const result = await this._channel.connectOverCDP({
|
||||
endpointURL,
|
||||
headers,
|
||||
|
|
@ -217,7 +215,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
|
|||
const browser = Browser.from(result.browser);
|
||||
if (result.defaultContext)
|
||||
browser._contexts.add(BrowserContext.from(result.defaultContext));
|
||||
browser._logger = logger;
|
||||
browser._logger = params.logger;
|
||||
browser._setBrowserType(this);
|
||||
browser._localUtils = this._playwright._utils;
|
||||
return browser;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import { ConnectionTransport, ProtocolRequest, WebSocketTransport } from '../tra
|
|||
import { CRDevTools } from './crDevTools';
|
||||
import { Browser, BrowserOptions, BrowserProcess, PlaywrightOptions } from '../browser';
|
||||
import * as types from '../types';
|
||||
import { debugMode, fetchData, headersArrayToObject, HTTPRequestParams, removeFolders, streamToString } from '../../utils/utils';
|
||||
import { debugMode, fetchData, getUserAgent, headersArrayToObject, HTTPRequestParams, removeFolders, streamToString } from '../../utils/utils';
|
||||
import { RecentLogsCollector } from '../../utils/debugLogger';
|
||||
import { Progress, ProgressController } from '../progress';
|
||||
import { TimeoutSettings } from '../../utils/timeoutSettings';
|
||||
|
|
@ -63,6 +63,11 @@ export class Chromium extends BrowserType {
|
|||
if (options.headers)
|
||||
headersMap = headersArrayToObject(options.headers, false);
|
||||
|
||||
if (!headersMap)
|
||||
headersMap = { 'User-Agent': getUserAgent() };
|
||||
else if (headersMap && !Object.keys(headersMap).some(key => key.toLowerCase() === 'user-agent'))
|
||||
headersMap['User-Agent'] = getUserAgent();
|
||||
|
||||
const artifactsDir = await fs.promises.mkdtemp(ARTIFACTS_FOLDER);
|
||||
|
||||
const wsEndpoint = await urlToWSEndpoint(progress, endpointURL);
|
||||
|
|
|
|||
Loading…
Reference in a new issue