diff options
| author | amankumarsingh77 <amankumarsingh7702@gmail.com> | 2026-07-27 23:10:18 +0530 |
|---|---|---|
| committer | Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> | 2026-08-02 19:12:46 +0530 |
| commit | 931576443dcb990761cb7e68e354465145f9292d (patch) | |
| tree | 26cb097e8f7fcbce269db66de5e63b08b7862ded /src | |
| parent | 44e3271c148e991e5547f36e3cfe596d71c91cfc (diff) | |
refactor(profile): drop CDP casts in favour of the typed boundary
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/profile/bind.ts | 11 | ||||
| -rw-r--r-- | src/profile/browser-process.ts | 6 |
2 files changed, 7 insertions, 10 deletions
diff --git a/src/profile/bind.ts b/src/profile/bind.ts index 5fbac6f..abdc5cc 100644 --- a/src/profile/bind.ts +++ b/src/profile/bind.ts @@ -20,6 +20,7 @@ import type { BrowserClient } from "../client"; import { attachTo } from "../cdp/attach"; +import type { ResultOf } from "../cdp/commands"; import { type CdpError, cdpError } from "../cdp/errors"; import { getWindowId } from "../cdp/window"; import { type Result, err, ok } from "../util/result"; @@ -31,18 +32,12 @@ import type { ProfilePin } from "./store"; const SEED_DEADLINE_MS = 15_000; const SEED_POLL_MS = 500; -type PageTarget = { - readonly targetId: string; - readonly type: string; - readonly url: string; - readonly browserContextId?: string; -}; +type PageTarget = ResultOf<"Target.getTargets">["targetInfos"][number]; const pageTargets = async (client: BrowserClient): Promise<ReadonlyArray<PageTarget>> => { const r = await client.session().callBrowser("Target.getTargets"); if (!r.success) return []; - const data = r.data as { targetInfos: ReadonlyArray<PageTarget> }; - return data.targetInfos.filter((t) => t.type === "page"); + return r.data.targetInfos.filter((t) => t.type === "page"); }; const manualFallbackHint = (pin: ProfilePin): string => diff --git a/src/profile/browser-process.ts b/src/profile/browser-process.ts index 77bc05c..ac31d4d 100644 --- a/src/profile/browser-process.ts +++ b/src/profile/browser-process.ts @@ -373,9 +373,11 @@ export const detectRunningBrowser = async (preferUserDataDir?: string): Promise< : await collectLinux(); if (candidates.length === 0) return { running: false }; - let best = candidates[0] as BrowserCandidate; + const [first, ...rest] = candidates; + if (!first) return { running: false }; + let best = first; let bestRank = rankBrowserCandidate(best, preferUserDataDir); - for (const candidate of candidates.slice(1)) { + for (const candidate of rest) { const rank = rankBrowserCandidate(candidate, preferUserDataDir); if (rank > bestRank) { best = candidate; |
