Skip to main content
Glama

execute_js

Execute JavaScript in the page context to read or modify the DOM, with optional hover before script and settle delay for reactive frameworks. Use when standard browser actions are insufficient.

Instructions

Execute arbitrary JavaScript in the page context and return the evaluation result. The script runs synchronously in the browser's main frame with full access to the DOM, window, and page APIs. Use as a last resort when CSS selectors and other tools cannot achieve the interaction — prefer click, fill_form, and select_option for standard interactions. Optionally accepts hover_selector to hover over an element before executing the script, enabling inspection of CSS :hover styles and hover-triggered DOM changes. When the script triggers reactive DOM changes (e.g., .click() on a toggle), the return value may reflect pre-mutation state because frameworks schedule updates asynchronously. Set settle_ms (e.g., 50) to wait for reactivity to flush before capturing the result.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute in the page context. The return value of the last expression is serialized as JSON and returned. For async operations, use 'await' (the script is wrapped in an async function). Example: "document.title" or "await fetch('/api/data').then(r => r.json())".
settle_msNoMilliseconds to wait after script execution before capturing the return value (max 5000). Use when the script triggers DOM mutations that a reactive framework (Vue, React, etc.) processes asynchronously — a value of 50-100ms allows framework reactivity to flush before reading state. Default: 0 (no delay).
hover_selectorNoOptional CSS selector or @eN ref (from page_map) of an element to hover over BEFORE executing the script. When provided, the mouse is moved over the element (triggering :hover CSS pseudo-class), then the script is evaluated. This allows inspecting hover-dependent computed styles (e.g. getComputedStyle(el).color after hover) or verifying hover-triggered DOM changes.
Behavior5/5

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

Discloses that the script runs synchronously in the browser's main frame with full DOM/API access, and that return values may reflect pre-mutation state due to async framework updates. Suggests settle_ms to wait for reactivity. With no annotations provided, the description fully covers behavioral traits.

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?

Two well-organized paragraphs: first covers main function and usage guideline, second details optional parameters. Every sentence adds value, no redundancy.

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 three parameters, no output schema, and moderate complexity, the description is complete. It covers all parameters with purpose and behavior, explains return value serialization, and addresses common pitfalls (async reactivity). No gaps.

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?

Adds significant meaning beyond the schema: explains that script's last expression is JSON-serialized, supports async with await, specifies settle_ms defaults and max, and clarifies how hover_selector works (hovers before execution, useful for inspecting :hover styles). Schema coverage is 100% but description enhances understanding.

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 it executes arbitrary JavaScript in the page context and returns the evaluation result. It distinguishes itself from sibling tools like click, fill_form, and select_option by positioning itself as a last resort for non-standard interactions.

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?

Explicitly advises when to use: 'as a last resort when CSS selectors and other tools cannot achieve the interaction' and directs to prefer click, fill_form, and select_option. Also provides context for optional parameters like hover_selector and settle_ms.

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/Mingye-Lu/AgenticCrawler'

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