Skip to main content
Glama

browser_js

Execute arbitrary JavaScript in the browser context to extract data, inspect objects, or test security. Returns the evaluated result.

Instructions

Execute arbitrary JavaScript in the browser page context. Returns the expression's result.

PREREQUISITE: browser_open and browser_go must have been called first.

USE CASES:

  • Extract CSRF tokens: 'document.querySelector("meta[name=csrf-token]").content'

  • Read cookies: 'document.cookie'

  • Hook fetch API to monitor requests

  • Inspect JavaScript objects and prototypes

  • Test DOM-based XSS payloads

  • Call internal JavaScript functions

The expression is evaluated in the page's JS context — it has full access to the page's DOM, variables, functions, and APIs.

Args: expression: JavaScript code to evaluate. Can be a single expression or multi-line code. Example: 'document.title' or 'fetch("/api/me").then(r=>r.json())' session_name: Browser session to use (default: "default")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tab_idNo
expressionYes
session_nameNodefault

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior4/5

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

With no annotations, the description carries the full disclosure burden. It clearly explains that execution happens in the page's JS context with full access to DOM, variables, functions, and APIs, and that it returns the expression's result. It does not mention potential side effects of arbitrary JS (e.g., page navigation, state mutation) or error behavior, but the inherent nature of arbitrary execution plus the provided context gives reasonable transparency.

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 well-structured with clear headings (PREREQUISITE, USE CASES, Args). Every part adds value: the use cases illustrate practical applications, the prerequisite prevents misuse, and the arg descriptions clarify input semantics. It is concise yet sufficiently detailed without verbose 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?

The description covers prerequisites, use cases, execution context, and return behavior, making it fairly complete for a complex tool. The presence of an output schema reduces the need for return-format details. However, it does not clarify whether promise-returning expressions are awaited (the fetch example returns a promise), and the missing 'tab_id' semantics leave a minor gap.

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 0%, so the description must compensate. It explains 'expression' well with examples and multi-line support, and defines 'session_name' with default. However, it completely omits 'tab_id', one of the three parameters, leaving its semantics and usage unclear. This partial compensation earns a middle score.

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 opens with a specific verb and resource: 'Execute arbitrary JavaScript in the browser page context.' It clearly distinguishes this tool from siblings like browser_get_dom or browser_get_text, which only read specific parts of the page. The 'Returns the expression's result' clause further defines the tool's purpose.

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?

The description explicitly states a prerequisite: browser_open and browser_go must have been called first. It also provides concrete use cases, which help the agent know when to invoke this tool. However, it does not explicitly mention when NOT to use it or point to alternatives such as browser_get_dom for simple DOM reads.

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/BobongKu/nodriver-proxy-mcp'

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