Skip to main content
Glama

browser.eval_js

Execute a JavaScript expression in the current page and return its JSON result; the first call returns approval_required, so retry with approval_id once approved.

Instructions

Execute a JavaScript expression in the current page context and return the result. Every call needs operator approval for that exact expression: the first call returns status approval_required with an approval_id; retry with approval_id once it is approved. Prefer find_elements, get_html or observe for reading the page — they need no approval.

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.eval_js"
  }
}

Input Schema

NameRequiredDescriptionDefault
expressionYesJavaScript expression or function source, evaluated in the page; returns its JSON value.
session_idNoTarget session id, from browser.create_session or browser.list_sessions. Optional when exactly one session is live; observe and act tools create one when none is.
timeout_msNoHow long to wait for the expression, at most 60000; omitted, 30000. One that times out may still be running in the page.
approval_idNoID of the approval granted for exactly this expression. The first call returns status approval_required with an approval_id; call again with it once an operator approves.
workflow_profileNogoverned: a call that can change something waits for approval. It answers status approval_required with an approval_id; call again with that id once it is granted. fast, the default, runs it directly unless this tool or deployment always requires approval.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.19.0
    • addedInput schema / properties / workflow_profile
      Added value: +{
      +  "description": "governed: a call that can change something waits for approval. It answers status approval_required with an approval_id; call again with that id once it is granted. fast, the default, runs it directly unless this tool or deployment always requires approval.",
      +  "enum": [
      +    "fast",
      +    "governed"
      +  ],
      +  "type": "string"
      +}
  2. Changed1 schema field changedv1.12.1
    • addedInput schema / properties / timeout_ms
      Added value: +{
      +  "anyOf": [
      +    {
      +      "maximum": 60000,
      +      "minimum": 100,
      +      "type": "integer"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "How long to wait for the expression, at most 60000; omitted, 30000. One that times out may still be running in the page.",
      +  "title": "Timeout Ms"
      +}
  3. Addedv1.8.1
  4. Removedv1.4.2
  5. Changed1 schema field changedv1.4.2
    • addedInput schema / properties / session_id / description
      Added value: +"ID of the target browser session, as returned by browser.create_session or listed by browser.list_sessions."
  6. Changed3 schema fields changedv1.0.3
    • addedInput schema / additionalProperties
      Added value: +false
    • addedInput schema / properties / session_id / maxLength
      Added value: +120
    • addedInput schema / properties / session_id / minLength
      Added value: +1
  7. First observedv0.5.0

TDQS

A4.2/5.0
Behavior4/5

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

The description surfaces the two-phase approval workflow prominently (first call returns approval_required with an approval_id, retry with it), which is the dominant behavioral trait of this tool and is consistent with annotations (readOnlyHint=false, destructiveHint=false, openWorldHint=true). Much of this is echoed from the approval_id and workflow_profile schema descriptions, and it does not cover what happens to non-serializable return values, so it is strong but not exhaustive.

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?

Three sentences, each earning its place: capability first, then the non-obvious approval protocol, then the cheaper alternatives. Front-loaded and free of filler.

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 single required parameter plus optional session/timeout/approval controls with no output schema, the description covers the critical operator-approval loop and the main failure mode (timeout, documented in schema). The remaining gap is return-value shape — the description says 'return the result' without noting serialization limits or the approval_required payload structure an agent must parse.

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 100%, so expression, session_id, timeout_ms, approval_id and workflow_profile are already well documented in the structured data. The description only restates the approval_id retry pattern and adds no syntax, scoping or format detail beyond the schema, making the 3 baseline appropriate.

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 a JavaScript expression in the current page context and return the result — which no sibling does. It also distinguishes itself from the reading tools (find_elements, get_html, observe) by implication, so an agent can select it 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?

Gives explicit when-not guidance by naming three alternatives for reading the page and the reason to prefer them (no approval needed). It stops short of saying when eval_js is the correct choice over those tools — presumably when they cannot express the read — so it is clear but not fully bidirectional.

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