Skip to content

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.

perf(ego-browser): collapse click actionability checks into one injected call

Zhuowei Wangc4ee581fd5e1
diff --git a/package/ego-browser/src/driver/action-target.ts b/package/ego-browser/src/driver/action-target.ts
index a7d2d15..0c1f3e9 100644
--- a/package/ego-browser/src/driver/action-target.ts
+++ b/package/ego-browser/src/driver/action-target.ts
@@ -244,6 +244,15 @@ export const SCROLL_TARGET_HELPERS = `
${SCROLL_TARGET_FUNCTIONS}
`;
+/**
+ * Scroll targeting plus the enabled check, for a forced click that skips the
+ * hit test but still refuses a disabled element.
+ */
+export const ENABLED_SCROLL_TARGET_HELPERS = `
+ ${ACTION_TARGET_STATE_HELPERS}
+ ${SCROLL_TARGET_FUNCTIONS}
+`;
+
/** Editing semantics layered on top of the shared composed-tree traversal. */
export const EDIT_ACTION_TARGET_HELPERS = `
${COMPOSED_TREE_HELPERS}
diff --git a/package/ego-browser/src/driver/page-actions.ts b/package/ego-browser/src/driver/page-actions.ts
index f49d72f..93659fc 100644
--- a/package/ego-browser/src/driver/page-actions.ts
+++ b/package/ego-browser/src/driver/page-actions.ts
@@ -7,6 +7,7 @@ import { RefMap } from "../ref-map.js";
import {
ACTION_TARGET_STATE_HELPERS,
EDIT_ACTION_TARGET_HELPERS,
+ ENABLED_SCROLL_TARGET_HELPERS,
HIT_TARGET_HELPERS,
SCROLL_TARGET_HELPERS,
} from "./action-target.js";
@@ -258,6 +259,8 @@ export async function clickInPage(
},
);
try {
+ // One page round trip computes the action point and verifies that the
+ // element is visible, enabled, and (unless forced) the hit target there.
let point = await resolveElementPoint(
services,
target.sessionId,
@@ -267,6 +270,7 @@ export async function clickInPage(
frameId: target.frameId,
actionName: "page.click",
hitTest: !options.force,
+ requireEnabled: true,
stability: "recompute",
pageSessionId: sessionId,
iframeSessions,
@@ -308,20 +312,13 @@ export async function clickInPage(
sessionId,
);
point = { ...pagePoint, local: point.local };
- await assertElementEnabled(
+ await assertClickTargetActionable(
services,
target.sessionId,
target.objectId,
- "page.click",
+ point.local,
+ { hitTest: !options.force },
);
- if (!options.force) {
- await assertElementReceivesPointerEvents(
- services,
- target.sessionId,
- target.objectId,
- point.local,
- );
- }
await dispatchMouseEvent(services, target.sessionId, {
type: "mouseMoved",
x: point.x,
@@ -333,24 +330,18 @@ export async function clickInPage(
}
for (let count = 1; count <= clickCount; count += 1) {
// Moving the pointer or completing an earlier click can change layout.
- // Recheck before every press so hover-created overlays fail closed.
- // A same-process iframe must keep its native move/press sequence
- // contiguous; its state was checked immediately before that gesture's
- // final move.
+ // Recheck the enabled state and the hit target in one page call before
+ // every press so hover-created overlays fail closed. A same-process
+ // iframe must keep its native move/press sequence contiguous; its state
+ // was checked immediately before that gesture's final move, and later
+ // presses in any iframe only recheck the enabled state.
if (!target.frameId || count > 1) {
- await assertElementEnabled(
- services,
- target.sessionId,
- target.objectId,
- "page.click",
- );
- }
- if (!options.force && !target.frameId) {
- await assertElementReceivesPointerEvents(
+ await assertClickTargetActionable(
services,
target.sessionId,
target.objectId,
point.local,
+ { hitTest: !options.force && !target.frameId },
);
}
await dispatchMouseEvent(services, target.sessionId, {
@@ -1317,6 +1308,8 @@ type ResolveElementPointOptions = {
frameId?: string;
actionName?: string;
hitTest?: boolean;
+ /** Also fail with "element is disabled" in the same page round trip. */
+ requireEnabled?: boolean;
stability?: ElementPointStability;
pageSessionId?: string;
iframeSessions?: Map<string, string>;
@@ -1352,6 +1345,7 @@ async function resolveElementPoint(
frameId,
actionName = "page.click",
hitTest = true,
+ requireEnabled = false,
stability = "strict",
pageSessionId = sessionId,
iframeSessions = new Map<string, string>(),
@@ -1398,14 +1392,22 @@ async function resolveElementPoint(
return { error: "element is not stable" };
}`
: settleExpression;
+ const helpers = hitTest
+ ? HIT_TARGET_HELPERS
+ : requireEnabled
+ ? ENABLED_SCROLL_TARGET_HELPERS
+ : SCROLL_TARGET_HELPERS;
const expression = `async function(${position ? "position" : ""}) {
- ${hitTest ? HIT_TARGET_HELPERS : SCROLL_TARGET_HELPERS}
+ ${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" };
}
+ if (${requireEnabled ? "true" : "false"} && isActionTargetDisabled(this)) {
+ return { error: "element is disabled" };
+ }
const scroll = scrollRequestForPoint(this, point);
if (scroll) return { scroll };
${strictStabilityExpression}
@@ -1782,6 +1784,53 @@ async function cursorPointForElement(
}
}
+/**
+ * Re-validate a click target after the pointer moved, in one page round trip:
+ * the element must still be connected and enabled and, when `hitTest` is set,
+ * nothing may intercept pointer events at the frame-local `point`. Failures
+ * keep the resolver's wording and order (disabled before intercepted) so the
+ * retry loop and callers see the same transient errors as before.
+ */
+async function assertClickTargetActionable(
+ services: PageActionServices,
+ sessionId: string,
+ objectId: string,
+ point: { x: number; y: number },
+ options: { hitTest: boolean; actionName?: string },
+): Promise<void> {
+ const { hitTest, actionName = "page.click" } = options;
+ const expression = `function clickTargetActionable(point) {
+ ${hitTest ? HIT_TARGET_HELPERS : ACTION_TARGET_STATE_HELPERS}
+ if (!this.isConnected) return { error: "element is not connected" };
+ if (isActionTargetDisabled(this)) return { error: "element is disabled" };
+ if (${hitTest ? "true" : "false"}) {
+ const interceptor = interceptingElementAtPoint(this, point);
+ if (interceptor) {
+ return { error: describeHitTarget(interceptor) + " intercepts pointer events" };
+ }
+ }
+ return { ok: true };
+ }`;
+ const response = await services.cdp(
+ "Runtime.callFunctionOn",
+ {
+ functionDeclaration: expression,
+ objectId,
+ arguments: [{ value: point }],
+ returnByValue: true,
+ awaitPromise: false,
+ },
+ sessionId,
+ );
+ const result = runtimeValue(response, expression);
+ if (typeof result?.error === "string") {
+ throw new ElementResolutionError(
+ `${actionName} failed: ${result.error}`,
+ "transient",
+ );
+ }
+}
+
async function assertElementReceivesPointerEvents(
services: PageActionServices,
sessionId: string,
diff --git a/package/ego-browser/src/driver/pointer.test.mjs b/package/ego-browser/src/driver/pointer.test.mjs
index c3b5e3f..db3b874 100644
--- a/package/ego-browser/src/driver/pointer.test.mjs
+++ b/package/ego-browser/src/driver/pointer.test.mjs
@@ -165,100 +165,137 @@ test("scroll propagates user-control errors from wheel dispatch", async () => {
}
});
-test("click triggers probe fallback when CDP click is not trusted", async () => {
+function withFakeEgo(run) {
const originalEgo = globalThis.ego;
globalThis.ego = { sendCDPMessage: () => {} };
- let probeEvaluateCount = 0;
- const evaluateExpressions = [];
+ return run().finally(() => {
+ if (originalEgo === undefined) delete globalThis.ego;
+ else globalThis.ego = originalEgo;
+ });
+}
+
+test("click dispatches native input without a page-side probe when the renderer acknowledges it", async () => {
+ const calls = [];
const restore = setOverrides({
- cdpOverride(method, params, sessionId) {
+ cdpOverride(method, params) {
+ calls.push({ method, params });
+ if (method === "Runtime.evaluate") {
+ // Element resolution (buildSelectorCenterJs) — return center point
+ return { result: { value: { x: 100, y: 200 } } };
+ }
+ return {};
+ },
+ });
+ try {
+ await withFakeEgo(() => click("#target"));
+ } finally {
+ restore();
+ }
+
+ assert.deepEqual(
+ calls.map((call) =>
+ call.method === "Input.dispatchMouseEvent"
+ ? `${call.method}:${call.params.type}`
+ : call.method,
+ ),
+ [
+ "Runtime.evaluate",
+ "Input.dispatchMouseEvent:mouseMoved",
+ "Input.dispatchMouseEvent:mousePressed",
+ "Input.dispatchMouseEvent:mouseReleased",
+ ],
+ "a normal click is element resolution plus three native input events",
+ );
+ assert.equal(
+ calls.some((call) =>
+ call.params.expression?.includes("__egoBrowserInputProbes"),
+ ),
+ false,
+ "the normal path never installs or reads a click probe",
+ );
+});
+
+test("click probes for the trusted click and falls back to synthetic events only after a dispatch timeout", async () => {
+ const calls = [];
+ const probeExpressions = [];
+ const restore = setOverrides({
+ cdpOverride(method, params) {
+ calls.push({ method, params });
if (method === "Runtime.evaluate") {
- // Probe calls contain __egoBrowserInputProbes; element resolution does not
if (params.expression?.includes("__egoBrowserInputProbes")) {
- probeEvaluateCount++;
- evaluateExpressions.push(params.expression);
- if (probeEvaluateCount === 1) {
+ probeExpressions.push(params.expression);
+ if (probeExpressions.length === 1) {
// installClickProbe — elementFromPoint returns truthy
return { result: { value: true } };
}
- // finishClickProbe — simulate CDP click was NOT seen
+ // finishClickProbe — the trusted click never arrived
return { result: { value: { seen: false, fallback: true } } };
}
- // Element resolution (buildSelectorCenterJs) — return center point
return { result: { value: { x: 100, y: 200 } } };
}
- // Input.dispatchMouseEvent calls proceed normally
+ if (method === "Input.dispatchMouseEvent") {
+ // Simulate CDP timeout — the browser couldn't dispatch the event
+ throw new Error("CDP request timed out: Input.dispatchMouseEvent");
+ }
return {};
},
});
try {
- await click("#target");
+ // Should NOT throw — timeout is absorbed because fallback succeeded
+ await withFakeEgo(() => click("#target"));
} finally {
restore();
- if (originalEgo === undefined) delete globalThis.ego;
- else globalThis.ego = originalEgo;
}
- // 2 probe Runtime.evaluate calls: install + finish (element resolution excluded)
assert.equal(
- probeEvaluateCount,
+ probeExpressions.length,
2,
- "Runtime.evaluate called for install and finish probes",
+ "the probe is installed and read once each after the timeout",
);
- assert.match(
- evaluateExpressions[0],
- /__egoBrowserInputProbes/,
- "install expression sets up click probe",
+ const firstInput = calls.findIndex(
+ (call) => call.method === "Input.dispatchMouseEvent",
+ );
+ const probeInstall = calls.findIndex((call) =>
+ call.params.expression?.includes("__egoBrowserInputProbes"),
+ );
+ assert(
+ firstInput >= 0 && probeInstall > firstInput,
+ "the probe is installed only after native input timed out",
);
assert.match(
- evaluateExpressions[1],
+ probeExpressions[1],
/dispatchEvent/,
"finish expression contains fallback mouse events",
);
assert.match(
- evaluateExpressions[1],
+ probeExpressions[1],
/MouseEvent/,
"finish expression dispatches MouseEvent in fallback",
);
});
-test("click absorbs CDP timeout when probe fallback succeeds", async () => {
- const originalEgo = globalThis.ego;
- globalThis.ego = { sendCDPMessage: () => {} };
- let probeEvaluateCount = 0;
+test("click rethrows a dispatch timeout when the fallback finds no element", async () => {
const restore = setOverrides({
- cdpOverride(method, params, sessionId) {
+ cdpOverride(method, params) {
if (method === "Runtime.evaluate") {
- // Probe calls contain __egoBrowserInputProbes; element resolution does not
if (params.expression?.includes("__egoBrowserInputProbes")) {
- probeEvaluateCount++;
- if (probeEvaluateCount === 1) {
- return { result: { value: true } };
- }
- // Fallback succeeded
- return { result: { value: { seen: false, fallback: true } } };
+ // installClickProbe — nothing under the point
+ return { result: { value: false } };
}
- // Element resolution (buildSelectorCenterJs) — return center point
return { result: { value: { x: 100, y: 200 } } };
}
if (method === "Input.dispatchMouseEvent") {
- // Simulate CDP timeout — the browser couldn't dispatch the event
throw new Error("CDP request timed out: Input.dispatchMouseEvent");
}
return {};
},
});
try {
- // Should NOT throw — timeout is absorbed because fallback succeeded
- await click("#target");
+ await assert.rejects(
+ () => withFakeEgo(() => click("#target")),
+ /CDP request timed out: Input\.dispatchMouseEvent/,
+ );
} finally {
restore();
- if (originalEgo === undefined) delete globalThis.ego;
- else globalThis.ego = originalEgo;
}
-
- assert.ok(
- probeEvaluateCount >= 2,
- "probe install and finish were called despite CDP timeout",
- );
});
diff --git a/package/ego-browser/src/driver/pointer.ts b/package/ego-browser/src/driver/pointer.ts
index 5281950..06af052 100644
--- a/package/ego-browser/src/driver/pointer.ts
+++ b/package/ego-browser/src/driver/pointer.ts
@@ -62,7 +62,10 @@ type ScrollUntilCondition =
| null;
type MouseEventOptions = Record<string, unknown>;
-const INPUT_EVENT_DELAY_MS = 25;
+// Native mouse events are delivered in order by the renderer, so a click needs
+// no pause between move, press, and release. Explicit `delayMs` options and
+// the pointer-driven drags keep their caller-chosen pauses.
+const INPUT_EVENT_DELAY_MS = 0;
const INPUT_DISPATCH_TIMEOUT_MS = 1000;
/**
@@ -90,8 +93,6 @@ export async function click(target: MouseTarget, options: ClickOptions = {}) {
const buttons = pressedButtons(button);
const clickCount = options.clickCount ?? options.clicks ?? 1;
maybeHighlight(point, options.label);
- const probeId = await installClickProbe(point);
- let dispatchError: unknown = null;
try {
await dispatchMouse(point, "mouseMoved", {
button: "none",
@@ -111,15 +112,13 @@ export async function click(target: MouseTarget, options: ClickOptions = {}) {
});
} catch (error) {
if (!isInputDispatchTimeout(error)) throw error;
- dispatchError = error;
+ // The renderer did not acknowledge native input in time (typically an
+ // occluded or hidden window). Only this path pays for the page-side
+ // probe: it waits briefly for the trusted click to land and otherwise
+ // dispatches synthetic mouse events to the element under the point.
+ const completed = await recoverTimedOutClick(point, clickCount);
+ if (!completed) throw error;
}
- const completed = await finishClickProbe(
- point,
- probeId,
- clickCount,
- Boolean(dispatchError),
- );
- if (dispatchError && !completed) throw dispatchError;
}
/**
@@ -226,9 +225,15 @@ export async function dragMouse(
}
function inputEventDelay(ms = INPUT_EVENT_DELAY_MS) {
+ if (!(ms > 0)) return Promise.resolve();
return new Promise((resolve) => setTimeout(resolve, ms));
}
+async function recoverTimedOutClick(point: Point, clickCount: number) {
+ const probeId = await installClickProbe(point);
+ return finishClickProbe(point, probeId, clickCount);
+}
+
async function installClickProbe(point: Point) {
if (!canProbeInputFallback()) return null;
const id = `click_${Date.now()}_${Math.random().toString(16).slice(2)}`;
@@ -264,13 +269,11 @@ async function finishClickProbe(
point: Point,
id: string | null,
clickCount: number,
- settle: boolean,
) {
if (!id) return false;
- // The renderer dispatches the click before it acknowledges the mouse input,
- // so the probe is already decided once dispatch returned. Only a timed-out
- // dispatch needs a settle before the page is asked whether input arrived.
- if (settle) await inputEventDelay(50);
+ // The probe is installed after a dispatch timeout, so give a late trusted
+ // click a moment to land before the page is asked whether input arrived.
+ await inputEventDelay(50);
try {
const result = await cdp(
"Runtime.evaluate",
diff --git a/package/ego-browser/src/page-actions.test.mjs b/package/ego-browser/src/page-actions.test.mjs
index b84f9ac..4780d63 100644
--- a/package/ego-browser/src/page-actions.test.mjs
+++ b/package/ego-browser/src/page-actions.test.mjs
@@ -4,6 +4,196 @@ import assert from "node:assert/strict";
import { clickInPage } from "../dist/src/driver/page-actions.js";
import { RefMap } from "../dist/src/ref-map.js";
+/**
+ * Services for a top-level raw-selector click: the strict resolver counts and
+ * resolves the selector with Runtime.evaluate, the action point comes from the
+ * expression that settles layout, and every other page call answers `respond`.
+ */
+function topLevelClickServices({
+ respond = () => ({ ok: true }),
+ point = { x: 10, y: 20 },
+} = {}) {
+ const calls = [];
+ const services = {
+ calls,
+ async cdp(method, params = {}, sessionId) {
+ calls.push([method, params, sessionId]);
+ if (method === "Runtime.evaluate") {
+ return params.returnByValue === false
+ ? { result: { objectId: "button-1" } }
+ : { result: { value: 1 } };
+ }
+ if (method === "Runtime.callFunctionOn") {
+ const value = params.functionDeclaration.includes("setTimeout(finish")
+ ? point
+ : respond(params);
+ return { result: { value } };
+ }
+ return {};
+ },
+ async showAgentMousePosition() {},
+ async showAgentTaskState() {},
+ async sleep() {},
+ };
+ return services;
+}
+
+function actionSequence(calls) {
+ return calls
+ .filter(([method]) => method !== "Runtime.evaluate")
+ .map(([method, params]) =>
+ method === "Input.dispatchMouseEvent"
+ ? `${method}:${params.type}`
+ : method,
+ );
+}
+
+function pageCalls(calls) {
+ return calls
+ .filter(([method]) => method === "Runtime.callFunctionOn")
+ .map(([, params]) => params.functionDeclaration);
+}
+
+test("Page click validates a top-level target once before the move and once before the press", async () => {
+ const services = topLevelClickServices();
+
+ await clickInPage(services, "session:page", new RefMap(), "#button");
+
+ assert.deepEqual(actionSequence(services.calls), [
+ "Runtime.callFunctionOn",
+ "Input.dispatchMouseEvent:mouseMoved",
+ "Runtime.callFunctionOn",
+ "Input.dispatchMouseEvent:mousePressed",
+ "Input.dispatchMouseEvent:mouseReleased",
+ "Runtime.releaseObject",
+ ]);
+ const [pointCheck, pressCheck] = pageCalls(services.calls);
+ for (const check of [pointCheck, pressCheck]) {
+ assert.match(
+ check,
+ /isActionTargetDisabled\(this\)/,
+ "each page call verifies the enabled state",
+ );
+ assert.match(
+ check,
+ /interceptingElementAtPoint\(this, point\)/,
+ "each page call verifies the hit target",
+ );
+ }
+ assert.match(pointCheck, /setTimeout\(finish, 100\)/);
+ assert.doesNotMatch(
+ pressCheck,
+ /setTimeout\(finish, 100\)/,
+ "the pre-press recheck does not wait for layout again",
+ );
+ const pressEvents = services.calls.filter(
+ ([method, params]) =>
+ method === "Input.dispatchMouseEvent" && params.type !== "mouseMoved",
+ );
+ assert(
+ pressEvents.every(([, params]) => params.x === 10 && params.y === 20),
+ "press and release use the resolved action point",
+ );
+});
+
+test("Page click fails before any pointer input when the element is disabled", async () => {
+ const services = topLevelClickServices({
+ point: { error: "element is disabled" },
+ });
+
+ await assert.rejects(
+ () => clickInPage(services, "session:page", new RefMap(), "#button"),
+ (error) => {
+ assert.equal(error.name, "ElementResolutionError");
+ assert.equal(error.kind, "transient");
+ assert.equal(error.message, "page.click failed: element is disabled");
+ return true;
+ },
+ );
+ assert.equal(
+ services.calls.some(([method]) => method === "Input.dispatchMouseEvent"),
+ false,
+ );
+});
+
+test("Page click fails closed when the pre-press recheck reports an interceptor", async () => {
+ const services = topLevelClickServices({
+ respond: () => ({
+ error: '<div id="hover-overlay"> intercepts pointer events',
+ }),
+ });
+
+ await assert.rejects(
+ () => clickInPage(services, "session:page", new RefMap(), "#button"),
+ (error) => {
+ assert.equal(error.name, "ElementResolutionError");
+ assert.equal(error.kind, "transient");
+ assert.equal(
+ error.message,
+ 'page.click failed: <div id="hover-overlay"> intercepts pointer events',
+ );
+ return true;
+ },
+ );
+ assert.deepEqual(
+ actionSequence(services.calls),
+ [
+ "Runtime.callFunctionOn",
+ "Input.dispatchMouseEvent:mouseMoved",
+ "Runtime.callFunctionOn",
+ "Runtime.releaseObject",
+ ],
+ "the pointer moved but no press reached the page",
+ );
+});
+
+test("Page click force skips the hit test but still rejects a disabled element", async () => {
+ const services = topLevelClickServices();
+
+ await clickInPage(services, "session:page", new RefMap(), "#button", {
+ force: true,
+ });
+
+ for (const check of pageCalls(services.calls)) {
+ assert.match(check, /isActionTargetDisabled\(this\)/);
+ assert.doesNotMatch(check, /elementsFromPoint/);
+ }
+ assert.equal(
+ services.calls.filter(
+ ([method, params]) =>
+ method === "Input.dispatchMouseEvent" && params.type === "mousePressed",
+ ).length,
+ 1,
+ );
+});
+
+test("Page click rechecks the target before every press of a multi-click", async () => {
+ const services = topLevelClickServices();
+
+ await clickInPage(services, "session:page", new RefMap(), "#button", {
+ clickCount: 2,
+ });
+
+ assert.deepEqual(actionSequence(services.calls), [
+ "Runtime.callFunctionOn",
+ "Input.dispatchMouseEvent:mouseMoved",
+ "Runtime.callFunctionOn",
+ "Input.dispatchMouseEvent:mousePressed",
+ "Input.dispatchMouseEvent:mouseReleased",
+ "Runtime.callFunctionOn",
+ "Input.dispatchMouseEvent:mousePressed",
+ "Input.dispatchMouseEvent:mouseReleased",
+ "Runtime.releaseObject",
+ ]);
+ const presses = services.calls
+ .filter(
+ ([method, params]) =>
+ method === "Input.dispatchMouseEvent" && params.type === "mousePressed",
+ )
+ .map(([, params]) => params.clickCount);
+ assert.deepEqual(presses, [1, 2]);
+});
+
test("Page click translates same-process iframe coordinates to the Page viewport", async () => {
const calls = [];
const states = [];
diff --git a/package/ego-browser/src/page-model.test.mjs b/package/ego-browser/src/page-model.test.mjs
index 0582263..10e7eba 100644
--- a/package/ego-browser/src/page-model.test.mjs
+++ b/package/ego-browser/src/page-model.test.mjs
@@ -6059,7 +6059,8 @@ test("Page click retries when an iframe disappears during session discovery", as
assert.deepEqual(await page.click("#ready", { timeout: 1_000 }), {});
assert.equal(discoveries, 2);
- assert.deepEqual(discoveryTimeouts, [1_000, 500]);
+ // The retry runs 50ms later on the remaining budget.
+ assert.deepEqual(discoveryTimeouts, [1_000, 950]);
});
});
@@ -6093,6 +6094,8 @@ test("Page click reports the action timeout instead of a tail discovery timeout"
async ensureFrameSessions(_targetId, timeoutMs) {
discoveryTimeouts.push(timeoutMs);
if (timeoutMs < 250) {
+ // A discovery timeout consumes its whole budget before failing.
+ await fixture.services.sleep(timeoutMs);
const error = new Error("CDP request timed out: Target.getTargets");
error.code = "EGO_CDP_REQUEST_TIMEOUT";
throw error;
@@ -6181,6 +6184,7 @@ test("Page click reports the last transient state after its timeout", async () =
() => page.click("#changing", { timeout: 1_000 }),
/page\.click timed out after 1000ms.*not visible/i,
);
+ // The blocked target is re-examined every 50ms until the 1000ms deadline.
assert.equal(
fixture.calls.filter(
([kind, method, params]) =>
@@ -6188,7 +6192,7 @@ test("Page click reports the last transient state after its timeout", async () =
method === "Runtime.callFunctionOn" &&
params.functionDeclaration.includes("getBoundingClientRect"),
).length,
- 3,
+ 21,
);
assert.equal(
fixture.calls.some(
diff --git a/package/ego-browser/src/page-model.ts b/package/ego-browser/src/page-model.ts
index 6186fcf..b1fcdad 100644
--- a/package/ego-browser/src/page-model.ts
+++ b/package/ego-browser/src/page-model.ts
@@ -611,7 +611,10 @@ const PAGE_CLOSE_CONFIRM_INTERVAL_MS = 50;
const CREATED_SPACE_TAB_TIMEOUT_MS = 2_000;
const CREATED_SPACE_TAB_POLL_INTERVAL_MS = 50;
const DEFAULT_PAGE_ACTION_TIMEOUT_MS = 3_000;
-const PAGE_ACTION_RESOLUTION_RETRY_MS = 500;
+// A blocked target (hidden, disabled, covered) is re-examined at this cadence
+// until the action timeout; a short interval lets an element that becomes
+// actionable a few frames later be clicked without waiting most of a second.
+const PAGE_ACTION_RESOLUTION_RETRY_MS = 50;
// A missing action target stops being retried once the page has shown no DOM
// mutation and no network activity for this long; a page that is still
// loading or rendering keeps the full action timeout.