feat(browser): add scrollintoview action

This commit is contained in:
Peter Steinberger
2026-01-12 21:56:08 +00:00
parent 2faf7cea93
commit 6857f16609
5 changed files with 87 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ type ActKind =
| "evaluate"
| "fill"
| "hover"
| "scrollIntoView"
| "press"
| "resize"
| "select"
@@ -154,6 +155,7 @@ export function registerBrowserAgentRoutes(
kind !== "evaluate" &&
kind !== "fill" &&
kind !== "hover" &&
kind !== "scrollIntoView" &&
kind !== "press" &&
kind !== "resize" &&
kind !== "select" &&
@@ -257,6 +259,21 @@ export function registerBrowserAgentRoutes(
});
return res.json({ ok: true, targetId: tab.targetId });
}
case "scrollIntoView": {
const ref = toStringOrEmpty(body.ref);
if (!ref) return jsonError(res, 400, "ref is required");
const timeoutMs = toNumber(body.timeoutMs);
const scrollRequest: Parameters<
typeof pw.scrollIntoViewViaPlaywright
>[0] = {
cdpUrl,
targetId: tab.targetId,
ref,
};
if (timeoutMs) scrollRequest.timeoutMs = timeoutMs;
await pw.scrollIntoViewViaPlaywright(scrollRequest);
return res.json({ ok: true, targetId: tab.targetId });
}
case "drag": {
const startRef = toStringOrEmpty(body.startRef);
const endRef = toStringOrEmpty(body.endRef);