Skip to content

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

chore: fix connectOverCDP on Windows when proxy is used (#10080)

Max Schmitt84d2ee392923
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('<html><title>Served by the proxy</title></html>');
+ });
+ 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