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.
Repository Guidelines
Project Overview
ego-browser is a Node.js CDP browser-automation harness for AI agents. It drives the ego lite browser through globalThis.ego bindings (provided by the closed-source ego lite app), exposes a compact snapshot/ref workflow, and layers reusable site-specific knowledge ("learnings") on top of the browser runtime.
This repo contains the open-source harness and the agent skill package — not the browser itself. The ego lite app bundles its own ego-browser binary that embeds this runtime. The Skill has two layers: skills/ego-browser/ is a thin entry Skill that tells agents to run ego-browser skill, and package/ego-browser/skill-body/SKILL.md is the versioned usage guide that command prints (ego-browser nodejs <<'EOF' ... EOF). The repo CLI built here takes the heredoc directly on stdin with no subcommand.
Architecture & Data Flow
package/ego-browser/src/index.tsis the entrypoint with two startup paths:- Executed directly as a CLI →
runMain()(reads JavaScript from stdin, executes it). - Imported as a module (how the app embeds it) →
installEgoSdk(globalThis).
- Executed directly as a CLI →
- Both paths expose the same helper surface.
public-api-schema.tsis the source of truth for the v2 API shown byhelp();helpers.tscombines it with the frozen v1 compatibility surface. src/run.tsexecutes stdin JavaScript inside an async function with the helpers injected as parameters.src/browser-runtime.tsowns CDP transport overego.sendCDPMessage, session attach/caching (2s TTL, auto re-attach on session loss), the buffered event queue (10k cap), and JS dialog tracking.src/cdp-eval.tsprovidescdp()andjs()(string-expression evaluation; top-levelreturnis auto-wrapped in an IIFE).src/element-resolver.tsresolves all target forms —@Nrefs,loc=css:/loc=role:/loc=href:locators,xpath=, raw CSS — and classifies failures astransient(retryable) orpermanent.src/page-ref-registry.ts+src/page-ledger.ts: v2 Page refs (@21, not@e21) are SDK-assigned ids bound to one frame/document/backend node. Their mappings and invalidation persist across rounds; partial snapshots merge by node identity and full snapshots replace the active set. Missing refs require a fresh snapshot.src/ref-map.ts+src/ref-state.tsretain the v1 native-ref refresh behavior.src/driver/—nav(tabs, navigation),pointer(click/scroll/drag),keyboard,observe(snapshot/screenshot),waits,files(upload),element-ops(objectId handles),load.src/learning/— discovery, validation, and execution of site skills fromskills/ego-browser/learnings/<site>/manifest.json(runSiteTool,runSiteBrowserTool,learnContext).src/state.tsis the shared mutable runtime state singleton;src/env.tsresolves the agent workspace (EGO_BROWSER_AGENT_WORKSPACE, falling back to the entry Skill bundled next to the build output, then the repo'sskills/ego-browser).src/help-runtime.tsparses the built bundle's JSDoc with acorn at runtime to powerhelp()— JSDoc on exported helpers is therefore user-facing documentation.
Data flow: stdin JS → runMain() → helperContext() helpers → browser runtime/CDP → snapshot or DOM/AX resolution → optional site tools → cliLog(...).
Task Spaces
Task spaces are isolated browsing contexts with an ownership model (agent / user):
- New scripts use
taskSpace(nameOrId)and operate through the returnedTaskSpaceand labeledPageobjects. task.pages()returns managed Page handles;task.tabs()returns the full managed and unmanaged tab inventory.- Control handoff uses
task.handOff()andtakeOverTaskSpace(spaceId). - The old global helpers remain available only for v1 script compatibility.
Key Directories
package/ego-browser/src/— runtime, helpers, resolver, drivers, learning subsystem.package/ego-browser/src/**/*.test.mjs— tests are colocated with the code (there is no separatetest/directory).package/ego-browser/scripts/—build.mjs(esbuild per-file →dist/src, rollup bundle →dist/out/index.js, rendersskill-body/SKILL.mdviarender-guide.mjs→dist/out/ego-browser/SKILL.mdplusSKILL.macos.md/SKILL.windows.md, selecting<!-- platform: ... -->blocks and adding version and end markers, copies the entry Skill and its learnings →dist/out/agent-skills/ego-browser),validate-site-skills.ts, and the real-browser E2E runner.package/ego-browser/skill-body/SKILL.md— canonical agent-facing usage guide, printed byego-browser skill.skills/ego-browser/— thin entry Skill published to skill markets and plugins:SKILL.md,references/install.md(plusinstall-macos.md/install-windows.md),references/clearing-state.md,scripts/install.sh, and the sitelearnings/. Seedocs/ego-browser-skill-command.mdfor the browser-side contract.plugins/ego/skills/ego-browser/is a copy of it for hosts that install the plugin from Git: edit onlyskills/ego-browser/, and the commit hook syncs and stages the copy (without the hook, runnpm --prefix plugins/ego run sync-skills).skills/ego-browser/learnings/— reusable per-site experience packs (manifest.json+notes/+tools/+browser-tools/).
Development Commands
Run from package/ego-browser/:
npm test— build, typecheck, thennode --testoversrc/**/*.test.mjs.npm run e2e— self-contained real-browser E2E suite using the current checkout through--sdk-path.npm run validate:site-skills— validate learned site skills.node dist/out/index.js <<'JS' ... JS— run the built CLI from this checkout (requires anegoruntime for real browser work;-his also supported).
Code Conventions & Common Patterns
- ESM only (
"type": "module"); Node 22+. - Public helpers are camelCase, verb-first for async actions (
ensureSession,runSiteTool). - V2
TaskSpaceandPagetime parameters are milliseconds. The v1 compatibility helpers keep their original units. - Helpers are injected into the script scope, not imported by agent scripts.
- New v2 APIs go through
public-api-schema.ts; keep runtime validation,help(), architecture, andskill-body/SKILL.mdin sync. - Snapshot refs (
@N) are short-lived; re-snapshot after navigation or DOM changes and prefer stableloc=...values for reuse. - Element-resolution failures should use
ElementResolutionErrorwith an honesttransient/permanentkind — wait loops rely on it. - The code prefers the small shared state singleton (
src/state.ts) over threading connection state through call sites. - Site skills must stay site-shaped and verifiable: stable URLs, durable selectors, no pixel coordinates, no secrets.
Testing & QA
- Framework: Node's built-in runner (
node --test), assertions vianode:assert/strict. - Tests run against the build output (
dist/src/...) —npm testbuilds first. - Behavior-focused tests inject overrides (
__testing.setOverrides) or aFakeEgodouble (seesrc/helpers.test.mjsandsrc/page-model.test.mjs). - Cover session handling, locator resolution, helper behavior, and site-skill validation when changing runtime code; run
npm run validate:site-skillsfor learning changes. npm run e2eis the self-contained real-browser gate, run by the pre-push hook (pre-commit runs only the fast checks against one shared build). It builds the current checkout, passes the resulting absolute bundle through--sdk-path, starts a local fixture server, uses a unique temporary task space, and cleans it up. A full pass records a fingerprint ofdist/out, the suite and the CLI undernode_modules/.cache/; an unchanged rerun skips, andEGO_BROWSER_REAL_E2E_FORCE=1overrides that. Do not link another runtime, reuse a prior E2E space, or manually take control while the suite is running.