Skip to content

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

fix: httpRequest for http url via https proxy (#37743)

Simon Knott232ea015fa2b
diff --git a/packages/playwright-core/src/server/utils/network.ts b/packages/playwright-core/src/server/utils/network.ts
index e6b0e61ae0..a10bcc7ea7 100644
--- a/packages/playwright-core/src/server/utils/network.ts
+++ b/packages/playwright-core/src/server/utils/network.ts
@@ -58,6 +58,7 @@ export function httpRequest(params: HTTPRequestParams, onResponse: (r: http.Inco
path: parsedUrl.href,
host: parsedProxyURL.hostname,
port: parsedProxyURL.port,
+ protocol: parsedProxyURL.protocol || 'http:',
headers: options.headers,
method: options.method
};
diff --git a/tests/installation/playwright-cli-install-should-work.spec.ts b/tests/installation/playwright-cli-install-should-work.spec.ts
index c3116aae37..a4593a98bf 100755
--- a/tests/installation/playwright-cli-install-should-work.spec.ts
+++ b/tests/installation/playwright-cli-install-should-work.spec.ts
@@ -16,7 +16,9 @@
import { test, expect } from './npmTest';
import { chromium } from '@playwright/test';
import path from 'path';
+import https from 'https';
import { TestProxy } from '../config/proxy';
+import { TestServer } from '../config/testserver';
test.use({ isolateBrowsers: true });
@@ -90,6 +92,30 @@ test('install command should ignore HTTP_PROXY', { annotation: { type: 'issue',
});
});
+test('install command should work with HTTPS proxy for HTTP downloads', async ({ exec }) => {
+ await exec('npm i playwright');
+ const httpsProxyServer = https.createServer(await TestServer.certOptions());
+
+ let requestCount = 0;
+ httpsProxyServer.on('request', (_req, res) => {
+ requestCount++;
+ res.statusCode = 502;
+ res.end();
+ });
+
+ await new Promise<void>(resolve => httpsProxyServer.listen(0, resolve));
+ await exec('npx playwright install chromium', {
+ env: {
+ PLAYWRIGHT_DOWNLOAD_HOST: 'http://example.com',
+ ALL_PROXY: `https://localhost:${(httpsProxyServer.address() as any).port}`,
+ NODE_TLS_REJECT_UNAUTHORIZED: '0',
+ },
+ expectToExitWithError: true,
+ });
+ expect(requestCount).toBeGreaterThan(0);
+ httpsProxyServer.close();
+});
+
test('should be able to remove browsers', async ({ exec, checkInstalledSoftwareOnDisk }) => {
await exec('npm i playwright');
await exec('npx playwright install chromium');