From 84d2ee3929234803a3de8c5b0ab3623c2ec3c13a Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 5 Nov 2021 17:38:13 +0100 Subject: [PATCH] chore: fix connectOverCDP on Windows when proxy is used (#10080) --- .../src/server/chromium/chromium.ts | 8 ++++++- tests/chromium/chromium.spec.ts | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.ts index 1c50df84fc..c0d77dcf50 100644 --- a/packages/playwright-core/src/server/chromium/chromium.ts +++ b/packages/playwright-core/src/server/chromium/chromium.ts @@ -91,7 +91,13 @@ export class Chromium extends BrowserType { browserLogsCollector: new RecentLogsCollector(), artifactsDir, downloadsPath: artifactsDir, - tracesDir: artifactsDir + tracesDir: artifactsDir, + // On Windows context level proxies only work, if there isn't a global proxy + // set. This is currently a bug in the CR/Windows networking stack. By + // passing an arbitrary value we disable the check in PW land which warns + // users in normal (launch/launchServer) mode since otherwise connectOverCDP + // does not work at all with proxies on Windows. + proxy: { server: 'per-context' }, }; progress.throwIfAborted(); const browser = await CRBrowser.connect(chromeTransport, browserOptions); diff --git a/tests/chromium/chromium.spec.ts b/tests/chromium/chromium.spec.ts index 2df27927bc..5d24b581d5 100644 --- a/tests/chromium/chromium.spec.ts +++ b/tests/chromium/chromium.spec.ts @@ -418,3 +418,25 @@ playwrightTest('should connect to an existing cdp session when passed as a first await browserServer.close(); } }); + +playwrightTest('should use proxy with connectOverCDP', async ({ browserType, server }, testInfo) => { + server.setRoute('/target.html', async (req, res) => { + res.end('Served by the proxy'); + }); + const port = 9339 + testInfo.workerIndex; + const browserServer = await browserType.launch({ + args: ['--remote-debugging-port=' + port] + }); + try { + const cdpBrowser = await browserType.connectOverCDP(`http://localhost:${port}/`); + const context = await cdpBrowser.newContext({ + proxy: { server: `localhost:${server.PORT}` } + }); + const page = await context.newPage(); + await page.goto('http://non-existent.com/target.html'); + expect(await page.title()).toBe('Served by the proxy'); + await cdpBrowser.close(); + } finally { + await browserServer.close(); + } +}); \ No newline at end of file