> 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.

# Replay

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



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

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

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

## 概览

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

## Lynx 扩展

### `Replay.end`

Ends TestBench replay by exposing a replay dump file as a stream.

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

###### 参数

| Name     | Type     | Required | Description                                                                                         |
| -------- | -------- | -------- | --------------------------------------------------------------------------------------------------- |
| `params` | `string` | Yes      | File path for the replay dump file. The native handler reads the whole params value as this string. |

###### 返回字段

| Name     | Type     | Description                                                             |
| -------- | -------- | ----------------------------------------------------------------------- |
| `stream` | `string` | FileStream handle returned in the Replay.end message params on success. |

###### 事件

- Replay.end

###### 备注

- Replay support must be enabled in the current runtime. If ReplayController::Enable() is false, the agent returns method not implemented.
- params is a raw string file path, not an object.
- On success, LynxGlobalDevToolMediator opens the file with FileStream::Open() and sends a Replay.end message whose params.stream is the stream handle.
- Read the returned stream handle with IO.read and close it with IO.close.
- If the file path cannot be opened, the method returns a CDP error with message file path doesn't exist.
- If ReplayController::Enable() becomes false inside the mediator task, the method returns a CDP error with message Replay doesn't enable.
- In the internal replay workflow, ReplayController::EndTest() saves collected replay dump data to this file path before notifying DevTool through the same Replay.end message shape.

###### 示例

**End replay and open the dump file**

Request:

```json
{
  "id": 2,
  "method": "Replay.end",
  "params": "/tmp/lynx-replay-dump.json"
}
```

Response:

```json
{
  "method": "Replay.end",
  "params": {
    "stream": "1"
  }
}
```

### `Replay.start`

Starts TestBench replay collection for the current Lynx page.

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

###### 参数

无参数。

###### 返回字段

无返回字段。

###### 备注

- Replay support must be enabled in the current runtime. If ReplayController::Enable() is false, the agent returns method not implemented.
- Dispatches through LynxGlobalDevToolMediator and starts ReplayController::StartTest() on the UI task runner.
- Returns an empty result object on success.
- Returns a CDP error with message Cannot find ui task runner when no UI task runner is available.

###### 示例

**Start replay collection**

Request:

```json
{
  "id": 1,
  "method": "Replay.start"
}
```

Response:

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

