From 41c6bb133ee6e7f671c20cbd66a81ad607e4971b Mon Sep 17 00:00:00 2001 From: DeepSeek Harness Agent Date: Sun, 8 Nov 2026 21:28:20 +0330 Subject: [PATCH] native-fixes: guard attach against a browser this process already drives (Firefox single BiDi session); report the existing connection instead of stranding it --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 39a0c5a..a75a159 100644 --- a/index.js +++ b/index.js @@ -982,6 +982,14 @@ async function run(args) { } case 'attach': { const port = effectivePort(args); + // Firefox allows exactly one WebDriver BiDi session. Re-attaching to a + // browser this process already drives would open a second socket against + // that single session, fail the handshake, and strand the browser with no + // owner (neither relaunch nor close could reach it). Report the existing + // connection instead. + if (session && session.port === port && session.ws.readyState === 1) { + return { ok: true, attached: true, port, liveMode: !!session.attached, alreadyConnected: true, note: 'already connected to this browser in this process' }; + } await attachOnly(port); return { ok: true, attached: true, port, liveMode: true }; }