diff --git a/docs/src/api/params.md b/docs/src/api/params.md index 27c1cfcc49..6e9a4593d8 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -447,9 +447,13 @@ Actual picture of each page will be scaled down if necessary to fit the specifie - `username` <[string]> Optional username to use if HTTP proxy requires authentication. - `password` <[string]> Optional password to use if HTTP proxy requires authentication. -Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this -option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example -`launch({ proxy: { server: 'per-context' } })`. +Network proxy settings to use with this context. + +:::note +For Chromium on Windows the browser needs to be launched with the global proxy for this option to work. If all +contexts override the proxy, global proxy will be never used and can be any string, for example +`launch({ proxy: { server: 'http://per-context' } })`. +::: ## select-options-values * langs: java, js diff --git a/src/server/browserContext.ts b/src/server/browserContext.ts index 97e1b579a3..6c7a8bb8b3 100644 --- a/src/server/browserContext.ts +++ b/src/server/browserContext.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import * as os from 'os'; import { TimeoutSettings } from '../utils/timeoutSettings'; import { debugMode, mkdirIfNeeded, createGuid } from '../utils/utils'; import { Browser, BrowserOptions } from './browser'; @@ -405,8 +406,8 @@ export function validateBrowserContextOptions(options: types.BrowserContextOptio options.recordVideo.size!.height &= ~1; } if (options.proxy) { - if (!browserOptions.proxy) - throw new Error(`Browser needs to be launched with the global proxy. If all contexts override the proxy, global proxy will be never used and can be any string, for example "launch({ proxy: { server: 'per-context' } })"`); + if (!browserOptions.proxy && browserOptions.isChromium && os.platform() === 'win32') + throw new Error(`Browser needs to be launched with the global proxy. If all contexts override the proxy, global proxy will be never used and can be any string, for example "launch({ proxy: { server: 'http://per-context' } })"`); options.proxy = normalizeProxySettings(options.proxy); } if (debugMode() === 'inspector') diff --git a/tests/browsercontext-proxy.spec.ts b/tests/browsercontext-proxy.spec.ts index 8db7198de3..557cbe4743 100644 --- a/tests/browsercontext-proxy.spec.ts +++ b/tests/browsercontext-proxy.spec.ts @@ -26,7 +26,9 @@ it.afterAll(async () => { await browser.close(); }); -it('should throw for missing global proxy', async ({ browserType, browserOptions, server }) => { +it('should throw for missing global proxy on Chromium Windows', async ({ browserName, platform, browserType, browserOptions, server }) => { + it.skip(browserName !== 'chromium' || platform !== 'win32'); + delete browserOptions.proxy; const browser = await browserType.launch(browserOptions); const error = await browser.newContext({ proxy: { server: `localhost:${server.PORT}` } }).catch(e => e); @@ -34,6 +36,27 @@ it('should throw for missing global proxy', async ({ browserType, browserOptions await browser.close(); }); +it('should work when passing the proxy only on the context level', async ({browserName, platform, browserType, browserOptions, contextOptions, server}) => { + // Currently an upstream bug in the network stack of Chromium which leads that + // the wrong proxy gets used in the BrowserContext. + it.fixme(browserName === 'chromium' && platform === 'win32'); + + server.setRoute('/target.html', async (req, res) => { + res.end('