Skip to main content
Glama

run_javascript

Execute arbitrary JavaScript in the active page to handle operations not covered by standard automation tools, including DOM access, storage reads, and dynamic page manipulation.

Instructions

Evaluate a JavaScript expression in the current page context.

Use this only when the required browser operation cannot be accomplished through the higher-level SeleniumBase tools.

The expression is evaluated through Chrome DevTools Protocol Runtime.evaluate in the currently active page. It executes with access to the page's JavaScript context, including DOM APIs, browser storage, and other same-origin page resources available to JavaScript.

Tool selection: - Prefer click, type_text, select_option, hover_with_action, focus_on, scroll, and other higher-level tools for normal browser interactions. - Prefer get_content, get_attributes, and find_elements for reading page content or element information. - Prefer manage_storage for ordinary localStorage/sessionStorage reads and writes. - Prefer manage_cookies for browser cookie operations. - Use this tool when a required operation needs arbitrary JavaScript that the higher-level tools do not expose.

Args: expression: A JavaScript expression or executable JavaScript code evaluated in the current page. It may reference standard browser globals such as document and window and may use DOM APIs.

    Examples:
        - "document.title"
        - "document.querySelector('button')?.textContent"
        - "localStorage.getItem('theme')"
        - "document.body.classList.contains('dark')"
        - "document.querySelector('#slider').value = '50'"

    The expression should produce a value when a result is needed.
    JavaScript that returns a Promise is supported and its resolved
    value is returned.

Returns: The JavaScript evaluation result when it can be serialized and returned across the MCP boundary. Primitive values, arrays, plain objects, and null are generally suitable return values. DOM objects, functions, symbols, and other non-serializable JavaScript values may not be returned directly; extract the needed property or convert the value to a serializable form first.

Security: This provides unrestricted JavaScript execution in the current browser page. It can read or modify page data and interact with the page in ways that bypass the higher-level tool abstractions. Only expose this MCP server to trusted clients.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYes
Install Server

TDQS

A5/5.0
Behavior5/5

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

Even though no annotations are provided, the description discloses execution via Chrome DevTools Protocol Runtime.evaluate, access to the page's JavaScript context, Promises support, serialization limitations for return values, and unrestricted security implications. It clearly states that this tool can read or modify page data and bypass higher-level abstractions, giving the agent a complete behavioral picture.

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 long but every section earns its place: purpose, tool-selection guidance, argument semantics, return behavior, and security warning. It is well-structured with clear headers and front-loaded with the core usage constraint. No filler or redundant marketing language is present.

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?

Given the tool's high complexity, minimal schema, no annotations, and no output schema, the description is remarkably complete. It covers execution context, supported input forms, return serialization, Promise resolution, and security risk. An agent has enough information to decide when to invoke it and to craft a correct expression.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema only provides the parameter name 'expression' with zero description coverage, so the description carries the full burden. It thoroughly explains what the expression may reference, gives multiple concrete examples, notes that Promises are supported, and clarifies that the expression should produce a serializable value when a result is needed. This far exceeds what the schema alone 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?

The description clearly states a specific verb and resource: 'Evaluate a JavaScript expression in the current page context.' It also distinguishes itself from the higher-level sibling tools by framing itself as the low-level arbitrary-JavaScript fallback. This makes its purpose unambiguous and differentiable.

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 explicitly says to use this only when higher-level SeleniumBase tools cannot accomplish the operation. It then lists preferred tools for specific categories such as click, type_text, get_content, manage_storage, and manage_cookies, and finally states the condition for using this tool. This is exemplary when-to-use guidance.

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

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/seleniumbase/SeleniumBase'

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