Skip to main content
Glama

execute_js

Destructive

Run custom JavaScript in a live browser tab to trigger side effects, control dialogs, and retrieve results with explicit session and timeout handling.

Instructions

Execute arbitrary JS, which can cause side effects, in session_id's browser tab under one total deadline. Pin an explicit session_id; fallbacks keep that target and never replay an already-started script. For complex async bodies use an explicit return in an async IIFE. accept/dismiss prepare current injectable frames on extension routes; the legacy CDP fallback covers only its current evaluation context. manual keeps native dialogs. wait=false returns operation_id after delivery acknowledgement; collect with get_execute_js_result in the same MCP session, without replay. partial/unknown results or an expired handle do not prove non-execution; inspect retry_safe before retrying. A dispatched exec_timeout retains an outcome_unknown reservation for the bounded recovery window; the deadline does not cancel page JS. Use wait_for/wait_for_url for page state instead of sleep Promises. Conversion on all routes: undefined/non-finite numbers become null; BigInt/symbol become strings; DOM/Error/functions become readable values; cycles/depth 6/iterables above 200 items have markers. JSON UTF-8 over 24 KiB or any unpaired UTF-16 uses a private JSON result_file with result_bytes, result_sha256, result_format and result_file_scope=js-value. result_file_encoding=json means JSON-decode the path once; otherwise use it directly. Parse the UTF-8 file once; it preserves the full converted value and markers. If file writing fails, parse the complete ASCII result_json once (result_json_scope=js-value); this fallback may exceed the inline limit and preserves original result/retry verdicts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
waitNo
scriptYes
timeoutNo
no_monitorNo
session_idNo
dialog_policyNodismiss

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.5.4
    • addedInput schema / properties / wait
      Added value: +{
      +  "default": true,
      +  "title": "Wait",
      +  "type": "boolean"
      +}
  2. First observedv0.1.0

TDQS

A4.4/5.0
Behavior5/5

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

Despite the annotations already declaring readOnlyHint=false and destructiveHint=true, the description adds a wealth of beyond-annotation disclosure: side effects, replay prevention, timeout semantics, result invalidation, retry conditions, and conversion/result-delivery behavior. It fully warns the agent about consequences such as non-cancellation of page JS on timeout and the outcome_unknown window.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single dense paragraph that packs many distinct concerns into a long run-on structure. It is genuinely rich and mostly every sentence earns its place, but the overwhelming length and lack of section breaks make it harder to scan and reduce cognitive load for an agent. Some details about result_file encoding and retries could be reorganized into bullet-like clauses.

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?

This is an extremely complex tool with six parameters, no schema descriptions, annotations that are broad, and an output schema that is declared but not available here. The description covers purpose, side effects, async behavior, result retrieval, timeout semantics, dialog policies, persistence of result output, fallback paths, and retry warnings. It is almost complete, yet it leaves 'no_monitor' undocumented and could benefit from explicitly naming each input parameter.

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?

The schema descriptions are at 0% coverage, so the description must compensate. It adds semantic value to session_id, wait, timeout, dialog_policy, and the script body—e.g. wait=false returning an operation_id and the type of conversion behavior. However, it never mentions the parameter 'no_monitor' at all, and the timeout is only approached indirectly via 'deadline', leaving some meaning implicit.

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—'Execute arbitrary JS, which can cause side effects, in session_id's browser tab under one total deadline'—names a specific verb, resource, and key constraint. It clearly distinguishes this tool from siblings like get_execute_js_result and cdp_command: this tool executes JavaScript in the browser context, not just commands or result retrieval.

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?

It provides explicit guidance on when to use wait_for/wait_for_url instead of sleep Promises, and explains how to collect the result with get_execute_js_result when wait=false. It does not explicitly state when not to use execute_js as opposed to specific alternative tools like cdp_command, but the purpose and fallback rules are clear enough for most use cases.

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