Skip to main content
Glama

Run JavaScript in the page

browser_eval

Run JavaScript in the current browser page and return its JSON-serializable result; promises are awaited, and an isolated world is optional.

Instructions

Run JavaScript in the page and return its JSON-serialisable result. An expression returns its value; for statements, use return. Promises are awaited. Runs in the page's own world by default (sees its globals); world "isolated" keeps it apart. Needs Chrome's "Allow User Scripts" switch for Deputy; the error says how to turn it on.

Input Schema

NameRequiredDescriptionDefault
codeYes
tabIdNo
worldNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.2

TDQS

A3.7/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 well: it discloses the default execution world and its global-visibility consequence, the alternate 'isolated' world, promise awaiting, JSON-serialisability of results, and an environment prerequisite ('Allow User Scripts' switch for Deputy) with error-message guidance. It omits side-effect/error-behavior detail (e.g., whether thrown errors surface or page mutations persist), keeping it from a 5.

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?

Four tight sentences, front-loaded with the core action and return contract, then edge behaviors. Densly informative with little waste, though the Deputy note and world clause could be trimmed slightly.

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?

No output schema and no annotations, so the description must cover return values and constraints; it does both (JSON-serialisable result, awaited promises, permission prerequisite). The main remaining gap is the unexplained tabId parameter and no statement of error behavior, but the essentials for correct invocation are present.

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

Parameters3/5

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

Schema description coverage is 0%, so the description must compensate. It explains `world` semantics (main default sees page globals, isolated keeps separate) and `code` semantics, but `tabId` is never addressed, leaving one of three parameters undocumented anywhere.

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

Purpose4/5

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

States a specific verb+resource ('Run JavaScript in the page and return its JSON-serialisable result'), which is clearly distinct from observation siblings like browser_read or browser_console. It does not explicitly position itself against those siblings, so it stops short of a 5.

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?

It gives practical usage detail (expression vs statement with `return`, promises awaited, world selection, the Deputy switch), which implies when the tool applies, but it never states when to prefer this over browser_extract, browser_inspect, or browser_console. Usage guidance is implied rather than explicit.

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