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): route snapshot hard stops through buildEgoError
0x0da7b694ec3a7
diff --git a/package/ego-browser/src/driver/observe.ts b/package/ego-browser/src/driver/observe.tsindex dfb4dbf..a46daa9 100644--- a/package/ego-browser/src/driver/observe.ts+++ b/package/ego-browser/src/driver/observe.ts@@ -12,6 +12,7 @@ import {isBrowserRuntime,pendingDialog,} from "../browser-runtime.js";+import { buildEgoError } from "../ego-errors.js";import { resolveElementCenter } from "../element-resolver.js";import {browserRefMap,@@ -45,7 +46,17 @@ export async function drainEvents() {}export async function snapshot(options: SnapshotOptions = {}) {- const result = await browserEgo().snapshot(options);+ let result;+ try {+ result = await browserEgo().snapshot(options);+ } catch (err) {+ // ego.snapshot rejects directly (it never resolves with { error }), so it never+ // reached buildEgoError — the single birthplace that records a hard stop for the+ // output sink and swaps native wording for ego-browser's owned guidance. Route the+ // rejection through it so a swallowed snapshot hard stop collapses like every other+ // ego error instead of leaking repeated native text.+ throw buildEgoError(err, "snapshot");+ }browserSnapshotRefsToRefMap(browserRefMap, result.refs || []);return result;}diff --git a/package/ego-browser/src/run-output-sink.test.mjs b/package/ego-browser/src/run-output-sink.test.mjsindex 2d29eeb..5b6170a 100644--- a/package/ego-browser/src/run-output-sink.test.mjs+++ b/package/ego-browser/src/run-output-sink.test.mjs@@ -20,6 +20,22 @@ function hardStopEgo(error_code) {};}+// A native ego whose `snapshot` REJECTS with a hard-stop code — the shape the real+// bindings use under user control (helpers.ts probeAgentControl relies on it). driver/+// observe.ts calls browserEgo().snapshot() directly, so the rejection only reaches the+// sink if snapshot() routes it through buildEgoError.+function snapshotHardStopEgo(error_code) {+ return {+ calls: 0,+ async snapshot() {+ this.calls += 1;+ const err = new Error("native wording that should never reach the agent");+ err.error_code = error_code;+ throw err;+ },+ };+}+function captureStream() {const chunks = [];return {@@ -117,6 +133,36 @@ test("an inactive / unassigned task space is also a hard stop", async () => {assert.doesNotMatch(result.stdout, /swallowed|business/);});+test("a swallowed snapshot hard stop (rejected, not resolved) also collapses to one message", async () => {+ // snapshot rejects directly instead of resolving with { error }, so it bypasses+ // assertNoEgoError; the collapse only works if snapshot() rebuilds it via buildEgoError.+ const ego = snapshotHardStopEgo("EGO_TASK_SPACE_USER_IN_CONTROL");+ const result = await runScript(+ `+ for (const site of ["a", "b", "c"]) {+ cliLog("visiting " + site);+ try {+ await snapshotText();+ cliLog("ok " + site);+ } catch (e) {+ cliLog("failed " + site + ": " + e.message);+ }+ }+ cliLog("summary: done");+ `,+ ego,+ );++ assert.equal(result.exitCode, 0);+ // The owned guidance survives once; the native wording and business logs are dropped.+ assert.match(result.stdout, /taken control of this task space/);+ assert.match(result.stdout, /takeOverTaskSpace\(\)/);+ assert.doesNotMatch(result.stdout, /native wording/);+ assert.doesNotMatch(result.stdout, /visiting|failed|ok |summary/);+ assert.equal(result.stdout.match(/takeOverTaskSpace\(\)/g).length, 1);+ assert.ok(ego.calls >= 3, "every iteration should have hit the snapshot hard stop");+});+test("an uncaught hard stop discards output without double-printing the message", async () => {const ego = hardStopEgo("EGO_TASK_SPACE_USER_IN_CONTROL");const result = await runScript(