> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# Template

本页面介绍 Lynx DevTool 支持的 `Template` CDP domain。



:::warning 实验性参考
此生成的参考文档仍在完善中。

- CDP events 尚未包含。
- 部分 Lynx 扩展已列出，但尚未提供详细文档。
- 方法说明尚未根据实现自动校验，可能不完整或不准确。

在依赖本参考前，请根据实现及所链接的 upstream CDP reference 验证实际行为。
:::

## 概览

- 作用域：`instance`
- CDP domain：Lynx 专有

## Lynx 扩展

### `Template.getTemplateJs`

Returns a base64-encoded slice of saved template binary bytes.

- Origin: `lynx-extension`
- Source: `devtool/lynx_devtool/agent/domain_agent/inspector_template_agent.cc`

###### 参数

| Name     | Type      | Required | Description                                                                                                                              |
| -------- | --------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `offset` | `integer` | Yes      | Byte offset into the saved template binary. Constraints: minimum 0.                                                                      |
| `size`   | `integer` | Yes      | Maximum number of bytes to read. Platform implementations may clamp this value to the available template length. Constraints: minimum 0. |

###### 返回字段

| Name   | Type     | Description                                                                                                                                                                       |
| ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data` | `string` | Base64-encoded template bytes for the requested range. Empty when no template bytes are available, offset is outside the saved template, or the platform delegate is unavailable. |

###### 备注

- Dispatches through LynxDevToolMediator to InspectorUIExecutor on the UI thread.
- params.offset and params.size are required. If either field is missing, the method returns a CDP error with message Params must have offset and size properties.
- The native executor reads offset and size as unsigned integers; callers should pass non-negative integers.
- Android returns a base64 slice from the saved binary template data or the bytes captured after a URL template load. The slice length is clamped to the remaining template bytes.
- The generic embedder implementation returns an empty data string.

###### 示例

**Read a template byte range**

Request:

```json
{
  "id": 1,
  "method": "Template.getTemplateJs",
  "params": {
    "offset": 0,
    "size": 4096
  }
}
```

Response:

```json
{
  "id": 1,
  "result": {
    "data": "AAECAw=="
  }
}
```

### `Template.templateApi`

Reports template data processor API information for the current template.

- Origin: `lynx-extension`
- Source: `devtool/lynx_devtool/agent/domain_agent/inspector_template_agent.cc`

###### 参数

无参数。

###### 返回字段

| Name             | Type      | Description                                                                                        |
| ---------------- | --------- | -------------------------------------------------------------------------------------------------- |
| `useDefault`     | `boolean` | Whether the current template has a default data processor closure.                                 |
| `processMapKeys` | `array`   | Names of registered data processor entries. This field is omitted when the processor map is empty. |

###### 备注

- Dispatches through LynxDevToolMediator to InspectorTasmExecutor on the TASM thread.
- When TASM is unavailable, the result reports useDefault as false.

###### 示例

**Get template processor API info**

Request:

```json
{
  "id": 1,
  "method": "Template.templateApi"
}
```

Response:

```json
{
  "id": 1,
  "result": {
    "useDefault": true,
    "processMapKeys": ["main"]
  }
}
```

### `Template.templateConfigInfo`

Compatibility method for removed template config info support.

- Origin: `lynx-extension`
- Source: `devtool/lynx_devtool/agent/domain_agent/inspector_template_agent.cc`

###### 参数

无参数。

###### 返回字段

| Name     | Type     | Description             |
| -------- | -------- | ----------------------- |
| `result` | `string` | Always an empty string. |

###### 备注

- This method does not call the mediator or platform facade.
- The response result is an empty string, not an object, because config info support was removed.

###### 示例

**Get removed template config info**

Request:

```json
{
  "id": 1,
  "method": "Template.templateConfigInfo"
}
```

Response:

```json
{
  "id": 1,
  "result": ""
}
```

### `Template.templateData`

Returns the current initial template data exposed by the platform facade.

- Origin: `lynx-extension`
- Source: `devtool/lynx_devtool/agent/domain_agent/inspector_template_agent.cc`

###### 参数

无参数。

###### 返回字段

| Name      | Type     | Description                                                                                                                                                  |
| --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `content` | `string` | Serialized template data produced from the platform Lepus value. This field is present only when the platform facade returns a non-null template data value. |

###### 备注

- Dispatches through LynxDevToolMediator to InspectorUIExecutor on the UI thread.
- Android reads the saved initial TemplateData pointer from the platform reload helper; Darwin delegates to the platform implementation.
- If the platform facade has no template data value, the result object is returned without content.

###### 示例

**Get current template data**

Request:

```json
{
  "id": 1,
  "method": "Template.templateData"
}
```

Response:

```json
{
  "id": 1,
  "result": {
    "content": "{\"title\":\"hello\"}"
  }
}
```

