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(connectOverCDP): send custom headers in /json/version request (#29408)
Dmitry Gozman3abd7c808ec7
diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.tsindex 9c1fa53253..0849c1c6fe 100644--- a/packages/playwright-core/src/server/chromium/chromium.ts+++ b/packages/playwright-core/src/server/chromium/chromium.ts@@ -82,7 +82,7 @@ export class Chromium extends BrowserType {const artifactsDir = await fs.promises.mkdtemp(ARTIFACTS_FOLDER);- const wsEndpoint = await urlToWSEndpoint(progress, endpointURL);+ const wsEndpoint = await urlToWSEndpoint(progress, endpointURL, headersMap);progress.throwIfAborted();const chromeTransport = await WebSocketTransport.connect(progress, wsEndpoint, headersMap);@@ -351,13 +351,14 @@ export class Chromium extends BrowserType {}}-async function urlToWSEndpoint(progress: Progress, endpointURL: string) {+async function urlToWSEndpoint(progress: Progress, endpointURL: string, headers: { [key: string]: string; }) {if (endpointURL.startsWith('ws'))return endpointURL;progress.log(`<ws preparing> retrieving websocket url from ${endpointURL}`);const httpURL = endpointURL.endsWith('/') ? `${endpointURL}json/version/` : `${endpointURL}/json/version/`;const json = await fetchData({url: httpURL,+ headers,}, async (_, resp) => new Error(`Unexpected status ${resp.statusCode} when connecting to ${httpURL}.\n` +`This does not look like a DevTools server, try connecting via ws://.`));diff --git a/tests/library/chromium/connect-over-cdp.spec.ts b/tests/library/chromium/connect-over-cdp.spec.tsindex 0262b73c7a..dd4e1c85fd 100644--- a/tests/library/chromium/connect-over-cdp.spec.ts+++ b/tests/library/chromium/connect-over-cdp.spec.ts@@ -256,9 +256,9 @@ test('should send extra headers with connect request', async ({ browserType, ser}{const [request] = await Promise.all([- server.waitForWebSocketConnectionRequest(),+ server.waitForRequest('/json/version/'),browserType.connectOverCDP({- endpointURL: `ws://localhost:${server.PORT}/ws`,+ endpointURL: `http://localhost:${server.PORT}`,headers: {'User-Agent': 'Playwright','foo': 'bar',