Skip to main content
Glama

run_javascript

Execute arbitrary JavaScript in the active page to handle operations not covered by standard browser automation tools.

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_element, type_text, select_option, hover_action, focus_element, scroll_page, 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

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.15.0

TDQS

A4.9/5.0
Behavior5/5

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

No annotations are provided, so the description carries the full burden, and it does: it discloses the execution channel (CDP Runtime.evaluate in the active page), what the code can reach (DOM APIs, storage, same-origin resources), the escaping behavior for Promises, the return-serialization limits (DOM objects/functions/symbols may not cross the MCP boundary), and a security warning about unrestricted execution. That is a rich behavioral profile well beyond a restated name.

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?

Front-loaded with the verb and the core selection rule, then cleanly sectioned into Tool selection, Args, Returns, and Security. It is longer than strictly necessary — the Security paragraph partially restates the bypass point already made in the opening and tool-selection sections — but every remaining sentence is actionable.

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 single-parameter arbitrary-execution tool with no output schema and no annotations, the definition covers purpose, routing, parameter shape, return serialization, and safety implications. There is nothing an agent needs in order to invoke it correctly that is missing.

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?

Schema description coverage is 0%, so the description must compensate fully and does: it defines 'expression' as an evaluable expression or executable code referencing document/window, and supplies five concrete examples spanning reads, optional chaining, storage access, and a mutation, plus the Promise-return rule. This is more semantic detail than a schema would typically carry.

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 opening sentence states a specific verb and resource ('Evaluate a JavaScript expression in the current page context') and the body clarifies the execution mechanism (CDP Runtime.evaluate) and scope (active page). An agent can distinguish this from every sibling because the description names the exact capability the higher-level tools lack.

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?

Explicit when-to-use ('only when the required browser operation cannot be accomplished through the higher-level SeleniumBase tools') plus a categorized list of alternatives (click_element/type_text for interaction, get_content/find_elements for reading, manage_storage, manage_cookies). The condition that selects this tool over each alternative is spelled out, not inferred.

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