Skip to main content
Glama

Evaluate JavaScript

browser_evaluate

Run custom JavaScript in a live page to read hidden state and return JSON-serialized results. Use it to extract values the accessibility tree doesn't expose.

Instructions

Runs JavaScript in the page and returns the JSON-serialized result. Accepts a bare expression ("document.title") or a function ("el => el.value"). When an element is targeted, it is bound to el. Use it to read state the accessibility tree does not expose.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cssNoCSS selector, as an alternative to ref.
refNoElement ref from the most recent snapshot, e.g. "e12". Preferred — refs are exact. Only valid for the page state that produced them.
nameNoAccessible name to match alongside role.
roleNoARIA role, e.g. "button". Combine with name for an accessible-name match.
indexNoWhich match to use when the selector is ambiguous (0-based, default 0).
maxCharsNo
sessionIdYesSession id returned by browser_start.
expressionYesExpression or function source to evaluate.
Behavior4/5

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

Although annotations already indicate readOnlyHint: false and openWorldHint: true, the description adds useful behavioral context: it accepts expressions or functions, binds targeted elements to `el`, and returns JSON-serialized results. It doesn't explicitly warn that arbitrary JS may have side effects, but that is implied by 'Runs JavaScript' and already covered by openWorldHint. No contradiction with annotations.

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 two sentences plus a usage example—no fluff. It front-loads the primary purpose and then adds the details that matter most (function form and element binding). Every sentence earns its place, and the example is illustrative without being verbose.

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?

With no output schema, the description explains the return type ('JSON-serialized result'). It covers the two execution modes, element binding, and a usage scenario. It doesn't enumerate all 8 parameters, but the high schema coverage handles that. The only minor gap is an explicit note that JavaScript can have side effects, though openWorldHint already implies this.

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 88%, so most parameters are documented. The description adds meaning beyond the schema by explaining the `expression` parameter with examples and clarifying how element targeting works (binding to `el`). It also implies how `css`/`ref`/`role`/`name` selectors relate to the expression, which the schema does not explicitly connect.

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 verb ('Runs JavaScript'), the resource ('in the page'), and the output ('JSON-serialized result'). It includes concrete examples ('document.title' and 'el => el.value') that make the purpose unmistakable. It differentiates from sibling browser_* tools because it is the only one that executes arbitrary JavaScript.

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?

The description provides a clear use case: 'Use it to read state the accessibility tree does not expose.' This tells agents when it is appropriate, but it does not explicitly mention alternatives or when not to use it (e.g., 'for accessible text use browser_read_text'). The guidance is implicit rather than explicit about exclusions.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hofmeister/web-ui-tester'

If you have feedback or need assistance with the MCP directory API, please join our Discord server