extension_eval
Evaluate JavaScript in an 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
Answers the value; extension_element_act acts, extension_dom_snapshot, extension_inspect and extension_logs_read read without code. Needs allowEval:true at launch (by hand: --allow-eval), the debug port included; runs carry a user gesture. Safari: pages only; extension_logs_read 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 | JavaScript expression; its value is the answer. | |
context | "background" | "popup" | "options" | "side-panel" | "devtools" | "newtab" | "history" | "bookmarks" | "content" | "page" | no | Default page on a Chromium MV3 session, else background; a closed surface is opened first (as extension_open does). | |
url | string | no | content/page: the tab by url. | |
tab | number | no | chrome.tabs id to break a url tie. | |
targetId | string | no | Page targetId (extension_open, extension_dom_snapshot listTargets); wins over url. | |
observe | boolean | string | no | false | true adds value.observation, the settled surface's elements; a surface name (e.g. popup) reads that one. |
browser | string | no | Running session's browser; needed when several run. | |
timeout | number | no | Timeout ms (default 30000; Firefox 10000; debug port 15000). | |
until | object | no | Re-run until the value is truthy; {} for the default interval and limit. |
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 three groups and the session gates
- Install in your client
extension_element_act: Click or fill one element by CSS selector, or send trusted mouse and key input to a surface or page, with no caller code and no allowEval.extension_element_read: Read one element's text by CSS selector, or wait until it is visible, in a surface or page.extension_open: Open an extension surface or a url in a session, or replay the toolbar click, a menu item or a shortcut, over the control channel (by hand: --allow-control).extension_reload: Reload a running session's background, or one tab, through the control channel (allowControl); answers once it is back.extension_storage_read: Read the extension's storage (chrome.storage or browser.storage) from its background, with no eval.extension_storage_write: Write one key of the extension's storage (chrome.storage or browser.storage) from its background, with no eval.