From 1fe0a6ec9813f37a1cad5db4c1bf6873aba42632 Mon Sep 17 00:00:00 2001 From: Edwin Hoksberg Date: Thu, 2 Jul 2026 16:12:01 +0200 Subject: [PATCH] Use existing browser context when connecting over CDP --- bin/playwright-server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/playwright-server.js b/bin/playwright-server.js index 597e5bd..c62e87d 100644 --- a/bin/playwright-server.js +++ b/bin/playwright-server.js @@ -318,7 +318,8 @@ class PlaywrightServer extends BaseHandler { const attached = await chromium.connectOverCDP(endpointURL, options || {}); const browserId = this.generateId('browser'); this.browsers.set(browserId, attached); - const context = await attached.newContext(); + const existingContexts = attached.contexts(); + const context = existingContexts.length > 0 ? existingContexts[0] : await attached.newContext(); const contextId = this.generateId('context'); this.contexts.set(contextId, { context, browserId, id: contextId }); return { browserId, defaultContextId: contextId, version: attached.version() };