aboutsummaryrefslogtreecommitdiff
path: root/src/domains/scroll.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmail.com>2026-07-28 00:17:13 +0530
committerAman Kumar <145339995+amankumarsingh77@users.noreply.github.com>2026-08-02 19:12:46 +0530
commitbfba73fa2f1373abd8a5a704c9c833d6fce1b44f (patch)
treee684310863ef6d9aaa9a6bd3d4d3100d75ee9069 /src/domains/scroll.ts
parent5cfa7ccc8f4082db111bc0186c5fa3d44b767ad3 (diff)
refactor(domains): share target resolution and CDP error mapping
The ref-vs-x/y branch turned out to exist in one tool, not four; it is now one helper with tests covering the half-specified-coordinate and stale-ref cases. cdpCall folds the repeated cdp_error mapping at 24 active-session call sites; target-scoped callOnTarget/callBrowser sites are left alone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'src/domains/scroll.ts')
-rw-r--r--src/domains/scroll.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/domains/scroll.ts b/src/domains/scroll.ts
index f29e931..1819a48 100644
--- a/src/domains/scroll.ts
+++ b/src/domains/scroll.ts
@@ -1,6 +1,7 @@
import { Type } from "typebox";
import { type Result, err, ok } from "../util/result";
import { defineBrowserTool, type ToolErr, type ToolOk } from "../util/tool";
+import { cdpCall } from "./cdp-call";
const ScrollArgs = Type.Object({
x: Type.Optional(Type.Number({ description: "X coordinate where to scroll. Default: viewport center" })),
@@ -40,19 +41,19 @@ export const scrollTool = defineBrowserTool({
// The page target must be focused or Input events are dropped silently
// (mouseWheel hangs; synthesizeScrollGesture returns ok but no scroll).
// Page.bringToFront makes the target the active one in the browser.
- const front = await client.session().call("Page.bringToFront", {});
- if (!front.success) return err({ kind: "cdp_error", message: front.error.message });
+ const front = await cdpCall(client, "Page.bringToFront", {});
+ if (!front.success) return front;
// Establish compositor mouse position before mouseWheel; without this,
// CDP sometimes drops the wheel event with a timeout.
- const moved = await client.session().call("Input.dispatchMouseEvent", {
+ const moved = await cdpCall(client, "Input.dispatchMouseEvent", {
type: "mouseMoved", x: cx, y: cy, button: "none", buttons: 0,
});
- if (!moved.success) return err({ kind: "cdp_error", message: moved.error.message });
- const wheel = await client.session().call("Input.dispatchMouseEvent", {
+ if (!moved.success) return moved;
+ const wheel = await cdpCall(client, "Input.dispatchMouseEvent", {
type: "mouseWheel", x: cx, y: cy, deltaX: dx, deltaY: dy,
button: "none", buttons: 0, pointerType: "mouse",
});
- if (!wheel.success) return err({ kind: "cdp_error", message: wheel.error.message });
+ if (!wheel.success) return wheel;
return ok({
text: `Scrolled at (${cx}, ${cy}) by (${dx}, ${dy})`,
details: { x: cx, y: cy, deltaX: dx, deltaY: dy },