Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(proxy): preserve HTTP env proxy request target (#40395)

Noah Jorgensen48798d902dee
diff --git a/packages/utils/network.ts b/packages/utils/network.ts
index c21027290b..de32b45d7f 100644
--- a/packages/utils/network.ts
+++ b/packages/utils/network.ts
@@ -58,7 +58,7 @@ export function httpRequest(params: HTTPRequestParams, onResponse: (r: http.Inco
if (proxyURL) {
const parsedProxyURL = normalizeProxyURL(proxyURL);
if (params.url.startsWith('http:')) {
- parsedProxyURL.pathname = url.toString();
+ options.path = url.toString();
url = parsedProxyURL;
} else {
options.agent = new HttpsProxyAgent(parsedProxyURL);
diff --git a/tests/library/chromium/connect-over-cdp.spec.ts b/tests/library/chromium/connect-over-cdp.spec.ts
index 77a18ca652..c5a06d0d6c 100644
--- a/tests/library/chromium/connect-over-cdp.spec.ts
+++ b/tests/library/chromium/connect-over-cdp.spec.ts
@@ -431,6 +431,21 @@ test('should use proxy with connectOverCDP', async ({ browserType, server }, tes
}
});
+test('should use env proxy with connectOverCDP discovery request', async ({ browserType, server, proxyServer, mode }) => {
+ test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/40394' });
+ test.skip(mode !== 'default'); // Out of process transport does not allow us to set env vars dynamically.
+ proxyServer.forwardTo(server.PORT);
+
+ const oldValue = process.env.HTTP_PROXY;
+ try {
+ process.env.HTTP_PROXY = proxyServer.URL;
+ await browserType.connectOverCDP(server.PREFIX).catch(() => {});
+ expect(proxyServer.requestUrls).toEqual([`${server.PREFIX}/json/version/`]);
+ } finally {
+ process.env.HTTP_PROXY = oldValue;
+ }
+});
+
test('should be able to connect via localhost', async ({ browserType }, testInfo) => {
const port = 9339 + testInfo.workerIndex;
const browserServer = await browserType.launch({