Skip to main content
Glama

browser_execute_script

Run JavaScript expressions in the current Chrome page context through the debugger, await returned promises, and get results or errors; use an IIFE for multi-statement logic.

Instructions

Execute JavaScript in the current page, through the Chrome debugger (Runtime.evaluate) in the page's own context: the page's globals are visible and its Content Security Policy does not block it. A returned promise is awaited. If the code throws, the answer is ok:false with error and name, and the code is not run again. The call answers within 29.5 s; if the time runs out before the code is sent, the answer is error call-timeout with sent:false (nothing ran). If no answer reaches the server within 45 s (Chrome itself stalled), the answer is error no-answer with sent:"unknown": the code MAY have run, it is not repeated, and you should call again only if it is safe to run twice. IMPORTANT: the parameter is code (NOT script - though that alias is accepted), and it must be an EXPRESSION, not statements: use an IIFE (() => { ...; return x; })(). Top-level return is a syntax error (the handler wraps code in parentheses).

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": {
      "code": "<code>"
    },
    "name": "browser_execute_script"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeYesJavaScript EXPRESSION to evaluate in page context. For multi-statement logic use an IIFE: (() => { ...; return result; })()
partitionNoRun this call in a partition from browser_partition (an id like "p1"). Leave it out for the default partition. An unknown or closed id is an error; the call is never sent to the default partition instead.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.33.0
    • addedInput schema / properties / partition
      Added value: +{
      +  "description": "Run this call in a partition from browser_partition (an id like \"p1\"). Leave it out for the default partition. An unknown or closed id is an error; the call is never sent to the default partition instead.",
      +  "type": "string"
      +}
  2. Changed1 schema field changedv1.28.0
    • changedInput schema / properties / code / description
      Previous value: -"JavaScript expression to evaluate (runs in page context)"New value: +"JavaScript EXPRESSION to evaluate in page context. For multi-statement logic use an IIFE: (() => { ...; return result; })()"
  3. First observedv1.0.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations supplied, the description carries the full burden and does so thoroughly: CSP is not a blocker, page globals are visible, returned promises are awaited, thrown errors come back as ok:false with error/name and are not retried. It also discloses two distinct failure paths with concrete timings (29.5 s send timeout with sent:false, 45 s no-answer with sent:"unknown" and possibly-executed code), which is exactly the non-idempotency risk an agent needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Opens with the core purpose and stacks the failure modes in the order an agent would encounter them, so it is well front-loaded. It is dense and the capitalized 'IMPORTANT' block is slightly shouty, but nearly every sentence supplies a fact that changes agent behavior (timeouts, non-retry semantics, expression vs. statements).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

There is no output schema, so the description must describe returns itself, and it does: ok/error shapes, the name field, and the sent flag values including the ambiguous 'unknown'. For a tool that can execute arbitrary code with irreversible side effects, all the risk-relevant context is present.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; the description earns more by adding that `script` is accepted as an alias for `code` and by explaining why top-level `return` fails (the handler wraps code in parentheses) and what shape the code must take. The `partition` parameter is left entirely to the schema, which is acceptable given the schema documents it.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Execute JavaScript in the current page') plus the exact mechanism (Chrome debugger Runtime.evaluate, page's own context). This clearly separates it from siblings like browser_fetch or browser_extract_list, which do not run arbitrary code in page context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit conditional guidance for the ambiguous retry case ('call again only if it is safe to run twice') and warns that the call must be an expression rather than statements. It does not, however, say when to prefer this over sibling tools that could accomplish similar tasks, so it stops short of full alternative routing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.