From f61c43418d704cccb67132540ed7feceacef1d2a Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Sat, 17 Oct 2026 13:20:04 +0300 Subject: Start a local Chrome when the target is an explicit local and none answers Dedicated profile (~/.chrome-cdp-profile), macOS only, never for the castle default. BU_LOCAL_CHROME_LAUNCH=off disables it. --- src/cdp/discovery.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/cdp/discovery.ts') diff --git a/src/cdp/discovery.ts b/src/cdp/discovery.ts index 7aa35f6..ea75c5c 100644 --- a/src/cdp/discovery.ts +++ b/src/cdp/discovery.ts @@ -8,6 +8,7 @@ import { type CdpError, cdpError } from "./errors"; import { asString, errnoCode, isRecord } from "../util/guards"; import { describeCdpTarget, resolveCdpTarget } from "./endpoint"; import { readTarget } from "./target-store"; +import { defaultLaunchDeps, launchLocalChrome, planLocalLaunch } from "./local-launch"; const PORT_PROBE_DEADLINE_MS = 30_000; const PORT_PROBE_INTERVAL_MS = 1_000; @@ -153,6 +154,18 @@ export const discoverEndpoint = async (): Promise> // through to the local browser the extension was originally written for. } + const found = await discoverLocalEndpoint(); + if (found.success || target.kind !== "local") return found; + + // FORK: an explicit local target with no browser to attach to starts one (src/cdp/local-launch.ts). + const plan = planLocalLaunch(); + if (plan.kind === "skip") return found; + const launched = await launchLocalChrome(plan.plan, defaultLaunchDeps((port) => queryLiveWsUrl(port))); + if (launched.success) return ok({ wsUrl: launched.data }); + return err(cdpError("discovery_failed", `${found.error.message}\n\nAuto-launch of local Chrome failed: ${launched.error}`)); +}; + +const discoverLocalEndpoint = async (): Promise> => { const dirs = userDataDirCandidates(); const candidates: Candidate[] = []; -- cgit v1.2.3