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.

fix(ego-browser): report actionability blockers

JackWangf897e9475e19
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/page-actionability.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/page-actionability.mjs
index 8975f03..6b1e15f 100644
--- a/package/ego-browser/scripts/real-browser-e2e/cases/page-actionability.mjs
+++ b/package/ego-browser/scripts/real-browser-e2e/cases/page-actionability.mjs
@@ -10,6 +10,8 @@ export function pageActionabilityCase() {
' .action-row { display: flex; gap: 12px; margin: 12px; min-height: 40px; }' +
' .drag-box { width: 80px; height: 40px; background: #ddd; }' +
'</style>' +
+ '<button id="hidden-action" hidden>Hidden action</button>' +
+ '<button id="zero-size-action" style="width:0;height:0;padding:0;border:0">Zero-size action</button>' +
'<div class="action-row">' +
' <button id="nested-disabled" disabled><span>Nested disabled action</span></button>' +
' <button id="native-disabled" disabled aria-disabled="false">Native disabled</button>' +
@@ -123,8 +125,19 @@ export function pageActionabilityCase() {
});
});
- await assertRejectsAny(
+ await assertRejects(
+ () => page.click("#hidden-action", { timeout: 150 }),
+ "element is hidden or inert",
+ "click explains that a matching element is hidden"
+ );
+ await assertRejects(
+ () => page.click("#zero-size-action", { timeout: 150 }),
+ "element has a zero-sized bounding box",
+ "click explains that a matching element has no usable size"
+ );
+ await assertRejects(
() => page.click('text="Nested disabled action"', { timeout: 150 }),
+ "element is disabled",
"click rejects a disabled control reached through its child"
);
assertEqual(
diff --git a/package/ego-browser/src/element-resolver.test.mjs b/package/ego-browser/src/element-resolver.test.mjs
index 5202347..b32f9d2 100644
--- a/package/ego-browser/src/element-resolver.test.mjs
+++ b/package/ego-browser/src/element-resolver.test.mjs
@@ -691,6 +691,97 @@ test("enabled action resolution permits opacity-zero native controls", async ()
);
});
+test("action resolution reports hidden and zero-sized blockers", async () => {
+ for (const blocker of [
+ "element is hidden or inert",
+ "element has a zero-sized bounding box",
+ ]) {
+ const cdp = new FakeCDP(async (method, params) => {
+ if (method !== "Runtime.evaluate") return {};
+ if (params.expression.includes("for (const element")) {
+ assert.match(params.expression, /element is hidden or inert/);
+ assert.match(
+ params.expression,
+ /element has a zero-sized bounding box/,
+ );
+ return { result: { value: blocker } };
+ }
+ if (params.expression.includes("__egoActionableMatches")) {
+ return { result: { value: 0 } };
+ }
+ return { result: { value: 1 } };
+ });
+
+ await assert.rejects(
+ () =>
+ resolveElementObjectId(
+ cdp,
+ "session:page",
+ new RefMap(),
+ "button.save",
+ new Map(),
+ { strict: true, actionability: "pointer-enabled" },
+ ),
+ (error) => {
+ assert.ok(error instanceof ElementResolutionError);
+ assert.equal(error.kind, "transient");
+ assert.match(error.message, new RegExp(blocker));
+ return true;
+ },
+ );
+ }
+});
+
+test("role action resolution reports visibility blockers", async () => {
+ const cdp = new FakeCDP(async (method, params) => {
+ if (method === "Accessibility.getFullAXTree") {
+ return {
+ nodes: [
+ {
+ role: { value: "button" },
+ name: { value: "Hidden" },
+ backendDOMNodeId: 101,
+ },
+ ],
+ };
+ }
+ if (method === "DOM.resolveNode") {
+ return { object: { objectId: "hidden-button" } };
+ }
+ if (method === "Runtime.callFunctionOn") {
+ assert.match(params.functionDeclaration, /element is hidden or inert/);
+ assert.match(
+ params.functionDeclaration,
+ /element has a zero-sized bounding box/,
+ );
+ return {
+ result: {
+ value: { actionable: false, blocker: "element is hidden or inert" },
+ },
+ };
+ }
+ return {};
+ });
+
+ await assert.rejects(
+ () =>
+ resolveElementObjectId(
+ cdp,
+ "session:page",
+ new RefMap(),
+ 'loc=role:button[name="Hidden"]',
+ new Map(),
+ { actionability: "pointer-enabled" },
+ ),
+ (error) => {
+ assert.ok(error instanceof ElementResolutionError);
+ assert.equal(error.kind, "transient");
+ assert.match(error.message, /element is hidden or inert/);
+ return true;
+ },
+ );
+});
+
test("ambiguous raw XPath selectors fail instead of choosing the first match", async () => {
const cdp = new FakeCDP(async (method, params) => {
if (method === "Runtime.evaluate") {
diff --git a/package/ego-browser/src/element-resolver.ts b/package/ego-browser/src/element-resolver.ts
index f8b8453..737dcca 100644
--- a/package/ego-browser/src/element-resolver.ts
+++ b/package/ego-browser/src/element-resolver.ts
@@ -1236,22 +1236,36 @@ async function roleMatchActionability(
{
functionDeclaration: `function() {
${actionabilityRequiresPointer(actionability) ? HIT_TARGET_HELPERS : ACTION_TARGET_STATE_HELPERS}
- if (!this.isConnected) return { actionable: false };
- const rect = this.getBoundingClientRect();
+ if (!this.isConnected) {
+ return { actionable: false, blocker: "element is detached from the DOM" };
+ }
+ if (this.closest?.("[hidden], [inert]")) {
+ return { actionable: false, blocker: "element is hidden or inert" };
+ }
const view = this.ownerDocument?.defaultView;
- if (!view || rect.width <= 0 || rect.height <= 0) return { actionable: false };
+ if (!view) {
+ return { actionable: false, blocker: "element has no browsing context" };
+ }
+ const rect = this.getBoundingClientRect();
+ if (rect.width <= 0 || rect.height <= 0) {
+ return { actionable: false, blocker: "element has a zero-sized bounding box" };
+ }
const style = view.getComputedStyle(this);
- const visible = !this.closest?.("[hidden], [inert]") &&
- style.display !== "none" &&
- style.visibility !== "hidden";
- if (!visible) return { actionable: false };
+ if (style.display === "none") {
+ return { actionable: false, blocker: "element has display: none" };
+ }
+ if (style.visibility === "hidden") {
+ return { actionable: false, blocker: "element has visibility: hidden" };
+ }
if (
${JSON.stringify(actionabilityRequiresEnabled(actionability))} &&
isActionTargetDisabled(this)
) return { actionable: false, blocker: "element is disabled" };
if (${JSON.stringify(actionabilityRequiresPointer(actionability))}) {
const point = actionPointForElement(this);
- if (!point) return { actionable: false };
+ if (!point) {
+ return { actionable: false, blocker: "element has no actionable point" };
+ }
if (!scrollRequestForPoint(this, point)) {
const interceptor = interceptingElementAtPoint(this, point);
if (interceptor) {
@@ -1621,19 +1635,24 @@ async function firstActionabilityBlocker(
`(() => {
${actionabilityRequiresPointer(actionability) ? HIT_TARGET_HELPERS : ACTION_TARGET_STATE_HELPERS}
for (const element of Array.from(${elementsExpression} || [])) {
- if (!element?.isConnected || element.closest?.("[hidden], [inert]")) continue;
+ if (!element?.isConnected) return "element is detached from the DOM";
+ if (element.closest?.("[hidden], [inert]")) return "element is hidden or inert";
const view = element.ownerDocument?.defaultView;
+ if (!view) return "element has no browsing context";
const rect = element.getBoundingClientRect();
- const style = view?.getComputedStyle(element);
- if (!view || rect.width <= 0 || rect.height <= 0 ||
- style.display === "none" || style.visibility === "hidden") continue;
+ if (rect.width <= 0 || rect.height <= 0) {
+ return "element has a zero-sized bounding box";
+ }
+ const style = view.getComputedStyle(element);
+ if (style.display === "none") return "element has display: none";
+ if (style.visibility === "hidden") return "element has visibility: hidden";
if (
${JSON.stringify(actionabilityRequiresEnabled(actionability))} &&
isActionTargetDisabled(element)
) return "element is disabled";
if (!${JSON.stringify(actionabilityRequiresPointer(actionability))}) continue;
const point = actionPointForElement(element);
- if (!point) continue;
+ if (!point) return "element has no actionable point";
if (scrollRequestForPoint(element, point)) continue;
const interceptor = interceptingElementAtPoint(element, point);
if (interceptor) {