From 632600ec0a0a68d9327e19bd419a1ae72047955f Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 21:55:55 +0530 Subject: refactor: one door from a tool to the browser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Four routes coexisted: cdpCall, a raw client.session().call, a session held in a local and called directly, and client.evaluateJs — and five files mixed two or three of them. The CdpError-to-ToolErr mapping was hand-copied at nine sites, plus a private copy in isolated-tab.ts. domains/cdp-call.ts now owns all of it: cdpErrToToolErr, cdpCall, cdpCallOnTarget, cdpCallBrowser, evalJs. Every other file under src/domains goes through them, which also removes a pile of `if (!r.success) return err({ kind: "cdp_error", ... })` boilerplate in favour of returning the failed Result as-is. Two scanner rules keep it that way, scoped to src/domains/ so the layer that legitimately owns the session — cdp/ and client.ts — is unaffected. Scoping is new to the rule model; without it the rules fired on the transport itself. One deliberate behaviour change: a CDP timeout now surfaces as kind "timeout" rather than "cdp_error". isolated-tab.ts already did this and the other 13 sites flattened it; the shared mapper uses the honest label rather than preserving the mislabel. Co-Authored-By: Claude Opus 5 (1M context) --- src/domains/ref-resolve.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/domains/ref-resolve.ts') diff --git a/src/domains/ref-resolve.ts b/src/domains/ref-resolve.ts index ece308e..0f509a0 100644 --- a/src/domains/ref-resolve.ts +++ b/src/domains/ref-resolve.ts @@ -2,6 +2,7 @@ import type { BrowserClient } from "../client"; import { type Result, err, ok } from "../util/result"; import type { ToolErr } from "../util/tool"; import { type Box, boxOf } from "./box"; +import { cdpCall } from "./cdp-call"; import { buildTree, collectInteractiveTargets, type SlimNode } from "./snapshot"; const staleErr = (ref: string): ToolErr => ({ @@ -16,7 +17,7 @@ export const resolveRefToObjectId = async ( ): Promise> => { const backendId = client.session().resolveRef(ref); if (backendId === undefined) return err(staleErr(ref)); - const resolved = await client.session().call("DOM.resolveNode", { backendNodeId: backendId }); + const resolved = await cdpCall(client, "DOM.resolveNode", { backendNodeId: backendId }); if (!resolved.success) { return err(staleErr(ref)); } @@ -49,7 +50,7 @@ export const interactiveDiff = async (client: BrowserClient): Promise => const session = client.session(); const prev = session.refSignatures(); - const axRes = await session.call("Accessibility.getFullAXTree", {}); + const axRes = await cdpCall(client, "Accessibility.getFullAXTree", {}); if (!axRes.success) return ""; const rawNodes = axRes.data.nodes; const slim = buildTree(rawNodes, { interestingOnly: true, maxNodes: 1000 }); -- cgit v1.2.3