Skip to main content
Glama

browser_execute_script

Runs JavaScript expressions in the current Chrome page context to read or modify page state, await promises, and return results or errors without CSP blocking.

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). 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).

Input Schema

NameRequiredDescriptionDefault
codeYesJavaScript EXPRESSION to evaluate in page context. For multi-statement logic use an IIFE: (() => { ...; return result; })()

Schema Changelog

Changes observed during successful MCP inspections.

  1. 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; })()"
  2. First observedv1.0.0

TDQS

A4.3/5.0
Behavior4/5

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

With no annotations, the description carries the full burden and does so well: it discloses promise awaiting, the ok:false/error/name failure shape, no-retry semantics, a 29.5s ceiling, and the call-timeout/sent:false distinction between 'nothing ran' and 'code ran but failed'. What it omits is that arbitrary JS can mutate or persist page state and whether frame/context matters, which is material for an unannotated arbitrary-code tool.

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?

Front-loaded with the mechanism, then failure/timeout semantics, then the parameter warning — a sensible order with little waste. Slightly overlong: the IIFE instruction is repeated from the schema and the all-caps IMPORTANT block restates part of the constraint, but every element still serves the caller.

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

Completeness4/5

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

For a one-parameter tool with no annotations and no output schema, the description covers invocation form, error shape, and timeout behavior thoroughly. The remaining gap is the success payload — it never says what ok:true contains (the expression's value, and how non-serializable values are handled), which an agent needs given there is no output schema.

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, but the description adds genuinely new information: the accepted `script` alias, and the hard constraint that the value must be an expression with top-level `return` being a syntax error because the handler wraps in parentheses. The IIFE guidance partially duplicates the schema description, which keeps it off a 5.

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') and pins down the mechanism ('Chrome debugger Runtime.evaluate in the page's own context'). That mechanism detail is what separates it from siblings like browser_fetch or browser_get_page_content, so an agent can route correctly without opening the schema.

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?

It gives real selection context: the page's globals are visible and CSP does not block it, which tells the agent when this is the right tool versus a DOM-extraction sibling. However, no alternative tool is named and no 'when not to use this' exclusion is stated, so it stops short of full routing guidance.

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