Execute JavaScript in a page
javascript_toolEvaluate a JavaScript expression in a Chrome tab's main or isolated world and return the last JSON-serializable value, even when the page's CSP blocks eval.
Instructions
Evaluate JavaScript in the main frame and return the value of the last expression. Do NOT use 'return' — just write the expression. The result must be JSON-serializable (undefined comes back as null); a returned promise is awaited for up to 25s. By default it runs in the page's MAIN world and sees the page's own JavaScript. world:'isolated' runs it in a dedicated isolated world of the main frame instead (reused within a document, so its own globals persist between calls): same DOM, but none of the page's globals or patched prototypes, so a page cannot change the DOM functions the script uses. It still reads the page's own content; if that world cannot be created the call fails and nothing runs (no fallback to MAIN). Runs through the debugger tier, so it works on pages whose Content-Security-Policy forbids eval — the page's own eval stays blocked, and the page's policy is never edited. Close DevTools on that tab first (only one debugger can attach). If the page navigates while the script is evaluating, the call fails and the script is NOT run again.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"text": "<text>",
"tabId": "<tabId>"
},
"name": "javascript_tool"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | JavaScript expression to evaluate | |
| tabId | Yes | Target tab ID (must be in the MCP group) | |
| world | No | 'main' (default): the page's own JavaScript world. 'isolated': a dedicated isolated world (reused within a document) sharing only the DOM |