extension_eval
Evaluate JavaScript in a running extension's background, surface, content script, page or targetId.
Quick start
Evaluate chrome.runtime.id in the background and in the popup
Asked to evaluate an expression, the agent starts the session with eval on and reads the value back.
How the agent uses it
Needs allowEval:true at start (by hand: --allow-eval) on every route, the debug port included, whose runs carry a user gesture. Safari: pages only; extension_logs reads the background.
Page text in the answer
Part of this tool's answer is text a web page or the extension wrote. The server fences it between <untrusted-data-ID> and </untrusted-data-ID> with a fresh random ID per call, named in untrusted.boundary. A fence is a signal to the model, not a gate: pair it with --no-ship when the agent reads pages you do not trust. See Server flags and telemetry.
Reference
| Group | local, on by default |
| Tier | Act |
| Needs | a session started with allowEval: true on extension_dev |
| Read only | no |
| Destructive | yes |
| Idempotent | no |
| Reaches the open web | yes |
Inputs
| Input | Type | Required | Default | What it does |
|---|---|---|---|---|
projectPath | string | yes | Project root of a running session: extension_dev, extension_start, or npx extension dev|start by hand | |
expression | string | yes | Expression to evaluate. | |
context | "background" | "popup" | "options" | "sidebar" | "devtools" | "newtab" | "history" | "bookmarks" | "content" | "page" | no | Default background; surfaces must be open (extension_open). | |
url | string | no | content/page: the tab by url. | |
tab | number | no | chrome.tabs id to break a url tie. | |
targetId | string | no | A page's targetId (extension_open, or dom_snapshot listTargets); overrides url. | |
browser | string | no | Session browser; required when several run. | |
timeout | number | no | Timeout ms (default 30000; Firefox 10000; debug port 15000). | |
until | object | no | Repeat until truthy ({} for defaults); never sleep in a shell. |
When it fails
- The call is refused because no session is live. Start one with
extension_devorextension_startand call again. - Eval is refused. Eval is the one gate that stays off. Start the session with
allowEval: trueonextension_dev. - The answer depends on the network. This tool reaches the open web, so a refusal can be the network, not the project.
Next
- MCP server: install, the two groups and the session gates
- Install in your client
extension_open: Open an extension surface or a url, or replay the toolbar action or a shortcut, over the control channel (by hand: --allow-control).extension_reload: Reload the extension's background, or a tab, over the control channel (allowControl); a background reload waits up to 5 s.extension_storage: Read or write one chrome.storage key from the background, over the control channel.