The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.
JavaScript agent-skillsai-agentautomationbrowserbrowser-automationclaude-codecodexhermes-agentskillsskills-sh
Fix page actions on moving elements
Aute2dfba3dc73e6
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/index.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/index.mjsindex 627e742..98f52d7 100644--- a/package/ego-browser/scripts/real-browser-e2e/cases/index.mjs+++ b/package/ego-browser/scripts/real-browser-e2e/cases/index.mjs@@ -9,6 +9,7 @@ import { keyboardCase } from "./keyboard.mjs";import { keyboardRegressionCase } from "./keyboard-regression.mjs";import { pageKeyboardInterfaceCase } from "./page-keyboard.mjs";import { pageClickHitTargetCase } from "./page-click-hit-target.mjs";+import { pageActionMotionCase } from "./page-action-motion.mjs";import { pageDragAndDrawCase } from "./page-drag-and-draw.mjs";import { pageJavaScriptDialogHandlingCase } from "./page-dialogs.mjs";import { pageMediaPlaybackCase } from "./page-media-playback.mjs";@@ -86,6 +87,7 @@ export const e2eCases = [{ name: "page fetch", body: pageFetchCase },{ name: "page actions and popup adoption", body: pageActionsAndPopupCase },{ name: "Page click hit target", body: pageClickHitTargetCase },+ { name: "Page action motion tolerance", body: pageActionMotionCase },{ name: "Page drag and canvas drawing", body: pageDragAndDrawCase },{name: "Page JavaScript dialog handling",diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/page-action-motion.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/page-action-motion.mjsnew file mode 100644index 0000000..0856a3b--- /dev/null+++ b/package/ego-browser/scripts/real-browser-e2e/cases/page-action-motion.mjs@@ -0,0 +1,102 @@+export function pageActionMotionCase() {+ return `+ const task = await taskSpace(taskName);+ const page = await newPageAt(task, baseUrl + "/?workflow=page-action-motion");++ await page.evaluate(() => {+ window.__motionActions = {+ visibleClicks: 0,+ offscreenClicks: 0,+ visibleClickTrusted: false,+ offscreenClickTrusted: false,+ visibleInputTrusted: false,+ offscreenInputTrusted: false,+ wheelEvents: 0,+ };+ const state = window.__motionActions;+ const animate = (element) => element.animate(+ [+ { transform: "translateX(-4px)" },+ { transform: "translateX(4px)" },+ ],+ { duration: 600, iterations: Infinity, direction: "alternate" },+ );++ const visibleButton = document.createElement("button");+ visibleButton.id = "continuously-moving-button";+ visibleButton.textContent = "Continuously moving action";+ visibleButton.style.cssText =+ "position:fixed;left:80px;top:80px;width:240px;height:64px;z-index:20";+ visibleButton.addEventListener("click", (event) => {+ state.visibleClicks += 1;+ state.visibleClickTrusted ||= event.isTrusted;+ });++ const visibleInput = document.createElement("input");+ visibleInput.id = "continuously-moving-field";+ visibleInput.style.cssText =+ "position:fixed;left:80px;top:180px;width:240px;height:40px;z-index:20";+ visibleInput.addEventListener("input", (event) => {+ state.visibleInputTrusted ||= event.isTrusted;+ });++ const spacer = document.createElement("div");+ spacer.style.height = "2200px";+ const offscreenButton = document.createElement("button");+ offscreenButton.id = "wheel-animated-button";+ offscreenButton.textContent = "Wheel animated action";+ offscreenButton.style.cssText = "width:240px;height:64px";+ offscreenButton.addEventListener("click", (event) => {+ state.offscreenClicks += 1;+ state.offscreenClickTrusted ||= event.isTrusted;+ });+ const offscreenInput = document.createElement("input");+ offscreenInput.id = "wheel-animated-field";+ offscreenInput.style.cssText = "display:block;width:240px;height:40px;margin-top:24px";+ offscreenInput.addEventListener("input", (event) => {+ state.offscreenInputTrusted ||= event.isTrusted;+ });++ let wheelAnimationStarted = false;+ document.addEventListener("wheel", () => {+ state.wheelEvents += 1;+ if (wheelAnimationStarted) return;+ wheelAnimationStarted = true;+ animate(offscreenButton);+ animate(offscreenInput);+ }, true);++ document.body.append(+ visibleButton,+ visibleInput,+ spacer,+ offscreenButton,+ offscreenInput,+ );+ animate(visibleButton);+ animate(visibleInput);+ });++ await page.click("#continuously-moving-button");+ await page.fill("#continuously-moving-field", "visible motion");+ await page.click("#wheel-animated-button");+ await page.fill("#wheel-animated-field", "wheel motion");++ const result = await page.evaluate(() => ({+ ...window.__motionActions,+ visibleValue: document.querySelector("#continuously-moving-field").value,+ offscreenValue: document.querySelector("#wheel-animated-field").value,+ }));+ assertEqual(result.visibleClicks, 1, "click accepts a moving element while its current point is safe");+ assertEqual(result.offscreenClicks, 1, "click revalidates a wheel-animated element");+ assertEqual(result.visibleValue, "visible motion", "fill does not require a static rectangle");+ assertEqual(result.offscreenValue, "wheel motion", "fill survives wheel-triggered motion");+ assert(+ result.visibleClickTrusted && result.offscreenClickTrusted &&+ result.visibleInputTrusted && result.offscreenInputTrusted,+ "motion-tolerant actions still reach the page as trusted input"+ );+ assert(result.wheelEvents > 1, "the offscreen action uses trusted wheel motion");+ await page.close();+ `;+}diff --git a/package/ego-browser/src/driver/page-actions.ts b/package/ego-browser/src/driver/page-actions.tsindex 4d1031c..c05351f 100644--- a/package/ego-browser/src/driver/page-actions.ts+++ b/package/ego-browser/src/driver/page-actions.ts@@ -259,12 +259,15 @@ export async function clickInPage(services,target.sessionId,target.objectId,- options.position,- target.frameId,- "page.click",- options.force,- sessionId,- iframeSessions,+ {+ position: options.position,+ frameId: target.frameId,+ actionName: "page.click",+ hitTest: !options.force,+ stability: "recompute",+ pageSessionId: sessionId,+ iframeSessions,+ },);const cursorPoint = await cursorPointForElement(services,@@ -308,6 +311,14 @@ export async function clickInPage(target.objectId,"page.click",);+ if (!options.force) {+ await assertElementReceivesPointerEvents(+ services,+ target.sessionId,+ target.objectId,+ point.local,+ );+ }await dispatchMouseEvent(services, target.sessionId, {type: "mouseMoved",x: point.x,@@ -404,14 +415,12 @@ export async function fillInPage(resolved.sessionId,resolved.objectId,);- await resolveElementPoint(+ await scrollElementIntoView(services,resolved.sessionId,actionObjectId,- undefined,resolved.frameId,"page.fill",- true,sessionId,iframeSessions,);@@ -908,17 +917,14 @@ async function clickResolvedElement(pageSessionId = sessionId,iframeSessions = new Map<string, string>(),): Promise<void> {- const point = await resolveElementPoint(- services,- sessionId,- objectId,- undefined,+ const point = await resolveElementPoint(services, sessionId, objectId, {frameId,- "page.fill",- false,+ actionName: "page.fill",+ hitTest: true,+ stability: "recompute",pageSessionId,iframeSessions,- );+ });await assertElementReceivesPointerEvents(services,sessionId,@@ -1036,12 +1042,15 @@ export async function hoverInPage(services,resolved.sessionId,resolved.objectId,- options.position,- resolved.frameId,- "page.hover",- options.force,- sessionId,- iframeSessions,+ {+ position: options.position,+ frameId: resolved.frameId,+ actionName: "page.hover",+ hitTest: !options.force,+ stability: "strict",+ pageSessionId: sessionId,+ iframeSessions,+ },);showAgentActionLabel(services, options.label);await dispatchMouseEvent(services, resolved.sessionId, {@@ -1098,23 +1107,29 @@ export async function dragAndDropInPage(services,source.sessionId,source.objectId,- options.sourcePosition,- source.frameId,- "page.dragAndDrop",- options.force,- sessionId,- iframeSessions,+ {+ position: options.sourcePosition,+ frameId: source.frameId,+ actionName: "page.dragAndDrop",+ hitTest: !options.force,+ stability: "strict",+ pageSessionId: sessionId,+ iframeSessions,+ },);const targetPoint = await resolveElementPoint(services,target.sessionId,target.objectId,- options.targetPosition,- target.frameId,- "page.dragAndDrop",- options.force,- sessionId,- iframeSessions,+ {+ position: options.targetPosition,+ frameId: target.frameId,+ actionName: "page.dragAndDrop",+ hitTest: !options.force,+ stability: "strict",+ pageSessionId: sessionId,+ iframeSessions,+ },);const button = options.button ?? "left";const buttons = pressedButtons(button);@@ -1292,17 +1307,54 @@ export async function wheelInPage();}+// Editing only needs visibility, clicking needs a fresh safe point, and+// hover/drag retain the stronger static-geometry contract.+type ElementPointStability = "none" | "recompute" | "strict";++type ResolveElementPointOptions = {+ position?: { x: number; y: number };+ frameId?: string;+ actionName?: string;+ hitTest?: boolean;+ stability?: ElementPointStability;+ pageSessionId?: string;+ iframeSessions?: Map<string, string>;+};++async function scrollElementIntoView(+ services: PageActionServices,+ sessionId: string,+ objectId: string,+ frameId: string | undefined,+ actionName: string,+ pageSessionId: string,+ iframeSessions: Map<string, string>,+): Promise<void> {+ await resolveElementPoint(services, sessionId, objectId, {+ frameId,+ actionName,+ hitTest: false,+ stability: "none",+ pageSessionId,+ iframeSessions,+ });+}+async function resolveElementPoint(services: PageActionServices,sessionId: string,objectId: string,- position?: { x: number; y: number },- frameId?: string,- actionName = "page.click",- force = false,- pageSessionId = sessionId,- iframeSessions = new Map<string, string>(),+ options: ResolveElementPointOptions = {},): Promise<{ x: number; y: number; local: { x: number; y: number } }> {+ const {+ position,+ frameId,+ actionName = "page.click",+ hitTest = true,+ stability = "strict",+ pageSessionId = sessionId,+ iframeSessions = new Map<string, string>(),+ } = options;if (position !== undefined &&(!position ||@@ -1317,18 +1369,10 @@ async function resolveElementPoint(const pointExpression = position? "({x:rect.x+position.x,y:rect.y+position.y})": "actionPointForElement(this)";- const expression = `async function(${position ? "position" : ""}) {- ${force ? SCROLL_TARGET_HELPERS : HIT_TARGET_HELPERS}- if (!this.isConnected) return { error: "element is not connected" };- let rect = this.getBoundingClientRect();- let point = ${pointExpression};- if (rect.width <= 0 || rect.height <= 0 || !point) {- return { error: "element is not visible" };- }- const scroll = scrollRequestForPoint(this, point);- if (scroll) return { scroll };- const firstRect = { x: rect.x, y: rect.y, width: rect.width, height: rect.height };- await new Promise((resolve) => {+ const settleExpression =+ stability === "none"+ ? ""+ : `await new Promise((resolve) => {let settled = false;const finish = () => {if (settled) return;@@ -1339,7 +1383,11 @@ async function resolveElementPoint(const timer = setTimeout(finish, 100);requestAnimationFrame(() => requestAnimationFrame(finish));});- rect = this.getBoundingClientRect();+ rect = this.getBoundingClientRect();`;+ const strictStabilityExpression =+ stability === "strict"+ ? `const firstRect = { x: rect.x, y: rect.y, width: rect.width, height: rect.height };+ ${settleExpression}if (Math.abs(rect.x - firstRect.x) > 0.25 ||Math.abs(rect.y - firstRect.y) > 0.25 ||@@ -1347,9 +1395,21 @@ async function resolveElementPoint(Math.abs(rect.height - firstRect.height) > 0.25) {return { error: "element is not stable" };+ }`+ : settleExpression;+ const expression = `async function(${position ? "position" : ""}) {+ ${hitTest ? HIT_TARGET_HELPERS : SCROLL_TARGET_HELPERS}+ if (!this.isConnected) return { error: "element is not connected" };+ let rect = this.getBoundingClientRect();+ let point = ${pointExpression};+ if (rect.width <= 0 || rect.height <= 0 || !point) {+ return { error: "element is not visible" };}+ const scroll = scrollRequestForPoint(this, point);+ if (scroll) return { scroll };+ ${strictStabilityExpression}point = ${pointExpression};- if (!${force ? "true" : "false"}) {+ if (${hitTest ? "true" : "false"}) {const interceptor = interceptingElementAtPoint(this, point);if (interceptor) {return { error: describeHitTarget(interceptor) + " intercepts pointer events" };diff --git a/package/ego-browser/src/page-actions.test.mjs b/package/ego-browser/src/page-actions.test.mjsindex 84e5278..b84f9ac 100644--- a/package/ego-browser/src/page-actions.test.mjs+++ b/package/ego-browser/src/page-actions.test.mjs@@ -91,10 +91,24 @@ test("Page click translates same-process iframe coordinates to the Page viewport([method, params]) =>method === "Input.dispatchMouseEvent" && params.type === "mouseMoved",);+ const initialMoveIndex = calls.findIndex(+ ([method, params]) =>+ method === "Input.dispatchMouseEvent" && params.type === "mouseMoved",+ );const pressIndex = calls.findIndex(([method, params]) =>method === "Input.dispatchMouseEvent" && params.type === "mousePressed",);+ assert(+ calls+ .slice(initialMoveIndex + 1, moveIndex)+ .some(+ ([method, params]) =>+ method === "Runtime.callFunctionOn" &&+ params.functionDeclaration.includes("elementsFromPoint"),+ ),+ "iframe clicks recheck the frame-local hit target after the initial pointer move",+ );assert.equal(calls.slice(moveIndex + 1, pressIndex)diff --git a/package/ego-browser/src/page-model.test.mjs b/package/ego-browser/src/page-model.test.mjsindex 880c2a2..3ad73f5 100644--- a/package/ego-browser/src/page-model.test.mjs+++ b/package/ego-browser/src/page-model.test.mjs@@ -4510,6 +4510,11 @@ test("Page click uses the wheel motion engine to bring an element into view", as/setTimeout\(finish, 100\)/,"stability sampling must not wait indefinitely for background animation frames",);+ assert.doesNotMatch(+ stabilityCall[2].functionDeclaration,+ /firstRect|element is not stable/,+ "click safety follows the recomputed hit point instead of requiring a static rectangle",+ );const wheelCalls = fixture.calls.filter(([kind, method, params]) =>kind === "cdp" &&@@ -4554,6 +4559,11 @@ test("Page fill uses the wheel motion engine to bring an element into view", asy"the field position is rechecked after scrolling",);assert.doesNotMatch(pointCalls[0][2].functionDeclaration, /scrollIntoView/);+ assert.doesNotMatch(+ pointCalls[0][2].functionDeclaration,+ /requestAnimationFrame|element is not stable/,+ "fill scrolling must not block keyboard input on element motion",+ );const wheelCalls = fixture.calls.filter(([kind, method, params]) =>kind === "cdp" &&