From 8bc09af4585927d97bd77b67e21a0ceb08a9c1bb Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 15 Sep 2020 06:22:07 +0200 Subject: [PATCH] fix(firefox): imply default ports for proxy (#3850) --- src/server/firefox/ffBrowser.ts | 9 ++++++++- test/proxy.spec.ts | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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(); +});