Skip to main content
Glama

browser-evaluate

Execute JavaScript code directly in the browser and retrieve results. Supports expressions, functions, async/await, and targeting specific DOM elements for precise evaluation.

Instructions

Evaluates JavaScript code directly in the browser context and returns the result. Supports expressions, function strings, and complex code with automatic execution handling. Can target the entire page or work with element handles for precise DOM manipulation.

Examples:

  • Simple expression: "document.title"

  • Arrow function: "() => document.querySelectorAll('a').length"

  • Regular function: "function() { return document.body.children.length; }"

  • Function with arguments: "(tag) => document.getElementsByTagName(tag).length"

  • Complex code: "() => { const divs = document.querySelectorAll('div'); return { count: divs.length, hasClass: divs[0]?.className }; }"

  • Async function: "async () => { const res = await fetch('/api'); return res.json(); }"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
functionYesJavaScript code to execute (expression or function string). Examples: - Expression: "document.title" - Arrow function: "() => document.querySelectorAll('a').length" - Regular function: "function() { return document.body.children.length; }" - With arguments: "(tag) => document.getElementsByTagName(tag).length" - Async function: "async () => { const res = await fetch('/api'); return res.json(); }"
argsNoOptional arguments to pass to the JavaScript function. Can be primitives, objects, arrays, or element references. Example: { url: "https://example.com", count: 5 }
elementNoCSS selector to target specific element for evaluation
contextIdNoBrowser ID to execute on (uses most recent browser if not provided)
timeoutNoExecution timeout in milliseconds (default: 30000)
returnTypeNoExpected return type for better serialization (default: auto)
Behavior3/5

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

The description mentions support for expressions, functions, async execution, and automatic handling, but lacks details on side effects, permissions, error behavior, or return value structure. With no annotations, this is only moderately transparent.

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?

The description is front-loaded with the core verb and includes a well-organized list of examples. It is slightly verbose with six example cases, but each adds clarity. Could be trimmed slightly without loss.

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?

For a tool with 6 parameters and no output schema, the description could explain return value format and error handling more clearly. The phrase 'returns the result' is vague, and 'automatic execution handling' lacks specifics. Sibling tools often provide more structured outputs.

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 100%, baseline 3. The description adds value by listing multiple example formats for the 'function' parameter, clarifying how to pass various JavaScript code snippets. However, other parameters are not further elaborated beyond the schema.

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 'Evaluates JavaScript code directly in the browser context and returns the result.' It distinguishes from sibling tools like get-element-html or capture-screenshot by focusing on arbitrary JavaScript execution.

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

Usage Guidelines3/5

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

The description provides examples of what the tool can do but does not explicitly state when to use it versus alternatives like execute-browser-commands or get-element-properties. Usage is implied but not guided.

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/ESnark/blowback'

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