Skip to main content
Glama

在页面执行 JavaScript

eval_js

Execute any JavaScript on a chosen web page and get serialized results, with built-in helpers for deep DOM queries, shadow DOM, iframes, waiting, and dynamic imports.

Instructions

在指定页面(pageId 省略且只连了一页时自动选中)执行任意 JavaScript 并返回序列化结果。支持 await 与多语句;最后一句表达式会被自动 return,也可显式 return。预置 $ / $$(普通查询)、$deep / $$deep(穿 shadow DOM 深度查询)、$import(页面路径动态 import)、$wait(轮询等条件,函数或选择器字符串,第二参为超时 ms)、$frame(同源 iframe 查询辅助,返回 {$,$$,$deep,$$deep,document,window})、$rect(元素几何+可见性)、$css(批量写样式)。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes要执行的 JS 代码
noteNo操作说明:展示给页面用户的自然语言描述(用户会在页面气泡的操作记录里看到),用用户的语言填写,建议始终提供
pageIdNo目标页面 id(可从 list_pages 获取;单页时可省略)
timeoutMsNo超时毫秒数,默认 30000,上限 120000
Behavior4/5

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

无 annotations,描述承担全部行为披露责任。它详细说明了自动选中页面、返回序列化结果、支持 await 与多语句、末句自动 return 或显式 return 等执行语义,并逐个定义了 9 个辅助函数的行为。但未说明 JS 抛错时的处理、超时后的表现,也未提示执行任意 JS 可能带来的页面副作用。

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?

长句但信息密度极高,从目的说明、执行语义到辅助函数清单,几乎无冗余,且核心目的前置。不过辅助函数以逗号连排成长句,缺少分项层级,可读性略受影响;在如此高复杂度的工具下篇幅总体合理。

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?

工具复杂度高(任意 JS 执行、9 个辅助函数、4 个参数),且无 annotations 也无 output schema。描述覆盖了执行语义和辅助函数 API,但未说明返回值封装结构(仅提"序列化结果")、JS 异常与超时行为,也没有副作用警告——对高风险 eval 工具而言这些都是明显缺口。

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 覆盖率为 100%,基线为 3;但描述为 code 参数补充了大量超出 schema(仅"要执行的 JS 代码")的语义:await/多语句规则、自动 return 行为、全部辅助函数的签名与返回值(如 $frame 返回 {$,$$,$deep,$$deep,document,window}),并对 pageId 省略时的自动选中行为做了补充,明显高于基线。

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?

描述以明确的动词+资源开篇:"在指定页面执行任意 JavaScript 并返回序列化结果",准确说明工具做什么。与兄弟工具(click、type、get_text 等)形成清晰区分——这是唯一执行任意脚本的工具,并补充了页面自动选中规则,无歧义、非同义反复。

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?

通过预置辅助函数($wait、$deep、$frame 等)隐含了典型使用场景,schema 中 pageId 也说明可从 list_pages 获取。但描述没有明确说明何时应使用 eval_js 而非 click/get_text 等替代工具,也没有排除条件(如简单交互优先用专用工具),依赖智能体自行推断。

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/kirakiray/web-bridge-mcp'

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