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.

Format helpers.ts with Prettier

0x0dde63ed25729
diff --git a/package/ego-browser/src/helpers.ts b/package/ego-browser/src/helpers.ts
index 2103c31..5146731 100644
--- a/package/ego-browser/src/helpers.ts
+++ b/package/ego-browser/src/helpers.ts
@@ -18,13 +18,26 @@ import {
loadLearnedContext,
runNodeSiteTool,
siteSkillsForUrl as siteSkillsForUrlCore,
- wrapBrowserTool
+ wrapBrowserTool,
} from "./learning/index.js";
export { NAME } from "./state.js";
export { cdp, js } from "./cdp-eval.js";
-export { click, doubleClick, hover, dragMouse, scroll, scrollBy, scrollToBottomUntil } from "./driver/pointer.js";
-export { pressKey, typeText, fillInput, dispatchKey } from "./driver/keyboard.js";
+export {
+ click,
+ doubleClick,
+ hover,
+ dragMouse,
+ scroll,
+ scrollBy,
+ scrollToBottomUntil,
+} from "./driver/pointer.js";
+export {
+ pressKey,
+ typeText,
+ fillInput,
+ dispatchKey,
+} from "./driver/keyboard.js";
export {
INTERNAL_URL_PREFIXES,
pageInfo,
@@ -36,10 +49,22 @@ export {
gotoUrl,
gotoAndWait,
ensureRealTab,
- iframeTarget
+ iframeTarget,
} from "./driver/nav.js";
-export { snapshot, snapshotRaw, snapshotText, captureScreenshot, elementCenter, drainEvents } from "./driver/observe.js";
-export { wait, waitForLoad, waitForElement, waitForNetworkIdle } from "./driver/waits.js";
+export {
+ snapshot,
+ snapshotRaw,
+ snapshotText,
+ captureScreenshot,
+ elementCenter,
+ drainEvents,
+} from "./driver/observe.js";
+export {
+ wait,
+ waitForLoad,
+ waitForElement,
+ waitForNetworkIdle,
+} from "./driver/waits.js";
export { uploadFile } from "./driver/files.js";
export { browserFetch, serverFetch } from "./http.js";
@@ -52,7 +77,9 @@ export async function listTaskSpaces() {
if (!ego || typeof ego.listTaskSpaces !== "function") {
throw new Error("listTaskSpaces requires ego.listTaskSpaces");
}
- return normalizeTaskSpaces(assertNoEgoError(await ego.listTaskSpaces(), "listTaskSpaces"));
+ return normalizeTaskSpaces(
+ assertNoEgoError(await ego.listTaskSpaces(), "listTaskSpaces"),
+ );
}
/*
@@ -97,7 +124,9 @@ export async function switchTaskSpace(nameOrId) {
}
const space = await findTaskSpace(nameOrId);
if (!isAgentOwned(space.ownership)) {
- throw new Error(`switchTaskSpace requires an agent-owned task space, got ownership ${JSON.stringify(space.ownership)}`);
+ throw new Error(
+ `switchTaskSpace requires an agent-owned task space, got ownership ${JSON.stringify(space.ownership)}`,
+ );
}
return selectTaskSpace(ego, space, "switchTaskSpace");
}
@@ -112,7 +141,9 @@ export async function newTaskSpace(name) {
if (!ego || typeof ego.createTaskSpace !== "function") {
throw new Error("newTaskSpace requires ego.createTaskSpace");
}
- const created = normalizeTaskSpace(assertNoEgoError(await ego.createTaskSpace(name), "newTaskSpace"));
+ const created = normalizeTaskSpace(
+ assertNoEgoError(await ego.createTaskSpace(name), "newTaskSpace"),
+ );
if (!created) {
throw new Error("newTaskSpace returned an invalid task space");
}
@@ -140,7 +171,9 @@ export async function useOrCreateTaskSpace(nameOrId) {
if (existing.ownership === "user") {
return claimTaskSpace(existing, "useOrCreateTaskSpace");
}
- throw new Error(`useOrCreateTaskSpace cannot use task space ${JSON.stringify(nameOrId)} with ownership ${JSON.stringify(existing.ownership)}`);
+ throw new Error(
+ `useOrCreateTaskSpace cannot use task space ${JSON.stringify(nameOrId)} with ownership ${JSON.stringify(existing.ownership)}`,
+ );
}
async function claimTaskSpace(space, op = "claimTaskSpace") {
@@ -149,7 +182,9 @@ async function claimTaskSpace(space, op = "claimTaskSpace") {
throw new Error(`${op} requires ego.claimTaskSpace`);
}
const id = taskSpaceNumericId(space, op);
- const claimed = normalizeTaskSpace(assertNoEgoError(await ego.claimTaskSpace(id, space.name), op));
+ const claimed = normalizeTaskSpace(
+ assertNoEgoError(await ego.claimTaskSpace(id, space.name), op),
+ );
if (!claimed) {
throw new Error(`${op} returned an invalid task space`);
}
@@ -165,7 +200,11 @@ async function selectTaskSpace(ego, space, op: string) {
return space;
}
-async function selectTaskSpaceIfProvided(ego, nameOrId?: string | number, op = "taskSpace") {
+async function selectTaskSpaceIfProvided(
+ ego,
+ nameOrId?: string | number,
+ op = "taskSpace",
+) {
if (nameOrId === undefined) return;
const match = await findTaskSpace(nameOrId);
await selectTaskSpace(ego, match, op);
@@ -182,8 +221,14 @@ async function selectTaskSpaceIfProvided(ego, nameOrId?: string | number, op = "
* @param {{ keep: boolean }} options Required. `keep:true` hands the page to the user; `keep:false` closes the space.
* @returns {Promise<{done: boolean, skipped?: "user-owned"}>} `{ done: true }` when the space was completed or closed; `{ done: false, skipped: "user-owned" }` when nothing was done.
*/
-export async function completeTaskSpace(nameOrId: string | number, options: { keep: boolean }) {
- if ((typeof nameOrId !== "string" && typeof nameOrId !== "number") || nameOrId === "") {
+export async function completeTaskSpace(
+ nameOrId: string | number,
+ options: { keep: boolean },
+) {
+ if (
+ (typeof nameOrId !== "string" && typeof nameOrId !== "number") ||
+ nameOrId === ""
+ ) {
throw new Error("completeTaskSpace requires a task space name or id");
}
if (!options || typeof options.keep !== "boolean") {
@@ -291,8 +336,14 @@ async function probeAgentControl() {
* @param {{ interval?: number, timeout?: number }} [options] interval & timeout in seconds (default 20s / 600s).
* @returns {Promise<void>}
*/
-export async function waitForAgentControl(nameOrId: string | number, options: { interval?: number; timeout?: number } = {}) {
- if ((typeof nameOrId !== "string" && typeof nameOrId !== "number") || nameOrId === "") {
+export async function waitForAgentControl(
+ nameOrId: string | number,
+ options: { interval?: number; timeout?: number } = {},
+) {
+ if (
+ (typeof nameOrId !== "string" && typeof nameOrId !== "number") ||
+ nameOrId === ""
+ ) {
throw new Error("waitForAgentControl requires a task space name or id");
}
const ego = globalThis.ego;
@@ -328,13 +379,15 @@ function normalizeTaskSpace(space) {
...space,
taskId,
id: space?.id ?? taskId,
- name: space?.name ?? taskId
+ name: space?.name ?? taskId,
};
}
function taskSpaceNumericId(space, op: string) {
if (typeof space?.id !== "number" || !Number.isFinite(space.id)) {
- throw new Error(`${op} requires a numeric task space id, got ${JSON.stringify(space?.id)}`);
+ throw new Error(
+ `${op} requires a numeric task space id, got ${JSON.stringify(space?.id)}`,
+ );
}
return space.id;
}
@@ -350,7 +403,9 @@ function findMatchingTaskSpace(spaces, nameOrId) {
if (typeof nameOrId === "number") {
return spaces.find((space) => space.id === nameOrId);
}
- const byName = spaces.find((space) => space.name === nameOrId || space.taskId === nameOrId);
+ const byName = spaces.find(
+ (space) => space.name === nameOrId || space.taskId === nameOrId,
+ );
if (byName) return byName;
if (/^\d+$/.test(nameOrId)) {
const id = Number(nameOrId);
@@ -363,7 +418,7 @@ function findMatchingTaskSpace(spaces, nameOrId) {
export async function siteSkillsForUrl(url) {
return siteSkillsForUrlCore(url, {
- agentWorkspace: state.agentWorkspace()
+ agentWorkspace: state.agentWorkspace(),
});
}
@@ -386,7 +441,7 @@ export async function siteSkills(url = undefined) {
*/
export async function runSiteTool(siteId, toolName, args: any = {}) {
return runNodeSiteTool(siteId, toolName, args, helperContext(), {
- agentWorkspace: state.agentWorkspace()
+ agentWorkspace: state.agentWorkspace(),
});
}
@@ -399,7 +454,7 @@ export async function runSiteTool(siteId, toolName, args: any = {}) {
*/
export async function runSiteBrowserTool(siteId, toolName, args: any = {}) {
const source = await loadBrowserToolSource(siteId, toolName, {
- agentWorkspace: state.agentWorkspace()
+ agentWorkspace: state.agentWorkspace(),
});
return js(wrapBrowserTool(source, args));
}
@@ -413,7 +468,7 @@ export async function runSiteBrowserTool(siteId, toolName, args: any = {}) {
export async function learnContext(url = undefined) {
const targetUrl = url ?? (await nav.pageInfo()).url ?? "";
return loadLearnedContext(targetUrl, {
- agentWorkspace: state.agentWorkspace()
+ agentWorkspace: state.agentWorkspace(),
});
}
@@ -443,7 +498,7 @@ export function helperContext(extra: any = {}) {
handOffTaskSpace,
takeOverTaskSpace,
waitForAgentControl,
- ...extra
+ ...extra,
};
return {
...all,
@@ -452,7 +507,7 @@ export function helperContext(extra: any = {}) {
if (typeof result === "string") return result;
if (Array.isArray(result)) return result.map(formatHelp).join("\n\n");
return formatHelp(result);
- }
+ },
};
}