Skip to main content
Glama

执行 JavaScript

browser_evaluate
Destructive

Evaluate a JavaScript expression in the page or a referenced element and return the result as JSON, enabling retrieval of computed styles or JS variables not available from snapshots or extraction.

Instructions

Evaluate a JavaScript expression in the page (or on a specific element by ref) and return the result as JSON. Runs in the page main world. Use for values not exposed by snapshot/extract, e.g. reading a computed style or a JS variable. The expression must be a single expression or IIFE.

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": {
      "expression": "<expression>"
    },
    "name": "browser_evaluate"
  }
}

Input Schema

NameRequiredDescriptionDefault
refNoElement ref to bind as the `element` variable (optional)
tabIdNoTab id (default: active tab)
expressionYesJavaScript expression to evaluate, e.g. "document.title" or "(() => {...})()"

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.15.0

TDQS

A3.8/5.0
Behavior3/5

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

Annotations already declare destructiveHint=true, openWorldHint=true and readOnlyHint=false, so the safety profile is carried structurally; the description adds real context beyond that by disclosing that code runs in the page main world and that the expression must be a single expression or IIFE. It does not, however, warn that evaluated code can mutate page state, nor what happens to non-serializable results, which matters for a destructiveHint 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?

Three short sentences, front-loaded with the core action and result format, then the routing hint, then the expression-form constraint. No filler, though the alternative-tool guidance could have been merged into the first sentence for tighter structure.

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

Completeness3/5

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

The description covers what the tool does, where it runs, and the expression form, and it names the return format in lieu of an output schema. For a tool flagged destructive and open-world, it leaves gaps around side effects, side-effect rollback, and serialization limits of the returned JSON.

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 coverage is 100%, so all three parameters are already documented, including the `element` binding for `ref`. The description reinforces the element-ref behavior but adds no syntax or format detail beyond the schema, so the baseline 3 applies.

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 ('Evaluate a JavaScript expression in the page... and return the result as JSON') and explicitly scopes it against alternatives by naming snapshot/extract as the tools for values this one should not be used for. An agent can tell this apart from browser_extract or browser_find without opening any 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?

Provides a clear positive selection rule ('Use for values not exposed by snapshot/extract') with two concrete examples (computed style, JS variable), which is genuinely actionable routing guidance. It stops short of explicit when-not-to-use exclusions or prerequisites, so it sits just below the top band.

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