diff options
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/index.ts b/src/index.ts index 5818a5d..2b95697 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,8 @@ import { restoreDownloadBehavior } from "./domains/files"; import { createDaemonTransport } from "./daemon/transport"; import { setDebugClicks } from "./util/debug"; import { asBoolean, asString } from "./util/guards"; +import { describeCdpTarget, resolveCdpTarget } from "./cdp/endpoint"; +import { queryLiveWsUrl } from "./cdp/discovery"; export default function browserHarnessExtension(pi: ExtensionAPI): void { const flagNs = asString(pi.getFlag("browser-namespace")); @@ -40,8 +42,32 @@ export default function browserHarnessExtension(pi: ExtensionAPI): void { } const s = client.status(); const pin = client.profilePin(); + + // FORK: the connection is lazy — nothing dials the browser until the + // first browser_* tool runs. A plain "Disconnected" reads as a fault + // when it is really just "not needed yet", so say which it is, and show + // what we would connect to. + const target = resolveCdpTarget(); + const reachable = + target.kind === "remote" ? (await queryLiveWsUrl(target.port, 2_000, target.host)) !== null : null; + + const browserLine = s.alive + ? "🟢 Connected" + : reachable === false + ? "🔴 Not connected — target unreachable" + : "🟡 Not connected yet — connects on the first browser tool call"; + + const targetLine = + target.kind === "remote" + ? `${describeCdpTarget(target)}${reachable ? " — reachable ✓" : " — unreachable ✗"}` + + (reachable === false && target.source === "default" + ? "\n will fall back to this machine's browser" + : "") + : describeCdpTarget(target); + const lines = [ - `Browser: ${s.alive ? "🟢 Connected" : "🔴 Disconnected"}`, + `Browser: ${browserLine}`, + `Target: ${targetLine}`, `Profile: ${pin ? pin.label : "not selected (uses whichever window is focused) — run /browser-profile"}`, `Session: ${s.sessionId ?? "none"}`, ]; |
