Skip to content

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.

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 ​

Grouplocal, on by default
TierAct
Needsa session started with allowEval: true on extension_dev
Read onlyno
Destructiveyes
Idempotentno
Reaches the open webyes

Inputs ​

InputTypeRequiredDefaultWhat it does
projectPathstringyesProject root of a running session: extension_dev, extension_start, or npx extension dev|start by hand
expressionstringyesExpression to evaluate.
context"background" | "popup" | "options" | "sidebar" | "devtools" | "newtab" | "history" | "bookmarks" | "content" | "page"noDefault background; surfaces must be open (extension_open).
urlstringnocontent/page: the tab by url.
tabnumbernochrome.tabs id to break a url tie.
targetIdstringnoA page's targetId (extension_open, or dom_snapshot listTargets); overrides url.
browserstringnoSession browser; required when several run.
timeoutnumbernoTimeout ms (default 30000; Firefox 10000; debug port 15000).
untilobjectnoRepeat 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_dev or extension_start and call again.
  • Eval is refused. Eval is the one gate that stays off. Start the session with allowEval: true on extension_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.