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

This commit is contained in:
Max Schmitt 2021-11-05 17:38:13 +01:00 committed by GitHub
parent 95a5c5cb79
commit 84d2ee3929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

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

View File

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