Skip to main content
Glama

execute_js

Run JavaScript in the active browser tab to inspect or modify page content. Use a return statement for results, or set preset='dom_tree' to output the DOM structure tree.

Instructions

在当前 tab 执行 JavaScript 代码。⚠️ 必须使用 return 语句返回结果。preset='dom_tree' 时 code 改为传 JSON 参数对象 {"max_depth":5,"include_text":true,"max_text_length":50,"selector":null},直接输出 DOM 结构树。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes要执行的 JavaScript 代码(必须用 return 返回结果!),或 preset='dom_tree' 时的 JSON 参数
presetNo预置脚本模板:dom_tree=DOM 结构树(免写模板 JS)
timeoutNo本次 JS 执行超时(秒,可选)。默认 150 秒。

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.2.1

TDQS

A3.5/5.0
Behavior3/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. It discloses the critical behavioral rule that the code must use return to produce a result, plus the default 150s timeout. It does not cover error behavior, sandbox/permission constraints, or what happens when the script throws, leaving meaningful gaps for a code-execution tool.

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?

Compact and front-loaded: the core action comes first, then the return-value warning, then the preset override. No filler sentences, though the preset paragraph is dense and could be slightly tightened.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no annotations and no output schema, the description must explain the return contract, which it partially does via the return-statement warning. However, it is silent on error handling, result serialization, and side effects, which matter for an arbitrary JS execution tool.

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?

Schema coverage is 100% and each parameter is already documented, so baseline would be 3. The description adds value beyond the schema by showing the exact JSON argument shape for preset='dom_tree' with concrete keys (max_depth, include_text, max_text_length, selector), clarifying how the overloaded 'code' parameter behaves.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: execute JavaScript code in the current tab, and clarifies a second mode (preset='dom_tree') that changes what 'code' means. It does not name or contrast with siblings like run_cdp or run_drission_code, so an agent must infer which execution tool to pick.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives the condition for the dom_tree preset (pass JSON params instead of code), which is useful usage guidance, but it never says when to prefer this tool over run_cdp or run_drission_code, nor any exclusions or prerequisites.

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