Skip to main content
Glama

执行脚本

web_evaluate

Execute JavaScript in the live page context and get back the result. Supports functions, expressions, and statements to read page data, modify content, or trigger actions.

Instructions

在页面上下文中执行 JavaScript 并返回结果。支持三种形态:函数表达式(function / async function / 箭头函数,以 arg 为参数调用并返回其返回值);表达式(返回求值结果);语句序列(let/var 多语句,返回最后一个表达式的值;含函数声明的语句序列按副作用执行,不返回结果,如需返回值请改用块箭头函数 + return)。返回值为 JSON 安全结构(undefined→null,循环引用→[Circular],NaN/Infinity→字符串,超长内容截断)。异步逻辑请使用 async 函数形态。

权限说明:高危操作:在页面内执行任意 JavaScript,可读取/修改页面数据、发起网络请求、获取 cookie 与登录态。仅在信任的页面上使用。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argNo传给函数形态脚本的参数(任意 JSON 值)
scriptYes要执行的 JavaScript(函数表达式 / 语句序列 / 表达式)
Behavior5/5

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

无注解,描述承担全部行为披露责任。完整说明返回值序列化规则(undefined→null、循环引用→[Circular]、NaN/Infinity→字符串、超长截断)、语句序列中函数声明不返回结果的特殊行为,以及高危权限(可读 cookie、登录态、发起网络请求)。

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?

描述虽然较长,但每一句都承载必要信息:形态区分、返回值处理、异步建议、安全警告。结构清晰,先功能后细节,无冗余或重复内容。

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?

对于执行任意 JS 的高复杂工具,描述覆盖了输入形式、返回值转换、异步处理、权限风险等关键方面。虽无输出 schema,但返回值行为的说明已足够Agent判断预期结果。

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 已覆盖两个参数且描述完整,但工具描述进一步补充了 arg 仅用于函数形态并作为参数传递,以及 script 可接受函数/表达式/语句序列三种形式,赋予参数更丰富的语义,超越 schema 本身。

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 并返回结果”,动词+资源+作用域清晰,与所有兄弟工具(如点击、填写、滚动)形成明确区分,不存在歧义。

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?

详细说明三种脚本形态(函数表达式、表达式、语句序列)及各自适用场景,并提示异步逻辑应使用 async 函数。虽未显式对比替代工具,但兄弟工具皆为页面交互操作,隐含了本工具的独特用途;安全警告也给出了使用前提。

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/JohnXu22786/browser-automation'

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