Skip to main content
Glama

browser.eval_js

Execute custom JavaScript in the current page context and retrieve the result. Requires explicit approval per expression; use for actions that need dynamic scripting, not for routine reading.

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

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

TDQS

A4.7/5.0
Behavior5/5

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

Beyond annotations, the description discloses the critical approval behavior: every call requires operator approval for that exact expression, the first call returns approval_required with an approval_id, and the call must be retried with that ID. This is essential operational context that is not present in the annotations or schema and directly affects how an agent invokes the tool.

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 three focused sentences: purpose, approval protocol, and alternative tools. It front-loads the core behavior and approval constraint, with no filler or redundant content.

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

Completeness5/5

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

For a mutation-capable eval tool with no output schema, the description plus schema covers all necessary invocation details: the expression, session handling, approval flow, result expectation, and less-privileged alternatives. An agent has enough information to call it correctly and recover from the approval_required status.

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%, and each parameter already has a meaningful schema description, particularly expression and approval_id. The tool description reinforces the approval flow but adds no parameter semantics beyond what the schema provides, so the baseline of 3 is 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?

The description states a specific operation: execute a JavaScript expression in the current page context and return the result. It also distinguishes itself from sibling read tools by explicitly naming find_elements, get_html, and observe as preferred alternatives. This leaves no ambiguity about what the tool does or how it differs.

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?

The description gives explicit when-not guidance: prefer find_elements, get_html, or observe for reading because they need no approval. It also explains the approval retry workflow, so an agent knows the exact conditions under which eval_js should be used and how to proceed after an approval_required response.

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