Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: update https-proxy-agent (#37713)
Simon Knott3270ee68944a
diff --git a/packages/playwright-core/ThirdPartyNotices.txt b/packages/playwright-core/ThirdPartyNotices.txtindex 57cf609a1c..f3fd74df49 100644--- a/packages/playwright-core/ThirdPartyNotices.txt+++ b/packages/playwright-core/ThirdPartyNotices.txt@@ -5,6 +5,7 @@ THIRD-PARTY SOFTWARE NOTICES AND INFORMATIONThis project incorporates components from the projects listed below. The original copyright notices and the licenses under which Microsoft received such components are set forth below. Microsoft reserves all rights not expressly granted herein, whether by implication, estoppel or otherwise.- [email protected] (https://github.com/TooTallNate/node-agent-base)+- [email protected] (https://github.com/TooTallNate/proxy-agents)- [email protected] (https://github.com/juliangruber/balanced-match)- [email protected] (https://github.com/juliangruber/brace-expansion)- [email protected] (https://github.com/brianloveswords/buffer-crc32)@@ -20,7 +21,7 @@ This project incorporates components from the projects listed below. The origina- [email protected] (https://github.com/mafintosh/end-of-stream)- [email protected] (https://github.com/sindresorhus/get-stream)- [email protected] (https://github.com/isaacs/node-graceful-fs)-- [email protected] (https://github.com/TooTallNate/node-https-proxy-agent)+- [email protected] (https://github.com/TooTallNate/proxy-agents)- [email protected] (https://github.com/beaugunderson/ip-address)- [email protected] (https://github.com/sindresorhus/is-docker)- [email protected] (https://github.com/sindresorhus/is-wsl)@@ -199,6 +200,33 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=========================================END OF [email protected] AND INFORMATION+%% [email protected] NOTICES AND INFORMATION BEGIN HERE+=========================================+(The MIT License)++Copyright (c) 2013 Nathan Rajlich <[email protected]>++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+'Software'), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+=========================================+END OF [email protected] AND INFORMATION+%% [email protected] NOTICES AND INFORMATION BEGIN HERE=========================================(MIT)@@ -565,124 +593,11 @@ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.=========================================END OF [email protected] AND INFORMATION-%% [email protected] NOTICES AND INFORMATION BEGIN HERE+%% [email protected] NOTICES AND INFORMATION BEGIN HERE=========================================-https-proxy-agent-================-### An HTTP(s) proxy `http.Agent` implementation for HTTPS-[](https://github.com/TooTallNate/node-https-proxy-agent/actions?workflow=Node+CI)--This module provides an `http.Agent` implementation that connects to a specified-HTTP or HTTPS proxy server, and can be used with the built-in `https` module.--Specifically, this `Agent` implementation connects to an intermediary "proxy"-server and issues the [CONNECT HTTP method][CONNECT], which tells the proxy to-open a direct TCP connection to the destination server.--Since this agent implements the CONNECT HTTP method, it also works with other-protocols that use this method when connecting over proxies (i.e. WebSockets).-See the "Examples" section below for more.---Installation---------------Install with `npm`:--``` bash-$ npm install https-proxy-agent-```---Examples-----------#### `https` module example--``` js-var url = require('url');-var https = require('https');-var HttpsProxyAgent = require('https-proxy-agent');--// HTTP/HTTPS proxy to connect to-var proxy = process.env.http_proxy || 'http://168.63.76.32:3128';-console.log('using proxy server %j', proxy);--// HTTPS endpoint for the proxy to connect to-var endpoint = process.argv[2] || 'https://graph.facebook.com/tootallnate';-console.log('attempting to GET %j', endpoint);-var options = url.parse(endpoint);--// create an instance of the `HttpsProxyAgent` class with the proxy server information-var agent = new HttpsProxyAgent(proxy);-options.agent = agent;--https.get(options, function (res) {- console.log('"response" event!', res.headers);- res.pipe(process.stdout);-});-```--#### `ws` WebSocket connection example--``` js-var url = require('url');-var WebSocket = require('ws');-var HttpsProxyAgent = require('https-proxy-agent');--// HTTP/HTTPS proxy to connect to-var proxy = process.env.http_proxy || 'http://168.63.76.32:3128';-console.log('using proxy server %j', proxy);--// WebSocket endpoint for the proxy to connect to-var endpoint = process.argv[2] || 'ws://echo.websocket.org';-var parsed = url.parse(endpoint);-console.log('attempting to connect to WebSocket %j', endpoint);--// create an instance of the `HttpsProxyAgent` class with the proxy server information-var options = url.parse(proxy);--var agent = new HttpsProxyAgent(options);--// finally, initiate the WebSocket connection-var socket = new WebSocket(endpoint, { agent: agent });--socket.on('open', function () {- console.log('"open" event!');- socket.send('hello world');-});--socket.on('message', function (data, flags) {- console.log('"message" event! %j %j', data, flags);- socket.close();-});-```--API------### new HttpsProxyAgent(Object options)--The `HttpsProxyAgent` class implements an `http.Agent` subclass that connects-to the specified "HTTP(s) proxy server" in order to proxy HTTPS and/or WebSocket-requests. This is achieved by using the [HTTP `CONNECT` method][CONNECT].--The `options` argument may either be a string URI of the proxy server to use, or an-"options" object with more specific properties:-- * `host` - String - Proxy host to connect to (may use `hostname` as well). Required.- * `port` - Number - Proxy port to connect to. Required.- * `protocol` - String - If `https:`, then use TLS to connect to the proxy.- * `headers` - Object - Additional HTTP headers to be sent on the HTTP CONNECT method.- * Any other options given are passed to the `net.connect()`/`tls.connect()` functions.---License---------(The MIT License)-Copyright (c) 2013 Nathan Rajlich <[email protected]>+Copyright (c) 2013 Nathan Rajlich <[email protected]>Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the@@ -702,10 +617,8 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.--[CONNECT]: http://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_Tunneling=========================================-END OF [email protected] AND INFORMATION+END OF [email protected] AND INFORMATION%% [email protected] NOTICES AND INFORMATION BEGIN HERE=========================================@@ -1497,6 +1410,6 @@ END OF [email protected] AND INFORMATIONSUMMARY BEGIN HERE=========================================-Total Packages: 44+Total Packages: 45=========================================END OF SUMMARY\ No newline at end of filediff --git a/packages/playwright-core/bundles/utils/package-lock.json b/packages/playwright-core/bundles/utils/package-lock.jsonindex 7900f7c098..6434eec236 100644--- a/packages/playwright-core/bundles/utils/package-lock.json+++ b/packages/playwright-core/bundles/utils/package-lock.json@@ -14,7 +14,7 @@"diff": "^7.0.0","dotenv": "^16.4.5","graceful-fs": "4.2.10",- "https-proxy-agent": "5.0.1",+ "https-proxy-agent": "7.0.6","jpeg-js": "0.4.4","mime": "^3.0.0","minimatch": "^3.1.2",@@ -236,15 +236,25 @@"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA=="},"node_modules/https-proxy-agent": {- "version": "5.0.1",- "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",- "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==",+ "version": "7.0.6",+ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz",+ "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==",+ "license": "MIT","dependencies": {- "agent-base": "6",+ "agent-base": "^7.1.2","debug": "4"},"engines": {- "node": ">= 6"+ "node": ">= 14"+ }+ },+ "node_modules/https-proxy-agent/node_modules/agent-base": {+ "version": "7.1.4",+ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz",+ "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==",+ "license": "MIT",+ "engines": {+ "node": ">= 14"}},"node_modules/ip-address": {diff --git a/packages/playwright-core/bundles/utils/package.json b/packages/playwright-core/bundles/utils/package.jsonindex c0559de57d..a38fc7abcc 100644--- a/packages/playwright-core/bundles/utils/package.json+++ b/packages/playwright-core/bundles/utils/package.json@@ -9,7 +9,7 @@"diff": "^7.0.0","dotenv": "^16.4.5","graceful-fs": "4.2.10",- "https-proxy-agent": "5.0.1",+ "https-proxy-agent": "7.0.6","jpeg-js": "0.4.4","mime": "^3.0.0","minimatch": "^3.1.2",diff --git a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.tsindex 846d2ca3d1..71251557c3 100644--- a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts+++ b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts@@ -129,10 +129,14 @@ class SocksProxyConnection {async connect() {const proxyAgent = this.socksProxy.getProxyAgent(this.host, this.port);- if (proxyAgent)- this._serverEncrypted = await proxyAgent.callback(new EventEmitter() as any, { host: rewriteToLocalhostIfNeeded(this.host), port: this.port, secureEndpoint: false });- else+ if (proxyAgent) {+ if ('callback' in proxyAgent)+ this._serverEncrypted = await proxyAgent.callback(new EventEmitter() as any, { host: rewriteToLocalhostIfNeeded(this.host), port: this.port, secureEndpoint: false });+ else+ this._serverEncrypted = await proxyAgent.connect(new EventEmitter() as any, { host: rewriteToLocalhostIfNeeded(this.host), port: this.port, secureEndpoint: false });+ } else {this._serverEncrypted = await createSocket(rewriteToLocalhostIfNeeded(this.host), this.port);+ }this._serverEncrypted.once('close', this._serverCloseEventListener);this._serverEncrypted.once('error', error => this._browserEncrypted.destroy(error));diff --git a/packages/playwright-core/src/server/utils/network.ts b/packages/playwright-core/src/server/utils/network.tsindex 157a6f7086..e6b0e61ae0 100644--- a/packages/playwright-core/src/server/utils/network.ts+++ b/packages/playwright-core/src/server/utils/network.ts@@ -62,9 +62,7 @@ export function httpRequest(params: HTTPRequestParams, onResponse: (r: http.Incomethod: options.method};} else {- (parsedProxyURL as any).secureProxy = parsedProxyURL.protocol === 'https:';-- options.agent = new HttpsProxyAgent(parsedProxyURL);+ options.agent = new HttpsProxyAgent(url.format(parsedProxyURL));options.rejectUnauthorized = false;}}@@ -160,11 +158,11 @@ export function createProxyAgent(proxy?: ProxySettings, forUrl?: URL) {if (forUrl && ['ws:', 'wss:'].includes(forUrl.protocol)) {// Force CONNECT method for WebSockets.- return new HttpsProxyAgent(proxyOpts);+ return new HttpsProxyAgent(url.format(proxyOpts));}- // TODO: We should use HttpProxyAgent conditional on proxyOpts.protocol instead of always using CONNECT method.- return new HttpsProxyAgent(proxyOpts);+ // TODO: This branch should be different from above. We should use HttpProxyAgent conditional on proxyOpts.protocol instead of always using CONNECT method.+ return new HttpsProxyAgent(url.format(proxyOpts));}export function createHttpServer(requestListener?: (req: http.IncomingMessage, res: http.ServerResponse) => void): http.Server;diff --git a/tests/config/testserver/index.ts b/tests/config/testserver/index.tsindex 177ea131d0..c05bd82ec3 100644--- a/tests/config/testserver/index.ts+++ b/tests/config/testserver/index.ts@@ -64,12 +64,16 @@ export class TestServer {return server;}- static async createHTTPS(dirPath: string, port: number, loopback?: string): Promise<TestServer> {- const server = new TestServer(dirPath, port, loopback, {+ static async certOptions() {+ return {key: await fs.promises.readFile(path.join(__dirname, 'key.pem')),cert: await fs.promises.readFile(path.join(__dirname, 'cert.pem')),passphrase: 'aaaa',- });+ };+ }++ static async createHTTPS(dirPath: string, port: number, loopback?: string): Promise<TestServer> {+ const server = new TestServer(dirPath, port, loopback, await this.certOptions());await server.waitUntilReady();return server;}diff --git a/tests/library/fetch-proxy.spec.ts b/tests/library/fetch-proxy.spec.tsindex 149bd2f2b1..5d35bef85b 100644--- a/tests/library/fetch-proxy.spec.ts+++ b/tests/library/fetch-proxy.spec.ts@@ -14,7 +14,9 @@* limitations under the License.*/+import https from 'node:https';import { contextTest as it, expect } from '../config/browserTest';+import { TestServer } from '../config/testserver';it.skip(({ mode }) => mode !== 'default');@@ -137,3 +139,35 @@ it('should use socks proxy', async ({ playwright, server, socksPort }) => {const response = await request.get(server.EMPTY_PAGE);expect(await response.text()).toContain('Served by the SOCKS proxy');});++it('should send correct ALPN protocol to HTTPS proxy', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37676' } }, async ({ playwright, server, nodeVersion }) => {+ it.skip(nodeVersion.major < 22, 'ALPNCallback is supported starting from Node 22');++ let offeredProtocols: string[];+ const proxy = https.createServer({+ ...(await TestServer.certOptions()),+ ALPNCallback: protocols => {+ offeredProtocols = protocols.protocols;+ return protocols[0];+ },+ });++ const port = await new Promise<number>(resolve => {+ proxy.listen(0, () => {+ const { port } = proxy.address() as any;+ resolve(port);+ });+ });++ const request = await playwright.request.newContext({+ proxy: { server: `https://localhost:${port}` },+ ignoreHTTPSErrors: true,+ });++ await expect(request.get(server.EMPTY_PAGE)).rejects.toThrowError();++ expect(offeredProtocols).toContain('http/1.1');++ proxy.close();+ await request.dispose();+});diff --git a/tests/library/har.spec.ts b/tests/library/har.spec.tsindex fd3f47264a..c3eb51172c 100644--- a/tests/library/har.spec.ts+++ b/tests/library/har.spec.ts@@ -16,12 +16,12 @@*/import { browserTest as it, expect } from '../config/browserTest';-import * as path from 'path';import fs from 'fs';import type { BrowserContext, BrowserContextOptions } from 'playwright-core';import type { AddressInfo } from 'net';import type { Log } from '../../packages/trace/src/har';import { parseHar } from '../config/utils';+import { TestServer } from '../config/testserver';const { createHttp2Server } = require('../../packages/playwright-core/lib/utils');async function pageWithHar(contextFactory: (options?: BrowserContextOptions) => Promise<BrowserContext>, testInfo: any, options: { outputPath?: string } & Partial<Pick<BrowserContextOptions['recordHar'], 'content' | 'omitContent' | 'mode'>> = {}) {@@ -676,10 +676,7 @@ it('should return security details directly from response', async ({ contextFact});it('should contain http2 for http2 requests', async ({ contextFactory }, testInfo) => {- const server = createHttp2Server({- key: await fs.promises.readFile(path.join(__dirname, '..', 'config', 'testserver', 'key.pem')),- cert: await fs.promises.readFile(path.join(__dirname, '..', 'config', 'testserver', 'cert.pem')),- });+ const server = createHttp2Server(await TestServer.certOptions());server.on('stream', stream => {stream.respond({'content-type': 'text/html; charset=utf-8',