Skip to content

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

fix(firefox): imply default ports for proxy (#3850)

Max Schmitt8bc09af45859
diff --git a/src/server/firefox/ffBrowser.ts b/src/server/firefox/ffBrowser.ts
index eda6f1f6fd..678c2acd5d 100644
--- a/src/server/firefox/ffBrowser.ts
+++ b/src/server/firefox/ffBrowser.ts
@@ -47,6 +47,7 @@ export class FFBrowser extends Browser {
}
if (options.proxy) {
const proxyServer = new URL(options.proxy.server);
+ let proxyPort = parseInt(proxyServer.port, 10);
let aType: 'http'|'https'|'socks'|'socks4' = 'http';
if (proxyServer.protocol === 'socks5:')
aType = 'socks';
@@ -54,11 +55,17 @@ export class FFBrowser extends Browser {
aType = 'socks4';
else if (proxyServer.protocol === 'https:')
aType = 'https';
+ if (proxyServer.port === '') {
+ if (proxyServer.protocol === 'http:')
+ proxyPort = 80;
+ else if (proxyServer.protocol === 'https:')
+ proxyPort = 443;
+ }
promises.push(browser._connection.send('Browser.setBrowserProxy', {
type: aType,
bypass: options.proxy.bypass ? options.proxy.bypass.split(',').map(domain => domain.trim()) : [],
host: proxyServer.hostname,
- port: parseInt(proxyServer.port, 10),
+ port: proxyPort,
username: options.proxy.username,
password: options.proxy.password,
}));
diff --git a/test/proxy.spec.ts b/test/proxy.spec.ts
index 67b36623e1..686470be39 100644
--- a/test/proxy.spec.ts
+++ b/test/proxy.spec.ts
@@ -152,3 +152,11 @@ it('should use socks proxy', (test, parameters) => {
await browser.close();
server.close();
});
+
+it('does launch without a port', async ({ browserType, defaultBrowserOptions }) => {
+ const browser = await browserType.launch({
+ ...defaultBrowserOptions,
+ proxy: { server: 'http://localhost' }
+ });
+ await browser.close();
+});