Skip to main content
Glama

browser.eval_js

Executes a JavaScript expression in the current page context and returns its JSON result. Requires per-expression operator approval, so use read-only page tools first when possible.

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.

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.

Schema Changelog

Changes observed during successful MCP inspections.

  1. 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"
      +}
  2. Addedv1.8.1
  3. Removedv1.4.2
  4. 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."
  5. 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
  6. First observedv0.5.0

TDQS

A4.4/5.0
Behavior4/5

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

Discloses the non-obvious operator-approval gate, including the approval_required status and the retry-with-approval_id protocol — context the annotations do not provide. However, it never states that arbitrary JS can mutate page/session state, which is the reason readOnlyHint=false and openWorldHint=true matter here.

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 with zero waste; the core action, the approval prerequisite, and the safer alternatives appear in that priority order. Nothing is buried or repeated.

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?

Covers purpose, approval flow, and sibling routing for a 4-parameter tool with no output schema and existing annotations. It leaves a small gap around return shape beyond the approval case and around side effects of evaluated code, but an agent can call it correctly.

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 expression, session_id, timeout_ms, and approval_id are already documented, and the description's approval_id explanation largely restates the schema. No extra syntax, format, or scoping detail is added beyond what the schema provides.

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 is unambiguous. It also distinguishes itself from reading-oriented siblings by naming find_elements, get_html, and observe as preferred alternatives for reads.

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

Usage Guidelines5/5

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

Gives an explicit when-not rule ('Prefer find_elements, get_html or observe for reading the page — they need no approval') plus the exact retry condition for the approval flow. An agent knows both when to choose this tool and when to choose a sibling.

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