agent-sphere / agent-sphere-chrome-extension
AGENTS.md78 starsChanged 18 days agoMITView on GitHub
Manifest V3 extension bridging the AgentSphere backend with the browser. Backend DTOs live in agent-sphere-common (ChromeCommandDTO, ChromeCallbackDTO, ChromePendingStore).
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 33,398 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-sphere/AGENTS.mdAGENTS.md
- agent-sphere-copilot-widget/AGENTS.mdAGENTS.md
- agent-sphere-ui/AGENTS.mdAGENTS.md
The file
We split this AGENTS.md into the rules it gives an agent
6 rules. About 0 are common, 0 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 42
Tab grouping: all agent tabs live in a dedicated agent window/group.
- Very specific: line 45
navigate must verify the real page: read location.href via agent_sphere_ping, not chrome.tabs.url (stale during redirects).
- Very specific: line 55
No tests/linter/CI. Injected scripts are classic scripts.
- Very specific: line 72
Every getContent mode returns data.
- Very specific: line 87
Use one delegated listener per container.
- Very specific: line 92
Never include a specific third-party site brand/domain in code, comments, logs, tests, or docs.
≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AgentSphere Chrome Extension
Manifest V3 extension bridging the AgentSphere backend with the browser. Backend DTOs live in agent-sphere-common (ChromeCommandDTO, ChromeCallbackDTO, ChromePendingStore).
No build step
package.jsonscripts point to a missingbuild.js;npm run buildfails.src/is empty stubs. Edit root-level files directly and reload the unpacked extension fromchrome://extensions.- Background is native ESM (
background.js,"type": "module"). Do not introduce a bundler; deploy zips these files directly.
Architecture
backend (SSE task stream ⇄ HTTP callback)
↕
offscreen.html/js — long-lived task SSE + command queue
↕ runtime message {target:'background', action:'task:command'}
background.js — router, executeInPage, tab management, callback POST
↕ tabs.sendMessage / chrome.scripting / chrome.debugger
content.js + content-locator.js — isolated-world execution
page-script.js — MAIN-world auth/session bridgebackground.js— ESM router; importslib/cdp-client.js,lib/tab-manager.js,lib/result.js,lib/offscreen-bridge.js.lib/cdp-client.js— the only file allowed to callchrome.debugger. Per-tab sessions,onDetachclears state,sendCommandthrows when stale, all operations serialized with per-op deadlines.lib/tab-manager.js— controlled tab, isolated AgentSphere window, ordered content-script injection,AgentSpheretab group, per-session tab registry.lib/offscreen-bridge.js/offscreen.js— long-lived SSE and command queue. Offscreen documents support onlychrome.runtime; never usechrome.storageorchrome.tabsthere.content-locator.js/content.js— injected together, sharewindow.__asContent; write actions use CDP trusted input frombackground.js.page-script.js— MAIN-world script interceptingwindow.open.lib/agent-cursor.js— pointer animation with arrival barrier before CDP click.
Key behaviors
- Cursor: content script mutates the DOM directly from the isolated world; no MAIN-world postMessage bridge. Pointer stays visible after landing; only the trail fades.
- Locator determinism: snapshot refs follow DOM order; write actions reuse the resolved element via
_reuseToken, never re-resolve. - Failure taxonomy (
lib/result.js):not_found/not_interactable/occluded/ambiguous; keep them distinct. - Fail-fast loading: missing/broken
content-locator.jsmust surface asinject_failed, not scatteredTypeErrors. - Screenshots:
lib/cdp-client.js#captureScreenshotonly. Base64 POSTs to/api/v1/browser/screenshot; callback carriesfileKey+ dimensions.clickAtuses the last viewport screenshot coordinates. Full-page screenshots are observation-only. - executeJS is two-tier: MAIN world via
chrome.scriptingfirst;chrome.debuggerRuntime.evaluateonly as strict-CSP fallback. There is no isolated-world tier (MV3 CSP forbids eval there). Keep that order. - executeJS results carry
method,resultType, and optionalwarning. - Timeout layering: extension
EXECJS_TIMEOUT_MS(27s) < backendEXECUTEJS_TIMEOUT_SECONDS(30s) <COMMAND_LEASE_MS(60s). - Tab grouping: all agent tabs live in a dedicated agent window/group; user tabs are never reused or navigated.
tabGroups+offscreenpermissions are required. - Background compatibility:
backgroundFocusMode(autodefault) probesdocument.visibilityState; a hidden/occluded agent window is focused before navigation and actions so Chrome does not pause rAF / clamp timers.alwaysfocuses every command,neverkeeps the legacy behavior. Focus returns to the user's window after 30s idle (alarm fallback for service-worker eviction). - Session-scoped tabs:
findReusableTab()only considers tabs registered to the current session; never fall back to any tab in the agent window. - navigate must verify the real page: read
location.hrefviaagent_sphere_ping, notchrome.tabs.url(stale during redirects). - Results include
errorCategory(not_found/csp_blocked/detached/inject_failed/timeout/no_tab) andmethod. - Auth: content script reports token → background stores in
storage.local→ offscreen reads it; storage change triggers reconnect.
Permissions (manifest.json)
tabs, scripting, storage, activeTab, alarms, debugger, webNavigation, tabGroups, offscreen; host <all_urls>. page-script.js is web-accessible.
Syntax checks
No tests/linter/CI. Injected scripts are classic scripts; node --check may accept top-level return that Chrome rejects. Use vm.Script:
node -e "const vm=require('vm'),fs=require('fs'); for (const f of ['content.js','content-locator.js','page-script.js']) new vm.Script(fs.readFileSync(f,'utf8'),{filename:f});"- Top-level
return/awaitis illegal in these files; put idempotency guards inside the IIFE.
Manual smoke test
- Log in on a widget/main site → Task badge on.
navigate: separate unfocused agent window opens; tabs land in theAgentSpheregroup; user window stays active.- Hidden/occluded agent window: the next navigate/action brings it forward (auto mode) and completes; focus returns after 30s idle.
navigatetwice with the same URL: reuse only inside the agent window.- executeJS on a normal site (scripting) and a strict-CSP site (debugger).
- Cross-site navigation mid-task → next executeJS recovers.
- DevTools on the controlled tab → session self-heals on next command.
- Every
getContentmode returns data; all failing at once suggestscontent-locator.jsfailed to load. - Popup Metrics tab: enable metrics, run a task, counters rise.
Local metrics (no backend)
lib/browser-metrics.jsis client-side only; off by default (settings.browserMetrics).browserMetricsholds counters/latency;browserMetricsRecentholds a 300-record ring buffer; keep them separate so popup re-render is cheap.- Counters are monotonic; never trim them.
selfChangedUnknownis excluded from both sides of the mis-click rate.misclickSuspect = changed === true && selfChanged === false;audit_verdictis ground truth.popup.js#snapshotOfduplicatesbuildSnapshot()arithmetic; change both together.
Popup rendering
- Escape every tool/user-derived string with
esc()beforeinnerHTML. Tool errors contain markup (e.g.<div#modal>). - Use one delegated listener per container; inline
onclick=is illegal under MV3 CSP. - Log rows use CSS ellipsis only; full text comes from
data-lineandtitle.
No third-party brands
Never include a specific third-party site brand/domain in code, comments, logs, tests, or docs. RISK_URL_PATTERNS must stay generic (//safe. prefix + captcha/intercept fragments). Move real site data to config; never edit applied Flyway migrations.
Release
deploy.yml zips an explicit root-level file list plus the whole lib/. Add every new root-level JS file to that list. Missing inject.js / content-editors.js entries are historical; do not recreate them.
Git
GitHub flow: branch off main → PR.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

