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

This commit is contained in:
Max Schmitt 2020-09-15 06:22:07 +02:00 committed by GitHub
parent f758a09d8e
commit 8bc09af458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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,
}));

View File

@ -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();
});