# 注入 JS

节点类型 `browser_injectJavaScript`

## 功能说明

在当前网页上下文执行 JavaScript，用于访问页面文档。

## 客户端配置界面

![注入 JS节点的客户端配置界面](/assets/inject-java-script.9c689498b6dcffb8a7b14e78bafdda313c402532c0e264f664dff533253a499a.0538f3a9.webp)

截图来自 MoreLogin 桌面客户端 V2.73.101 的英文界面。

## 输入字段

以下字段位于 `data.browserUi.inputs`。

| 字段 | 类型或取值 | Schema 必填 | 执行默认值 | 说明与边界 |
|  --- | --- | --- | --- | --- |
| `params` | array<`object`> | 否 | `[]` | params 编辑器初值 `[]` |
| `content` | `string` | 否 | — | 注入脚本 |
| `outputFormat` | `object`（支持变量引用） | 否 | `{"type":"object"}` | 输出格式 编辑器初值 `{"type":"object"}` |
| `executionTimeoutMs` | `WorkflowNumber` | 否 | `3000` | 执行超时（毫秒）; minimum after resolution: 100; maximum after resolution: 30000 编辑器初值 `3000` |


## 条件与边界

- 仅接受输入脚本，通过 params 显式传值，类型为 object/array 的常量参数必须是合法的 JSON 对象/数组（写入时校验）；在真实页面异步执行，执行超时 100–30000ms。
- 校验错误码 `RPA_NODE_INPUT_INVALID`


## 输入引用

| 字段 | 允许的形式 |
|  --- | --- |
| `params` | `literal`, `template` |
| `content` | `literal`, `template` |
| `outputFormat` | `literal`, `template` |
| `executionTimeoutMs` | `literal`, `numericExpression` |


## 输出字段

| 输出字段 | 类型或取值 |
|  --- | --- |
| `result` | `["null","boolean","number","string"]` / array<`JSON`> / `object` |
| `injected` | `true` |


按契约用 `${nodeId.data.field}` 引用公开字段。

## JSON 示例

可放入流程 `nodes` 数组或其他节点 `blocks` 中的完整节点对象。

```json
{
  "id": "page_info",
  "type": "browser_injectJavaScript",
  "data": {
    "title": "读取页面标题和链接数量",
    "browserAction": "injectJavaScript",
    "browserUi": {
      "inputs": {
        "params": [],
        "content": "return { title: document.title, links: document.links.length };",
        "outputFormat": {
          "type": "object"
        },
        "executionTimeoutMs": 3000
      },
      "exception": {
        "timeout": 30000,
        "policy": "interrupt"
      }
    }
  }
}
```

[返回节点目录](/zh/browser-rpa/nodes)