agent-sphere / agent-sphere-chrome-extension
AGENTS.md119 starsChanged 2 months agoMITView on GitHub
Manifest V3 Chrome extension that bridges the AgentSphere backend with the browser for automated operations. Backend agent-sphere-common holds the chrome-bridge DTOs (ChromeCommandDTO, ChromeCallbackDTO, ChromePendingStore). Files: - background.js — router; imports lib/cdp-client.js, lib/tab-manager.js, lib/result.js, lib/offscreen-bridge.js. Keep it ESM; the SW is "type": "module". - lib/cdp-client.js — single chrome.debugger wrapper: per-tab sessions, onDetach clears the tab's session (self-heal), sendCommand throws Debugger is not attached… when stale, all ops serialized through a promise queue, evaluate retries once on detach races. Do not call…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 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 repository2 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-sphere/AGENTS.mdAGENTS.md
The file
We split this AGENTS.md into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 40
Keep that order. Do not make debugger the default path.
- Very specific: line 44
Tab grouping: every tab the plugin navigates/opens is added to the AgentSphere group (tabGroups permission).
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 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 Chrome extension that bridges the AgentSphere backend with the browser for automated operations. Backend agent-sphere-common holds the chrome-bridge DTOs (ChromeCommandDTO, ChromeCallbackDTO, ChromePendingStore).
Current state (observable — verify if changed)
package.jsonscriptsbuild/devcallnode build.js, butbuild.jsdoes not exist —npm run buildFAILS.src/is empty stubs. Edit root-level files directly and load unpacked viachrome://extensions.- No build step. Background is native ES modules (
background.jswith"type": "module"imports fromlib/). Do not introduce a bundler — the deploy workflow zips these files directly.
Architecture
backend (SSE task stream ⇄ HTTP callback)
↕
offscreen.html/js — long-lived task SSE + command queue (immune to SW suspension)
↕ runtime message {target:'background', action:'task:command'}
background.js (ESM) — message router, executeInPage, tab grouping, callback POST
↕ tabs.sendMessage / chrome.scripting / chrome.debugger
content.js + content-locator.js — primary execution layer (ISOLATED world)
page-script.js (MAIN world) — auth/session bridge (sessionStorage → content script)Files:
background.js— router; importslib/cdp-client.js,lib/tab-manager.js,lib/result.js,lib/offscreen-bridge.js. Keep it ESM; the SW is"type": "module".lib/cdp-client.js— singlechrome.debuggerwrapper: per-tab sessions,onDetachclears the tab's session (self-heal),sendCommandthrowsDebugger is not attached…when stale, all ops serialized through a promise queue,evaluateretries once on detach races. Do not callchrome.debuggeroutside this file.lib/tab-manager.js— controlled tab, content-script injection (3 files, ordered),askContentauto-re-injects on "Receiving end does not exist", and theAgentSpheretab group (aggregates every plugin tab; recreated if the group is closed).lib/offscreen-bridge.js— creates/pings the offscreen doc (alarm recreates it if the browser closes it).offscreen.js— holds/api/v1/runtime/user/task/streamSSE, zombie detection, reconnect, forwardsbrowser_operationto background. Offscreen documents support ONLYchrome.runtime— nochrome.storage/chrome.tabsthere. Token/baseUrl are fetched from background viatask:creds, and connection status is reported viatask:status(background writesstorage.local.taskConnected). Do not callchrome.storageinsideoffscreen.js.content-locator.js/content.js— injected together (in that order) into the isolated world; share thewindow.__asContentnamespace. Write actions (click/type/key/hover) run via CDP trusted input inbackground.js; content script only reads/wait/scroll/uploads.inject.js— deleted. There is no inject-bridge tier anymore.page-script.js— MAIN-world script (web_accessible) interceptingwindow.open.
Key behaviors
- Screenshots (vision operation):
screenshotaction (viewport viaPage.captureScreenshot,scope=fullusescaptureBeyondViewport) lives only inlib/cdp-client.js#captureScreenshot— the one place allowed to callchrome.debugger. The base64 is POSTed toPOST /api/v1/browser/screenshot(Bearer) and the callback carries only thefileKey+ dimensions (no large base64 over the callback/Redis).clickAt(x, y)clicks at the device pixels of the last viewport screenshot (converted to CSS px viadevicePixelRatio); non-interactive points click through with awarning. Snapshot items carrybounds(top-frame CSS px rect) for screenshot↔ref alignment. Full-page screenshots are observation-only — no coordinate clicking. - executeJS is two-tier, debugger is the strict-CSP fallback (in
background.js#executeJsOnTab):- MAIN world via
chrome.scripting(world:'MAIN') — the page CSP applies, so this works on most sites and fails fast on strict-CSP origins (cached incspBlockedOrigins). chrome.debuggerRuntime.evaluate(bypasses CSP; strict sites like 猎聘 land here). There is NO isolated-world tier: MV3's extension CSP (script-src 'self' 'wasm-unsafe-eval' …) forbidseval()/new Function()in content-script isolated worlds, so an isolated eval can never work — do not reintroduce it. Keep that order. Do not make debugger the default path.
- MAIN world via
- executeJS result transparency: results always carry
method(scripting-main/debugger),resultType, and — when execution may have been blocked or the value was unserializable — awarningfield. The backend surfaces these (ChromeResultVO.warning/resultType) so the agent stops retrying a blocked executeJS. - Content-script capabilities:
click/type/hoveracceptindex(1-based, selector) andoccurrence(1-based, text) to pick the Nth of identical elements (content-locator.js).closeDialogscloses every open[role="dialog"]/toast in one call.getContent(mode: query, selector)returns a compact up-to-50-element match list instead of the full DOM.getContentfull mode is capped at 2000 DOM nodes. - Debugger disconnects: an external detach (opening DevTools on the controlled tab, cross-site navigation) drops the session. The
onDetachlistener + retry-once incdp-client.jsmake the next command self-heal. It is still best to avoid opening DevTools on the controlled tab and to avoid cross-site navigation mid-task. - Tab grouping: every tab the plugin navigates/opens is added to the
AgentSpheregroup (tabGroupspermission). Requires thetabGroups+offscreenpermissions — keep them inmanifest.json. - Results carry
errorCategory(not_found/csp_blocked/detached/inject_failed/timeout/no_tab) andmethodso the backend agent can pick a retry strategy instead of blind retries. - Auth flow unchanged: content script reports
token→ background stores instorage.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.
No tests / linter / CI
Manually reload the unpacked extension and smoke-test before pushing:
- log in on a widget/main site → Task badge on
navigateseveral tabs → all land in theAgentSpheregroup- executeJS on a normal site (MAIN-world scripting) and on a strict-CSP site (debugger fallback)
- cross-site navigation mid-task → next executeJS recovers
devtoolson the controlled tab → session self-heals on next command
Git
GitHub flow: feature 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.

