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(ego-browser): hand a v1 click fast-path miss to the shared resolver
Zhuowei Wangafbb36d93028
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjsindex baaa8e9..66bf98e 100644--- a/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs+++ b/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs@@ -221,6 +221,25 @@ export function pointerCase() {"window.__fixtureState.pointerEvents");+ /* raw selector inside the fixture iframe: the v1 helper resolves raw+ selectors in the top document only (no iframe session search), so the+ combined resolve-and-probe fast path must hand a miss to the shared+ resolver, which reports it with the same wording as before, and the+ next top-document click must still work. */+ cliLog(JSON.stringify({ pointerStep: "selector inside iframe" }));+ await assertRejects(+ () => click("#iframe-action"),+ "Element not found: #iframe-action",+ "a raw selector that only matches inside the iframe is reported by the shared resolver"+ );+ const afterMissBefore = await js("return window.__fixtureState.clicks");+ await click("#click-button");+ await waitForJsValue(+ "window.__fixtureState.clicks",+ afterMissBefore + 1,+ "a top-document click still works after the fast path missed"+ );+/* checkbox toggle */cliLog(JSON.stringify({ pointerStep: "checkbox" }));await js("document.querySelector('#checkbox').checked = false; window.__fixtureState.checkboxChecked = false; return true;");diff --git a/package/ego-browser/src/driver/pointer.test.mjs b/package/ego-browser/src/driver/pointer.test.mjsindex 9915c2a..8546b83 100644--- a/package/ego-browser/src/driver/pointer.test.mjs+++ b/package/ego-browser/src/driver/pointer.test.mjs@@ -339,9 +339,67 @@ test("click rethrows a dispatch timeout when the probe has no element to fall ba}});-test("click reports a missing CSS selector as a transient resolution error", async () => {+test("click falls back to the shared resolver when the fast path finds no element", async () => {+ // The combined resolve-and-probe evaluate searches the default session only.+ // A miss there must not be reported as "not found": the shared resolver+ // decides, and when it resolves the element the probe is installed in a+ // call of its own before any input.+ const calls = [];+ let evaluations = 0;const restore = setOverrides({- cdpOverride(method) {+ cdpOverride(method, params) {+ calls.push({ method, params });+ if (method === "Runtime.evaluate") {+ evaluations += 1;+ if (evaluations === 1) return { result: { value: null } };+ if (params.expression.includes("__egoBrowserInputProbes")) {+ return { result: { value: true } };+ }+ return { result: { value: { x: 70, y: 80 } } };+ }+ return {};+ },+ });+ try {+ await withFakeEgo(() => click("#inside-frame"));+ } finally {+ restore();+ }++ assert.deepEqual(methodSequence(calls), [+ "Runtime.evaluate",+ "Runtime.evaluate",+ "Runtime.evaluate",+ "Input.dispatchMouseEvent:mouseMoved",+ "Input.dispatchMouseEvent:mousePressed",+ "Input.dispatchMouseEvent:mouseReleased",+ ]);+ assert(+ isProbeExpression(calls[0]),+ "the fast path tried to resolve and probe at once",+ );+ assert.equal(+ isProbeExpression(calls[1]),+ false,+ "the shared resolver evaluates the selector without a probe",+ );+ assert(isProbeExpression(calls[2]), "the probe is installed before input");+ assert.match(calls[2].params.expression, /\{"x":70,"y":80\}/);+ assert.deepEqual(+ calls.slice(3).map((call) => [call.params.x, call.params.y]),+ [+ [70, 80],+ [70, 80],+ [70, 80],+ ],+ );+});++test("click reports a selector missing from every session with the resolver's wording", async () => {+ const calls = [];+ const restore = setOverrides({+ cdpOverride(method, params) {+ calls.push({ method, params });if (method === "Runtime.evaluate") return { result: { value: null } };return {};},@@ -359,4 +417,9 @@ test("click reports a missing CSS selector as a transient resolution error", asy} finally {restore();}+ assert.deepEqual(+ methodSequence(calls),+ ["Runtime.evaluate", "Runtime.evaluate"],+ "the fast path misses, the shared resolver reports",+ );});diff --git a/package/ego-browser/src/driver/pointer.ts b/package/ego-browser/src/driver/pointer.tsindex 48e6918..dac0d3f 100644--- a/package/ego-browser/src/driver/pointer.ts+++ b/package/ego-browser/src/driver/pointer.ts@@ -1,10 +1,6 @@import { cdp, js } from "../cdp-eval.js";import { browserCdp } from "../browser-runtime.js";-import {- ElementResolutionError,- buildSelectorCenterJs,- isRawSelector,-} from "../element-resolver.js";+import { buildSelectorCenterJs, isRawSelector } from "../element-resolver.js";import { elementCenter } from "./observe.js";import { resolveAndCall } from "./element-ops.js";@@ -242,10 +238,11 @@ function inputEventDelay(ms = INPUT_EVENT_DELAY_MS) {/*** Resolve the click point and install the trusted-click probe before any- * input is dispatched. A plain CSS selector does both in the one- * `Runtime.evaluate` that already resolves it; refs, locators, offsets, and- * coordinates resolve first and install the probe in a call of their own- * rather than risk a replayed click. Without native bindings there is no+ * input is dispatched. A plain CSS selector found in the default session does+ * both in the one `Runtime.evaluate` that resolves it; refs, locators,+ * offsets, coordinates, and a selector the fast path did not find resolve+ * through the shared resolver first and install the probe in a call of their+ * own rather than risk a replayed click. Without native bindings there is no* fallback, so no probe is installed.*/async function resolveClickTarget(target: MouseTarget): Promise<ClickTarget> {@@ -273,16 +270,13 @@ async function resolveRawSelectorClickTarget(returnByValue: true,awaitPromise: false,});- // An invalid selector or an unexpected value is reported by the shared- // resolver, which evaluates the same selector again.+ // No match in the default session, an invalid selector, or an unexpected+ // value: hand the selector to the shared resolver, which searches the+ // sessions it knows about and reports a missing element with its own+ // wording. The probe was not installed in that case, so the generic path+ // installs one after resolving.if (result.exceptionDetails) return null;const value = result.result?.value;- if (value === null) {- throw new ElementResolutionError(- `Element not found: ${selector}`,- "transient",- );- }if (typeof value?.x !== "number" || typeof value?.y !== "number") {return null;}