From 14c0082370cea466dc1bdb35ec9e176cf73b4db7 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 20 Jun 2025 14:11:56 +0200 Subject: [PATCH 1/2] chore: follow-up to connectOverCDP fetch logic --- .../src/server/chromium/chromium.ts | 2 +- .../library/chromium/connect-over-cdp.spec.ts | 41 +++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.ts index fdeabb672656a..33fbb385f67c5 100644 --- a/packages/playwright-core/src/server/chromium/chromium.ts +++ b/packages/playwright-core/src/server/chromium/chromium.ts @@ -383,7 +383,7 @@ async function urlToWSEndpoint(progress: Progress, endpointURL: string, headers: progress.log(` retrieving websocket url from ${endpointURL}`); const url = new URL(endpointURL); if (!url.pathname.endsWith('/')) - url.pathname = url.pathname + '/'; + url.pathname += '/'; url.pathname += 'json/version/'; const httpURL = url.toString(); diff --git a/tests/library/chromium/connect-over-cdp.spec.ts b/tests/library/chromium/connect-over-cdp.spec.ts index 389f8838eef37..8708f0e492d23 100644 --- a/tests/library/chromium/connect-over-cdp.spec.ts +++ b/tests/library/chromium/connect-over-cdp.spec.ts @@ -41,23 +41,6 @@ test('should connect to an existing cdp session', async ({ browserType, mode }, } }); -test('should connect to an existing cdp session with verbose path', async ({ browserType, mode }, testInfo) => { - const port = 9339 + testInfo.workerIndex; - const browserServer = await browserType.launch({ - args: ['--remote-debugging-port=' + port] - }); - try { - const cdpBrowser = await browserType.connectOverCDP({ - endpointURL: `http://127.0.0.1:${port}/json/version/abcdefg`, - }); - const contexts = cdpBrowser.contexts(); - expect(contexts.length).toBe(1); - await cdpBrowser.close(); - } finally { - await browserServer.close(); - } -}); - test('should use logger in default context', async ({ browserType }, testInfo) => { test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/28813' }); const port = 9339 + testInfo.workerIndex; @@ -289,6 +272,30 @@ test('should send extra headers with connect request', async ({ browserType, ser } }); +test('should keep URL parameters when adding json/version', { + annotation: { + type: 'issue', + description: 'https://github.com/microsoft/playwright/issues/36097' + } +}, async ({ browserType, server }) => { + await Promise.all([ + server.waitForRequest('/browser/json/version/?foo=bar'), + browserType.connectOverCDP(`http://localhost:${server.PORT}/browser/?foo=bar`).catch(() => {}) + ]); +}); + +test('should append /json/version with a slash if there isnt one', { + annotation: { + type: 'issue', + description: 'https://github.com/microsoft/playwright/issues/36357' + } +}, async ({ browserType, server }) => { + await Promise.all([ + server.waitForRequest('/browser/json/version/?foo=bar'), + browserType.connectOverCDP(`http://localhost:${server.PORT}/browser?foo=bar`).catch(() => {}) + ]); +}); + test('should send default User-Agent header with connect request', async ({ browserType, server }, testInfo) => { { const [request] = await Promise.all([ From 60c9fad07041454203a414a23fd05fbcda575e8c Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 20 Jun 2025 14:28:55 +0200 Subject: [PATCH 2/2] Update tests/library/chromium/connect-over-cdp.spec.ts Signed-off-by: Max Schmitt --- tests/library/chromium/connect-over-cdp.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/library/chromium/connect-over-cdp.spec.ts b/tests/library/chromium/connect-over-cdp.spec.ts index 8708f0e492d23..b5347e2ab74bf 100644 --- a/tests/library/chromium/connect-over-cdp.spec.ts +++ b/tests/library/chromium/connect-over-cdp.spec.ts @@ -287,7 +287,7 @@ test('should keep URL parameters when adding json/version', { test('should append /json/version with a slash if there isnt one', { annotation: { type: 'issue', - description: 'https://github.com/microsoft/playwright/issues/36357' + description: 'https://github.com/microsoft/playwright/issues/36378' } }, async ({ browserType, server }) => { await Promise.all([