Skip to main content
Glama

browser_execute_script

Run custom JavaScript expressions in the current browser page to read data, modify elements, or trigger actions, solving automation limits by returning computed results directly from the live DOM.

Instructions

Execute JavaScript in the current page. 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

TableJSON 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.2/5.0
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It discloses the handler wrapping behavior (which causes top-level return to fail) and the alias acceptance. This gives useful insight into how the tool processes input, though it does not warn about potential side effects or security implications of executing arbitrary JavaScript.

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

Conciseness5/5

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

The description is a single, focused sentence that front-loads the core purpose and then immediately addresses the most critical usage pitfalls. Every word earns its place, with no fluff or redundancy.

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 simple one-parameter tool with no output schema, the description covers the essential aspects: what it does, the parameter name, the expression requirement, and the wrapping behavior. It does not specify the return value, but that is not necessary given the lack of an output schema. The description is sufficient for correct invocation.

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?

The schema already describes the code parameter as an expression with IIFE guidance, achieving 100% coverage. The description adds value by clarifying the alias (script) and explaining the consequence of using top-level return, which is not in the schema. This extra semantic detail helps the agent avoid common mistakes.

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?

The description clearly states the tool executes JavaScript in the current page, with a specific verb and resource. It distinguishes itself from siblings like browser_fetch or browser_console_logs by its purpose, and the prominent IMPORTANT note adds specificity.

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

Usage Guidelines3/5

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

The description provides critical usage instructions: the correct parameter name (code, not script) and the requirement that the input be an expression, not statements. It also warns about the top-level return error. However, it does not explicitly state when to use this tool versus alternatives like browser_fetch or browser_evaluate (if such existed), so it lacks guidance on tool selection.

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