Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: make fetch api work with connectOverCDP (#13521)
Max Schmitt584140f97aeb
diff --git a/packages/playwright-core/src/server/fetch.ts b/packages/playwright-core/src/server/fetch.tsindex 7514b53e40..285c8d114d 100644--- a/packages/playwright-core/src/server/fetch.ts+++ b/packages/playwright-core/src/server/fetch.ts@@ -141,7 +141,7 @@ export abstract class APIRequestContext extends SdkObject {const method = params.method?.toUpperCase() || 'GET';const proxy = defaults.proxy;let agent;- if (proxy) {+ if (proxy && proxy.server !== 'per-context') {// TODO: support bypass proxyconst proxyOpts = url.parse(proxy.server);if (proxyOpts.protocol?.startsWith('socks')) {diff --git a/tests/library/browsercontext-fetch.spec.ts b/tests/library/browsercontext-fetch.spec.tsindex dabd15328d..0221260ac3 100644--- a/tests/library/browsercontext-fetch.spec.ts+++ b/tests/library/browsercontext-fetch.spec.ts@@ -955,3 +955,21 @@ it('should abort requests when browser context closes', async ({ contextFactory,expect(error.message).toContain('Request context disposed');await connectionClosed;});++it('should work with connectOverCDP', async ({ browserName, browserType, server }, testInfo) => {+ it.skip(browserName !== 'chromium');+ 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] = cdpBrowser.contexts();+ const response = await context.request.get(server.PREFIX + '/simple.json');+ expect(response.url()).toBe(server.PREFIX + '/simple.json');+ expect(response.status()).toBe(200);+ expect(await response.text()).toBe('{"foo": "bar"}\n');+ } finally {+ await browserServer.close();+ }+});