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.

feat(ego-browser): own static wording only for the two business codes

0x0cdd6dc219d6f
diff --git a/package/ego-browser/src/browser-runtime.test.mjs b/package/ego-browser/src/browser-runtime.test.mjs
index cf9fa72..1981590 100644
--- a/package/ego-browser/src/browser-runtime.test.mjs
+++ b/package/ego-browser/src/browser-runtime.test.mjs
@@ -11,8 +11,8 @@ test("browserCdp surfaces the owned message and error_code when ensureSession is
globalThis.ego = {
async listTabs() {
return {
- error: "The task is under user control: 7",
- error_code: "EGO_TASK_SPACE_USER_IN_CONTROL",
+ error: "Task space 10 is not assigned to an agent.",
+ error_code: "EGO_TASK_SPACE_INACTIVE",
};
},
};
@@ -20,8 +20,11 @@ test("browserCdp surfaces the owned message and error_code when ensureSession is
await assert.rejects(
() => browserCdp("Runtime.evaluate", {}, undefined, 1000),
(err) => {
- assert.equal(err.error_code, "EGO_TASK_SPACE_USER_IN_CONTROL");
- assert.equal(err.message, "The task is under user control.");
+ assert.equal(err.error_code, "EGO_TASK_SPACE_INACTIVE");
+ assert.equal(
+ err.message,
+ "Task space is not assigned to an agent. Claim this task space before sending CDP messages.",
+ );
return true;
},
);
@@ -41,7 +44,7 @@ test("browserCdp rejects the in-flight request via onSendCDPMessageError", async
queueMicrotask(() =>
globalThis.ego.onSendCDPMessageError(
"native reconstructed text",
- "EGO_TASK_SPACE_USER_IN_CONTROL",
+ "EGO_TASK_SPACE_INACTIVE",
),
);
},
@@ -51,8 +54,11 @@ test("browserCdp rejects the in-flight request via onSendCDPMessageError", async
// Browser-level method skips ensureSession; short timeout bounds a regression.
() => browserCdp("Browser.getVersion", {}, undefined, 1000),
(err) => {
- assert.equal(err.error_code, "EGO_TASK_SPACE_USER_IN_CONTROL");
- assert.equal(err.message, "The task is under user control.");
+ assert.equal(err.error_code, "EGO_TASK_SPACE_INACTIVE");
+ assert.equal(
+ err.message,
+ "Task space is not assigned to an agent. Claim this task space before sending CDP messages.",
+ );
return true;
},
);
diff --git a/package/ego-browser/src/ego-errors.test.mjs b/package/ego-browser/src/ego-errors.test.mjs
index e9e8bbb..1a6bf1e 100644
--- a/package/ego-browser/src/ego-errors.test.mjs
+++ b/package/ego-browser/src/ego-errors.test.mjs
@@ -41,14 +41,15 @@ test("isEgoErrorCode narrows to known codes only", () => {
assert.equal(isEgoErrorCode(undefined), false);
});
-test("resolveEgoError overrides live text with the owned wording for a known code", () => {
+test("resolveEgoError overrides live text with the owned wording for an owned code", () => {
const resolved = resolveEgoError({
- error: "Task space not found: 7",
- error_code: "EGO_TASK_SPACE_NOT_FOUND",
+ error: "Task space 7 is not assigned to an agent.",
+ error_code: "EGO_TASK_SPACE_INACTIVE",
});
assert.deepEqual(resolved, {
- code: "EGO_TASK_SPACE_NOT_FOUND",
- message: "Task space not found.",
+ code: "EGO_TASK_SPACE_INACTIVE",
+ message:
+ "Task space is not assigned to an agent. Claim this task space before sending CDP messages.",
});
});
@@ -65,13 +66,37 @@ test("resolveEgoError keeps live text for an unknown future code", () => {
);
});
-test("resolveEgoError falls back to the ego-browser message for a bare code", () => {
- assert.deepEqual(resolveEgoError("EGO_TASK_SPACE_USER_IN_CONTROL"), {
- code: "EGO_TASK_SPACE_USER_IN_CONTROL",
- message: "The task is under user control.",
+test("resolveEgoError defers to live text for a code ego-browser does not own", () => {
+ // EGO_OPERATION_FAILED is not owned: the client wording (e.g. which operation
+ // failed) is more specific than any static line.
+ assert.deepEqual(
+ resolveEgoError({
+ error: "Failed to create task space",
+ error_code: "EGO_OPERATION_FAILED",
+ }),
+ {
+ code: "EGO_OPERATION_FAILED",
+ message: "Failed to create task space",
+ },
+ );
+});
+
+test("resolveEgoError falls back to the raw code for a bare non-owned code", () => {
+ // ego-browser does not own NOT_SELECTED and a bare code carries no live text,
+ // so the stable code itself is the most specific thing to surface.
+ assert.deepEqual(resolveEgoError("EGO_TASK_SPACE_NOT_SELECTED"), {
+ code: "EGO_TASK_SPACE_NOT_SELECTED",
+ message: "EGO_TASK_SPACE_NOT_SELECTED",
});
});
+test("resolveEgoError uses the id-less guidance block for a bare user-control code", () => {
+ const { code, message } = resolveEgoError("EGO_TASK_SPACE_USER_IN_CONTROL");
+ assert.equal(code, "EGO_TASK_SPACE_USER_IN_CONTROL");
+ assert.match(message, /controlling this task space/);
+ assert.doesNotMatch(message, /<id>/);
+});
+
test("resolveEgoError falls back to the raw code, then a generic message", () => {
assert.deepEqual(resolveEgoError({ error_code: "EGO_FUTURE_CODE" }), {
code: "EGO_FUTURE_CODE",
@@ -107,15 +132,15 @@ test("assertNoEgoError resolves the message via the code and attaches error_code
try {
assertNoEgoError(
{
- error: "The task is under user control",
- error_code: "EGO_TASK_SPACE_USER_IN_CONTROL",
+ error: "Task space not selected",
+ error_code: "EGO_TASK_SPACE_NOT_SELECTED",
},
"listTabs",
);
assert.fail("expected assertNoEgoError to throw");
} catch (err) {
- assert.equal(err.message, "listTabs: The task is under user control.");
- assert.equal(err.error_code, "EGO_TASK_SPACE_USER_IN_CONTROL");
+ assert.equal(err.message, "listTabs: Task space not selected");
+ assert.equal(err.error_code, "EGO_TASK_SPACE_NOT_SELECTED");
}
});
@@ -127,7 +152,10 @@ test("assertNoEgoError omits the prefix when no op is given", () => {
});
assert.fail("expected assertNoEgoError to throw");
} catch (err) {
- assert.equal(err.message, "The task space is inactive.");
+ assert.equal(
+ err.message,
+ "Task space is not assigned to an agent. Claim this task space before sending CDP messages.",
+ );
assert.equal(err.error_code, "EGO_TASK_SPACE_INACTIVE");
}
});
diff --git a/package/ego-browser/src/ego-errors.ts b/package/ego-browser/src/ego-errors.ts
index a3f872f..cb68916 100644
--- a/package/ego-browser/src/ego-errors.ts
+++ b/package/ego-browser/src/ego-errors.ts
@@ -8,9 +8,8 @@
*
* The code is the durable contract; the wording can drift between builds. Branch
* on the code (isEgoUserControlError), not on the message. EGO_ERROR_MESSAGES is
- * where ego-browser owns its own wording per code: for any code this build knows,
- * its wording is authoritative and overrides the browser's live text. Unknown
- * (future) codes fall back to the live text.
+ * where ego-browser owns its wording for the few codes an agent must act on; every
+ * other code (and any unknown future code) defers to the browser's live text.
*
* Single source of truth — error handling was previously duplicated across
* helpers.ts and driver/nav.ts.
@@ -38,26 +37,23 @@ export const EGO_ERROR_CODES = [
export type EgoErrorCode = (typeof EGO_ERROR_CODES)[number];
/**
- * ego-browser-owned message for each stable code. For codes this build knows,
- * this wording is authoritative and overrides the browser's live text; customize
- * wording here. Keep it free of dynamic values (no ids).
+ * Codes whose wording ego-browser owns. A listed code returns this static, id-less
+ * message instead of the browser's live text — reserved for the two business signals
+ * an agent must react to, not just report. Every other code is absent here and
+ * defers to the live message (and any unknown future code does too), which is more
+ * specific than any static line.
*/
-const EGO_ERROR_MESSAGES: Record<EgoErrorCode, string> = {
- EGO_BROWSER_UNAVAILABLE: "No active browser.",
- EGO_CDP_CHANNEL_UNAVAILABLE: "The CDP channel is not connected.",
- EGO_CDP_SEND_FAILED: "Failed to send the CDP message.",
- EGO_INVALID_ARGUMENT: "Invalid argument.",
- EGO_INVALID_RESULT_PAYLOAD: "The browser returned an invalid result payload.",
- EGO_OPERATION_FAILED: "The browser operation failed.",
- EGO_RESULT_CONVERSION_FAILED: "Failed to convert the browser result.",
- EGO_SNAPSHOT_FAILED: "Failed to capture the page snapshot.",
- EGO_TASK_HOST_DISCONNECTED: "The task host is no longer available.",
- EGO_TASK_SPACE_INACTIVE: "The task space is inactive.",
- EGO_TASK_SPACE_NOT_FOUND: "Task space not found.",
- EGO_TASK_SPACE_NOT_SELECTED: "Task space not selected.",
- EGO_TASK_SPACE_UNAVAILABLE: "The task space is unavailable.",
- EGO_TASK_SPACE_USER_IN_CONTROL: "The task is under user control.",
- EGO_WEB_CONTENTS_UNAVAILABLE: "The page contents are unavailable.",
+const EGO_ERROR_MESSAGES: Partial<Record<EgoErrorCode, string>> = {
+ EGO_TASK_SPACE_INACTIVE:
+ "Task space is not assigned to an agent. Claim this task space before sending CDP messages.",
+ EGO_TASK_SPACE_USER_IN_CONTROL: [
+ "The user is controlling this task space. Browser commands are paused.",
+ "Do not take over automatically. Wait for the user to return control or ask you to continue.",
+ "To resume after user confirmation, call:",
+ " await takeOverTaskSpace()",
+ "",
+ `If supported, offer choices like "Continue" or "Finish task"; otherwise tell the user: "You are now controlling this task space. Reply 'continue' when ready, and I will resume."`,
+ ].join("\n"),
};
/** Type guard for codes this build knows about. */
@@ -88,10 +84,10 @@ export function egoErrorCode(err: unknown): string | undefined {
/**
* Resolve any ego error into a stable `{ code, message }` pair.
*
- * For a code this build knows, `message` is the ego-browser-owned wording for
- * that code. Otherwise it falls back to the live human-readable text the browser
- * supplied, then the bare code, then a generic string. `code` is the stable
- * classifier and may be undefined.
+ * For a code ego-browser owns wording for, `message` is that owned wording.
+ * Otherwise (a code not owned here, or an unknown future code) it falls back to
+ * the live human-readable text the browser supplied, then the bare code, then a
+ * generic string. `code` is the stable classifier and may be undefined.
*/
export function resolveEgoError(err: unknown): {
code?: string;