diff options
Diffstat (limited to 'src/cdp/discovery.ts')
| -rw-r--r-- | src/cdp/discovery.ts | 13 |
1 files changed, 13 insertions, 0 deletions
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<Result<CdpEndpoint, CdpError>> // 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<Result<CdpEndpoint, CdpError>> => { const dirs = userDataDirCandidates(); const candidates: Candidate[] = []; |
