Skip to content

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.

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 ​

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
expressionstringyesJavaScript expression; its value is the answer.
context"background" | "popup" | "options" | "side-panel" | "devtools" | "newtab" | "history" | "bookmarks" | "content" | "page"noDefault page on a Chromium MV3 session, else background; a closed surface is opened first (as extension_open does).
urlstringnocontent/page: the tab by url.
tabnumbernochrome.tabs id to break a url tie.
targetIdstringnoPage targetId (extension_open, extension_dom_snapshot listTargets); wins over url.
observeboolean | stringnofalsetrue adds value.observation, the settled surface's elements; a surface name (e.g. popup) reads that one.
browserstringnoRunning session's browser; needed when several run.
timeoutnumbernoTimeout ms (default 30000; Firefox 10000; debug port 15000).
untilobjectnoRe-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_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 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.