diff --git a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts index 416f5078ef99c..cfe8fd1778e54 100644 --- a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts +++ b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts @@ -313,7 +313,7 @@ export class ClientCertificatesProxy { const proxyFromOptions = createProxyAgent(this._proxy); if (proxyFromOptions) return proxyFromOptions; - const proxyFromEnv = getProxyForUrl(`https://${host}:${port}`); + const proxyFromEnv = getProxyForUrl(new URL(`https://${host}:${port}`)); if (proxyFromEnv) return createProxyAgent({ server: proxyFromEnv }); } diff --git a/packages/playwright-core/src/server/utils/network.ts b/packages/playwright-core/src/server/utils/network.ts index 1aea7f6d7b986..19577312994ab 100644 --- a/packages/playwright-core/src/server/utils/network.ts +++ b/packages/playwright-core/src/server/utils/network.ts @@ -47,7 +47,7 @@ export function httpRequest(params: HTTPRequestParams, onResponse: (r: http.Inco if (params.rejectUnauthorized !== undefined) options.rejectUnauthorized = params.rejectUnauthorized; - const proxyURL = getProxyForUrl(params.url); + const proxyURL = getProxyForUrl(url); if (proxyURL) { const parsedProxyURL = normalizeProxyURL(proxyURL); if (params.url.startsWith('http:')) { diff --git a/packages/playwright-core/src/utilsBundle.ts b/packages/playwright-core/src/utilsBundle.ts index d5e8a2d940673..411c4b386b151 100644 --- a/packages/playwright-core/src/utilsBundle.ts +++ b/packages/playwright-core/src/utilsBundle.ts @@ -18,7 +18,7 @@ export const colors: typeof import('../bundles/utils/node_modules/colors/safe') export const debug: typeof import('../bundles/utils/node_modules/@types/debug') = require('./utilsBundleImpl').debug; export const diff: typeof import('../bundles/utils/node_modules/@types/diff') = require('./utilsBundleImpl').diff; export const dotenv: typeof import('../bundles/utils/node_modules/dotenv') = require('./utilsBundleImpl').dotenv; -export const getProxyForUrl: typeof import('../bundles/utils/node_modules/@types/proxy-from-env').getProxyForUrl = require('./utilsBundleImpl').getProxyForUrl; +const getProxyForUrlFromEnv: typeof import('../bundles/utils/node_modules/@types/proxy-from-env').getProxyForUrl = require('./utilsBundleImpl').getProxyForUrl; export const HttpsProxyAgent: typeof import('../bundles/utils/node_modules/https-proxy-agent').HttpsProxyAgent = require('./utilsBundleImpl').HttpsProxyAgent; export const jpegjs: typeof import('../bundles/utils/node_modules/jpeg-js') = require('./utilsBundleImpl').jpegjs; export const lockfile: typeof import('../bundles/utils/node_modules/@types/proper-lockfile') = require('./utilsBundleImpl').lockfile; @@ -39,6 +39,18 @@ export type { Range as YAMLRange, Scalar as YAMLScalar, YAMLError, YAMLMap, YAML export type { Command } from '../bundles/utils/node_modules/commander'; export type { EventEmitter as WebSocketEventEmitter, RawData as WebSocketRawData, WebSocket, WebSocketServer } from '../bundles/utils/node_modules/@types/ws'; +// Wraps proxy-from-env's getProxyForUrl to accept a modern URL instance, +// avoiding the deprecated url.parse() call inside the library. +// It only reads a couple of fields. +export function getProxyForUrl(url: URL): string { + return getProxyForUrlFromEnv({ + protocol: url.protocol, + // WHATWG URL strips default ports from hostname, which node:url doesn't, but this doesnt matter for proxy-from-env. + host: url.host, + port: url.port, + } as import('node:url').Url); +} + export function ms(ms: number): string { if (!isFinite(ms)) return '-';