@loom-framework/core 0.1.0-alpha.191 → 0.1.0-alpha.195
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builtin-skills/app-skill/references/models.md +2 -0
- package/builtin-skills/app-skill/references/process-recovery.md +222 -0
- package/builtin-skills/playwright-cli/SKILL.md +282 -0
- package/builtin-skills/playwright-cli/references/request-mocking.md +87 -0
- package/builtin-skills/playwright-cli/references/running-code.md +232 -0
- package/builtin-skills/playwright-cli/references/session-management.md +169 -0
- package/builtin-skills/playwright-cli/references/storage-state.md +275 -0
- package/builtin-skills/playwright-cli/references/test-generation.md +88 -0
- package/builtin-skills/playwright-cli/references/tracing.md +139 -0
- package/builtin-skills/playwright-cli/references/video-recording.md +43 -0
- package/dist/backend/process/engine.d.ts +4 -0
- package/dist/backend/process/engine.d.ts.map +1 -1
- package/dist/backend/process/engine.js +16 -0
- package/dist/backend/process/engine.js.map +1 -1
- package/dist/backend/process/process-helpers.d.ts +6 -2
- package/dist/backend/process/process-helpers.d.ts.map +1 -1
- package/dist/backend/process/process-helpers.js +10 -2
- package/dist/backend/process/process-helpers.js.map +1 -1
- package/dist/backend/routes/process-routes.d.ts.map +1 -1
- package/dist/backend/routes/process-routes.js +40 -2
- package/dist/backend/routes/process-routes.js.map +1 -1
- package/dist/cli/commands/process.d.ts.map +1 -1
- package/dist/cli/commands/process.js +11 -2
- package/dist/cli/commands/process.js.map +1 -1
- package/dist/cli/generators/capability-generator.d.ts.map +1 -1
- package/dist/cli/generators/capability-generator.js +10 -7
- package/dist/cli/generators/capability-generator.js.map +1 -1
- package/dist/cli/templates/event-management-page.d.ts +1 -1
- package/dist/cli/templates/event-management-page.js +1 -1
- package/dist/cli/templates/login-page.d.ts +1 -1
- package/dist/cli/templates/login-page.js +1 -1
- package/dist/cli/templates/model-management-page.d.ts +1 -1
- package/dist/cli/templates/model-management-page.js +1 -1
- package/dist/cli/templates/notification-center-page.d.ts +1 -1
- package/dist/cli/templates/notification-center-page.js +1 -1
- package/dist/cli/templates/notification-detail-page.d.ts +1 -1
- package/dist/cli/templates/notification-detail-page.js +1 -1
- package/dist/cli/templates/process-management-page.d.ts +1 -1
- package/dist/cli/templates/process-management-page.js +1 -1
- package/dist/cli/templates/skill-management-page.d.ts +1 -1
- package/dist/cli/templates/skill-management-page.js +1 -1
- package/dist/cli/templates/user-management-page.d.ts +1 -1
- package/dist/cli/templates/user-management-page.js +1 -1
- package/package.json +1 -1
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
| 语法 | 示例 | 说明 |
|
|
30
30
|
|------|------|------|
|
|
31
31
|
| 等值匹配 | `{"subject":"数学"}` | 字段等于指定值 |
|
|
32
|
+
| IN 数组匹配 | `{"subject":["数学","英语"]}` | 字段匹配数组中任一值 |
|
|
32
33
|
| 多条件 AND | `{"subject":"数学","difficulty":"困难"}` | 多字段同时匹配 |
|
|
33
34
|
| 范围查询 | `{"createdAt":{"__range":["2026-03-01","2026-03-31"]}}` | 闭区间,包含两端点 |
|
|
35
|
+
| 开放上界 | `{"createdAt":{"__range":["2026-05-21","9999-12-31"]}}` | 实现大于等于(≥),上界设为远未来日期 |
|
|
34
36
|
|
|
35
37
|
**注意**:不支持 `$gte`、`$gt`、`$lte`、`$lt`、`>=`、`<` 等比较操作符,使用不支持的语法不会报错但返回空结果。范围查询必须使用 `__range`。
|
|
36
38
|
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# Process 恢复指南
|
|
2
|
+
|
|
3
|
+
## 目的
|
|
4
|
+
|
|
5
|
+
当 Loom 实例因停机(电脑关机、服务重启等)错过 Feeder 消息或 cron 执行时,AI 助手使用本指南帮用户恢复遗漏的数据和补跑错过的定时任务。
|
|
6
|
+
|
|
7
|
+
## 触发场景
|
|
8
|
+
|
|
9
|
+
用户可能这样说:
|
|
10
|
+
- "补一下过去4小时的消息"
|
|
11
|
+
- "我昨天下班后到今早的消息没收到,恢复一下"
|
|
12
|
+
- "从昨晚10点到今天早上9点的消息补回来"
|
|
13
|
+
- "看看有没有定时任务漏跑了"
|
|
14
|
+
|
|
15
|
+
## 前提条件
|
|
16
|
+
|
|
17
|
+
恢复操作依赖以下数据模型字段(如果模型没有这些字段,告知用户先添加):
|
|
18
|
+
|
|
19
|
+
| 字段 | 类型 | 用途 |
|
|
20
|
+
|------|------|------|
|
|
21
|
+
| `messageId` | string | 消息唯一 ID(去重键),从 `rawData.mid` 或 `rawData.msgId` 提取 |
|
|
22
|
+
| `conversation` | string | 会话(会话名+会话ID),格式如 `"AntDingCli测试群1(73408370409)"`,从 `rawData.group` 或 `rawData.groupName+groupId` 拼接,单聊用 `rawData._conversationTitle` |
|
|
23
|
+
|
|
24
|
+
如果当前模型缺少这些字段,需要在 `loom.config.ts` 的对应模型 fields 中添加:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
{ name: 'messageId', type: 'string', description: { 'zh-CN': '消息ID(去重键)', 'en-US': 'Message ID (dedup key)' } },
|
|
28
|
+
{ name: 'conversation', type: 'string', description: { 'zh-CN': '会话(会话名+会话ID)', 'en-US': 'Conversation (name + ID)' } },
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 恢复流程
|
|
32
|
+
|
|
33
|
+
### 第一步:确定时间窗口
|
|
34
|
+
|
|
35
|
+
用户指定时间范围,格式灵活:
|
|
36
|
+
- 相对时间:"过去4小时" → `--from 4h`
|
|
37
|
+
- 绝对时间:"昨晚10点到今早9点" → `--from "2026-05-20 22:00" --to "2026-05-21 09:00"`
|
|
38
|
+
- 日期:"昨天一整天" → `--from 1d --to 0d`
|
|
39
|
+
|
|
40
|
+
将用户意图转换为 `antding history` 的 `--from` / `--to` 参数。`--from` 和 `--to` 支持:
|
|
41
|
+
- `YYYY-MM-DD`(天级)
|
|
42
|
+
- `YYYY-MM-DD HH:MM`(分钟级)
|
|
43
|
+
- `Nd` / `Nh` / `Nm`(相对时间)
|
|
44
|
+
- Unix 时间戳(秒级)
|
|
45
|
+
|
|
46
|
+
### 第二步:确定会话列表
|
|
47
|
+
|
|
48
|
+
从当前实例的 Process 配置中提取监控的会话。查看各 Process 的 source 脚本中的 `--cid` 参数:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
loom process list
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
从输出中找到所有 Feeder 的 `--cid` 参数,收集去重后的 CID 列表。
|
|
55
|
+
|
|
56
|
+
用户也可以**额外指定**不在 Feeder 监控范围内的会话:
|
|
57
|
+
- "也把岳立那个聊天的补一下" → 用 `antding list` 查找 CID
|
|
58
|
+
|
|
59
|
+
### 第三步:查已有消息确定 gap
|
|
60
|
+
|
|
61
|
+
查询 inbox 在目标时间窗口内已有哪些消息,用于后续去重:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 日级范围查询(推荐,避免时间格式不一致问题)
|
|
65
|
+
loom data read <inbox_model> --filter '{"createdAt":{"__range":["2026-05-20","2026-05-21"]}}' --limit 200
|
|
66
|
+
|
|
67
|
+
# 按 conversation 分组查看(等值匹配会话名+ID)
|
|
68
|
+
loom data read <inbox_model> --filter '{"conversation":"AntDingCli测试群1(73408370409)"}' --limit 100
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**filter 语法注意**:Loom 只支持三种 filter 操作符:
|
|
72
|
+
- 等值匹配:`{"status":"pending"}`
|
|
73
|
+
- IN 数组:`{"status":["pending","dispatched"]}`
|
|
74
|
+
- 范围查询(闭区间):`{"createdAt":{"__range":["2026-05-20","2026-05-21"]}}`
|
|
75
|
+
- 不支持 `_gte`、`_lte` 等操作符;实现"大于等于"用 `{"createdAt":{"__range":["2026-05-21","9999-12-31"]}}`
|
|
76
|
+
|
|
77
|
+
### 第四步:逐会话拉取遗漏消息
|
|
78
|
+
|
|
79
|
+
对每个 CID 执行 `antding history`:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# 优先 --hybrid(本地优先,远程补充)
|
|
83
|
+
antding history -c <CID> --from "<开始时间>" --to "<结束时间>" --limit 50 --format json --hybrid
|
|
84
|
+
|
|
85
|
+
# 如果 hybrid 失败或超时,回退到 --local
|
|
86
|
+
antding history -c <CID> --from "<开始时间>" --to "<结束时间>" --limit 50 --format json --local
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**关键参数**:
|
|
90
|
+
- `--limit`:默认只有 10 条,恢复场景必须显式设大(建议 50-100)
|
|
91
|
+
- `--format json`:返回结构化数据,每条消息含 `messageId`、`conversationId`、`senderId`、`createdAtMsec` 等(注意:`conversationId` 是 antding 返回的原始 CID,写入 inbox 时需拼接为 `会话名(CID)` 格式存入 `conversation` 字段)
|
|
92
|
+
- `--hybrid`:本地数据库优先,覆盖不到的时间段自动从服务端拉取
|
|
93
|
+
- `--local`:纯离线,不依赖 daemon,但只包含本地缓存的消息
|
|
94
|
+
- `--timeout`:默认 20 秒,大量消息时可能需要加大
|
|
95
|
+
|
|
96
|
+
**注意**:`antding history` 一次只支持一个 CID,需要逐个会话查询。
|
|
97
|
+
|
|
98
|
+
消息量过大时(>100条/会话)分批处理:
|
|
99
|
+
1. 首次 `--limit 50`
|
|
100
|
+
2. 如果返回满 50 条,用最早一条的 `createdAtMsec` 作为新的 `--to`,继续拉取
|
|
101
|
+
3. 重复直到返回不足 50 条
|
|
102
|
+
4. 批间适当等待,避免 daemon 压力
|
|
103
|
+
|
|
104
|
+
### 第五步:去重并写入
|
|
105
|
+
|
|
106
|
+
对每条拉取到的消息:
|
|
107
|
+
|
|
108
|
+
**5a. 提取 messageId 和 conversation**
|
|
109
|
+
|
|
110
|
+
从 `antding history --format json` 返回的消息结构中:
|
|
111
|
+
- `messageId` → 消息唯一标识(字符串,如 `"26084289099968"`)
|
|
112
|
+
- `conversationId` → 会话 CID(如 `"73408370409"` 或 `"997642:1388075"`),需拼接为 `会话名(CID)` 存入 `conversation` 字段
|
|
113
|
+
- `_conversationTitle` → 会话名(如 `"AntDingCli测试群1"`、`"岳立"`),与 CID 拼接后写入 `conversation`
|
|
114
|
+
- `senderId` → 发送者 UID
|
|
115
|
+
- `createdAt` / `createdAtMsec` → 消息时间
|
|
116
|
+
- `messageContent` → 消息内容(结构体,含 `text`、`contentType` 等)
|
|
117
|
+
|
|
118
|
+
**5b. 去重检查**
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
loom data read <inbox_model> --filter '{"messageId":"<messageId>"}'
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
如果返回非空(total > 0),说明该消息已存在,跳过。计数 `skipped++`。
|
|
125
|
+
|
|
126
|
+
**5c. 写入 inbox**
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
loom data write <inbox_model> --data '{
|
|
130
|
+
"source": "dingtalk",
|
|
131
|
+
"sender": "<senderName>(<senderId>)",
|
|
132
|
+
"content": "<提取的文本内容>",
|
|
133
|
+
"rawData": <原始消息JSON>,
|
|
134
|
+
"messageId": "<messageId>",
|
|
135
|
+
"conversation": "<会话名(CID)>",
|
|
136
|
+
"status": "pending",
|
|
137
|
+
"traceId": "trace_recovery_<messageId>"
|
|
138
|
+
}'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**5d. 触发路由(如果需要)**
|
|
142
|
+
|
|
143
|
+
写入 inbox 后,如需让下游 Process 处理,向 EventBus 注入事件:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
curl -sf -X POST http://localhost:<port>/api/v1/events/emit \
|
|
147
|
+
-H 'Content-Type: application/json' \
|
|
148
|
+
-H "Authorization: Bearer $LOOM_TOKEN" \
|
|
149
|
+
-d '{
|
|
150
|
+
"pattern": "<对应的event pattern>",
|
|
151
|
+
"payload": {
|
|
152
|
+
"msgContent": "<消息内容>",
|
|
153
|
+
"messageId": "<messageId>",
|
|
154
|
+
"recovered": true,
|
|
155
|
+
"recoveryWindow": "<开始时间> ~ <结束时间>"
|
|
156
|
+
},
|
|
157
|
+
"source": "cli"
|
|
158
|
+
}'
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`source` 只允许 `server`、`cli`、`feeder` 三个值。
|
|
162
|
+
|
|
163
|
+
事件 pattern 根据消息来源确定——参考各 Process 的事件订阅配置(`loom event list`)。恢复消息统一使用基础 pattern(如 `dingtalk:message`),urgent/mention 的判断交给 ingest Process 重新执行。
|
|
164
|
+
|
|
165
|
+
### 第六步:汇报结果
|
|
166
|
+
|
|
167
|
+
恢复完成后,向用户汇报:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
消息恢复完成:
|
|
171
|
+
- <会话名>(<CID>):<N> 条新消息,<M> 条重复跳过
|
|
172
|
+
- <会话名>(<CID>):该时段无消息
|
|
173
|
+
|
|
174
|
+
合计:恢复 <X> 条,跳过 <Y> 条重复
|
|
175
|
+
所有恢复的消息已写入 inbox,<是否触发EventBus路由>。
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Cron 断档检测
|
|
179
|
+
|
|
180
|
+
用户还可能问"哪些定时任务漏跑了"。检测流程:
|
|
181
|
+
|
|
182
|
+
### 1. 列出有 cron 的 Process
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
loom process list
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
从输出中找到所有有 `cron` 配置的 Process。
|
|
189
|
+
|
|
190
|
+
### 2. 读取执行日志
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
loom process logs <name> --limit 20
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
查看每个 cron Process 的最近执行时间,对比断档窗口内应有的执行次数。
|
|
197
|
+
|
|
198
|
+
### 3. 建议补跑
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
过去 <N> 小时断档,以下定时任务错过了执行:
|
|
202
|
+
|
|
203
|
+
| Process | Cron | 应执行 | 实际执行 | 建议 |
|
|
204
|
+
|---------|------|--------|---------|------|
|
|
205
|
+
| morning-brief | 0 8 * * 1-5 | 1次 | 0次 | 建议补跑 |
|
|
206
|
+
| vuln-remind | 0 9 * * 1-5 | 1次 | 0次 | 建议补跑 |
|
|
207
|
+
|
|
208
|
+
是否要我补跑?执行命令:loom process run <name>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**注意**:不要自动补跑,等用户确认后再执行 `loom process run <name>`。有些定时任务(如已经过期的告警巡检)补跑意义不大,让用户判断。
|
|
212
|
+
|
|
213
|
+
## 边界情况
|
|
214
|
+
|
|
215
|
+
| 场景 | 处理方式 |
|
|
216
|
+
|------|---------|
|
|
217
|
+
| antding daemon 未运行 | `--hybrid` 会失败,自动回退 `--local`;都失败则告知用户启动钉钉后重试 |
|
|
218
|
+
| 消息量过大 | 分批拉取,每次 50 条,向用户说明进度 |
|
|
219
|
+
| short gap(<5分钟断档) | 直接告知"断档时间很短,可能没有遗漏消息",如用户坚持则照常执行 |
|
|
220
|
+
| 去重查询失败 | 保守跳过——宁可少恢复不可重复写入 |
|
|
221
|
+
| 历史消息无法拉取 | `--local` 模式受本地缓存限制,更早的消息可能不可用,告知用户时间范围限制 |
|
|
222
|
+
| conversation 格式 | 统一为 `会话名(CID)` 格式,如 `AntDingCli测试群1(73408370409)` 或 `岳立(997642:1388075)`,与 sender 的 `姓名(UID)` 格式保持一致 |
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: playwright-cli
|
|
3
|
+
description: Automates browser interactions for web testing, form filling, screenshots, and data extraction. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages. This is a low-level tool - for authenticated web fetching, use web-fetch skill instead.
|
|
4
|
+
allowed-tools: Bash(playwright-cli:*)
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Browser Automation with playwright-cli
|
|
8
|
+
|
|
9
|
+
## Quick start
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# open new browser
|
|
13
|
+
playwright-cli open
|
|
14
|
+
# navigate to a page
|
|
15
|
+
playwright-cli goto https://playwright.dev
|
|
16
|
+
# interact with the page using refs from the snapshot
|
|
17
|
+
playwright-cli click e15
|
|
18
|
+
playwright-cli type "page.click"
|
|
19
|
+
playwright-cli press Enter
|
|
20
|
+
# take a screenshot (rarely used, as snapshot is more common)
|
|
21
|
+
playwright-cli screenshot
|
|
22
|
+
# close the browser
|
|
23
|
+
playwright-cli close
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Commands
|
|
27
|
+
|
|
28
|
+
### Core
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
playwright-cli open
|
|
32
|
+
# open and navigate right away
|
|
33
|
+
playwright-cli open https://example.com/
|
|
34
|
+
playwright-cli goto https://playwright.dev
|
|
35
|
+
playwright-cli type "search query"
|
|
36
|
+
playwright-cli click e3
|
|
37
|
+
playwright-cli dblclick e7
|
|
38
|
+
playwright-cli fill e5 "user@example.com"
|
|
39
|
+
playwright-cli drag e2 e8
|
|
40
|
+
playwright-cli hover e4
|
|
41
|
+
playwright-cli select e9 "option-value"
|
|
42
|
+
playwright-cli upload ./document.pdf
|
|
43
|
+
playwright-cli check e12
|
|
44
|
+
playwright-cli uncheck e12
|
|
45
|
+
playwright-cli snapshot
|
|
46
|
+
playwright-cli snapshot --filename=after-click.yaml
|
|
47
|
+
playwright-cli eval "document.title"
|
|
48
|
+
playwright-cli eval "el => el.textContent" e5
|
|
49
|
+
playwright-cli dialog-accept
|
|
50
|
+
playwright-cli dialog-accept "confirmation text"
|
|
51
|
+
playwright-cli dialog-dismiss
|
|
52
|
+
playwright-cli resize 1920 1080
|
|
53
|
+
playwright-cli close
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Navigation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
playwright-cli go-back
|
|
60
|
+
playwright-cli go-forward
|
|
61
|
+
playwright-cli reload
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Keyboard
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
playwright-cli press Enter
|
|
68
|
+
playwright-cli press ArrowDown
|
|
69
|
+
playwright-cli keydown Shift
|
|
70
|
+
playwright-cli keyup Shift
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Mouse
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
playwright-cli mousemove 150 300
|
|
77
|
+
playwright-cli mousedown
|
|
78
|
+
playwright-cli mousedown right
|
|
79
|
+
playwright-cli mouseup
|
|
80
|
+
playwright-cli mouseup right
|
|
81
|
+
playwright-cli mousewheel 0 100
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Save as
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
playwright-cli screenshot
|
|
88
|
+
playwright-cli screenshot e5
|
|
89
|
+
playwright-cli screenshot --filename=page.png
|
|
90
|
+
playwright-cli pdf --filename=page.pdf
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Tabs
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
playwright-cli tab-list
|
|
97
|
+
playwright-cli tab-new
|
|
98
|
+
playwright-cli tab-new https://example.com/page
|
|
99
|
+
playwright-cli tab-close
|
|
100
|
+
playwright-cli tab-close 2
|
|
101
|
+
playwright-cli tab-select 0
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Storage
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
playwright-cli state-save
|
|
108
|
+
playwright-cli state-save auth.json
|
|
109
|
+
playwright-cli state-load auth.json
|
|
110
|
+
|
|
111
|
+
# Cookies
|
|
112
|
+
playwright-cli cookie-list
|
|
113
|
+
playwright-cli cookie-list --domain=example.com
|
|
114
|
+
playwright-cli cookie-get session_id
|
|
115
|
+
playwright-cli cookie-set session_id abc123
|
|
116
|
+
playwright-cli cookie-set session_id abc123 --domain=example.com --httpOnly --secure
|
|
117
|
+
playwright-cli cookie-delete session_id
|
|
118
|
+
playwright-cli cookie-clear
|
|
119
|
+
|
|
120
|
+
# LocalStorage
|
|
121
|
+
playwright-cli localstorage-list
|
|
122
|
+
playwright-cli localstorage-get theme
|
|
123
|
+
playwright-cli localstorage-set theme dark
|
|
124
|
+
playwright-cli localstorage-delete theme
|
|
125
|
+
playwright-cli localstorage-clear
|
|
126
|
+
|
|
127
|
+
# SessionStorage
|
|
128
|
+
playwright-cli sessionstorage-list
|
|
129
|
+
playwright-cli sessionstorage-get step
|
|
130
|
+
playwright-cli sessionstorage-set step 3
|
|
131
|
+
playwright-cli sessionstorage-delete step
|
|
132
|
+
playwright-cli sessionstorage-clear
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Network
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
playwright-cli route "**/*.jpg" --status=404
|
|
139
|
+
playwright-cli route "https://api.example.com/**" --body='{"mock": true}'
|
|
140
|
+
playwright-cli route-list
|
|
141
|
+
playwright-cli unroute "**/*.jpg"
|
|
142
|
+
playwright-cli unroute
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### DevTools
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
playwright-cli console
|
|
149
|
+
playwright-cli console warning
|
|
150
|
+
playwright-cli network
|
|
151
|
+
playwright-cli run-code "async page => await page.context().grantPermissions(['geolocation'])"
|
|
152
|
+
playwright-cli tracing-start
|
|
153
|
+
playwright-cli tracing-stop
|
|
154
|
+
playwright-cli video-start
|
|
155
|
+
playwright-cli video-stop video.webm
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Open parameters
|
|
159
|
+
```bash
|
|
160
|
+
# Use specific browser when creating session
|
|
161
|
+
playwright-cli open --browser=chrome
|
|
162
|
+
playwright-cli open --browser=firefox
|
|
163
|
+
playwright-cli open --browser=webkit
|
|
164
|
+
playwright-cli open --browser=msedge
|
|
165
|
+
# Connect to browser via extension
|
|
166
|
+
playwright-cli open --extension
|
|
167
|
+
|
|
168
|
+
# Use persistent profile (by default profile is in-memory)
|
|
169
|
+
playwright-cli open --persistent
|
|
170
|
+
# Use persistent profile with custom directory
|
|
171
|
+
playwright-cli open --profile=/path/to/profile
|
|
172
|
+
|
|
173
|
+
# Start with config file
|
|
174
|
+
playwright-cli open --config=my-config.json
|
|
175
|
+
|
|
176
|
+
# Close the browser
|
|
177
|
+
playwright-cli close
|
|
178
|
+
# Delete user data for the default session
|
|
179
|
+
playwright-cli delete-data
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Snapshots
|
|
183
|
+
|
|
184
|
+
After each command, playwright-cli provides a snapshot of the current browser state.
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
> playwright-cli goto https://example.com
|
|
188
|
+
### Page
|
|
189
|
+
- Page URL: https://example.com/
|
|
190
|
+
- Page Title: Example Domain
|
|
191
|
+
### Snapshot
|
|
192
|
+
[Snapshot](.playwright-cli/page-2026-02-14T19-22-42-679Z.yml)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
You can also take a snapshot on demand using `playwright-cli snapshot` command.
|
|
196
|
+
|
|
197
|
+
If `--filename` is not provided, a new snapshot file is created with a timestamp. Default to automatic file naming, use `--filename=` when artifact is a part of the workflow result.
|
|
198
|
+
|
|
199
|
+
## Browser Sessions
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
# create new browser session named "mysession" with persistent profile
|
|
203
|
+
playwright-cli -s=mysession open example.com --persistent
|
|
204
|
+
# same with manually specified profile directory (use when requested explicitly)
|
|
205
|
+
playwright-cli -s=mysession open example.com --profile=/path/to/profile
|
|
206
|
+
playwright-cli -s=mysession click e6
|
|
207
|
+
playwright-cli -s=mysession close # stop a named browser
|
|
208
|
+
playwright-cli -s=mysession delete-data # delete user data for persistent session
|
|
209
|
+
|
|
210
|
+
playwright-cli list
|
|
211
|
+
# Close all browsers
|
|
212
|
+
playwright-cli close-all
|
|
213
|
+
# Forcefully kill all browser processes
|
|
214
|
+
playwright-cli kill-all
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Local installation
|
|
218
|
+
|
|
219
|
+
In some cases user might want to install playwright-cli locally. Use `npm install -g @playwright/cli@latest` `playwright-cli --help` to launch. If running globally available `playwright-cli` binary fails, use `npx playwright-cli` to run the commands. For example:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
npx playwright-cli open https://example.com
|
|
223
|
+
npx playwright-cli click e1
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Example: Form submission
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
playwright-cli open https://example.com/form
|
|
230
|
+
playwright-cli snapshot
|
|
231
|
+
|
|
232
|
+
playwright-cli fill e1 "user@example.com"
|
|
233
|
+
playwright-cli fill e2 "password123"
|
|
234
|
+
playwright-cli click e3
|
|
235
|
+
playwright-cli snapshot
|
|
236
|
+
playwright-cli close
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Example: Multi-tab workflow
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
playwright-cli open https://example.com
|
|
243
|
+
playwright-cli tab-new https://example.com/other
|
|
244
|
+
playwright-cli tab-list
|
|
245
|
+
playwright-cli tab-select 0
|
|
246
|
+
playwright-cli snapshot
|
|
247
|
+
playwright-cli close
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Example: Debugging with DevTools
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
playwright-cli open https://example.com
|
|
254
|
+
playwright-cli click e4
|
|
255
|
+
playwright-cli fill e7 "test"
|
|
256
|
+
playwright-cli console
|
|
257
|
+
playwright-cli network
|
|
258
|
+
playwright-cli close
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
playwright-cli open https://example.com
|
|
263
|
+
playwright-cli tracing-start
|
|
264
|
+
playwright-cli click e4
|
|
265
|
+
playwright-cli fill e7 "test"
|
|
266
|
+
playwright-cli tracing-stop
|
|
267
|
+
playwright-cli close
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Specific tasks
|
|
271
|
+
|
|
272
|
+
* **Request mocking** [references/request-mocking.md](references/request-mocking.md)
|
|
273
|
+
* **Running Playwright code** [references/running-code.md](references/running-code.md)
|
|
274
|
+
* **Browser session management** [references/session-management.md](references/session-management.md)
|
|
275
|
+
* **Storage state (cookies, localStorage)** [references/storage-state.md](references/storage-state.md)
|
|
276
|
+
* **Test generation** [references/test-generation.md](references/test-generation.md)
|
|
277
|
+
* **Tracing** [references/tracing.md](references/tracing.md)
|
|
278
|
+
* **Video recording** [references/video-recording.md](references/video-recording.md)
|
|
279
|
+
|
|
280
|
+
## Related Skills
|
|
281
|
+
|
|
282
|
+
* **playwright-cli-auth** - 认证会话管理,用于保存和复用登录态
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Request Mocking
|
|
2
|
+
|
|
3
|
+
Intercept, mock, modify, and block network requests.
|
|
4
|
+
|
|
5
|
+
## CLI Route Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Mock with custom status
|
|
9
|
+
playwright-cli route "**/*.jpg" --status=404
|
|
10
|
+
|
|
11
|
+
# Mock with JSON body
|
|
12
|
+
playwright-cli route "**/api/users" --body='[{"id":1,"name":"Alice"}]' --content-type=application/json
|
|
13
|
+
|
|
14
|
+
# Mock with custom headers
|
|
15
|
+
playwright-cli route "**/api/data" --body='{"ok":true}' --header="X-Custom: value"
|
|
16
|
+
|
|
17
|
+
# Remove headers from requests
|
|
18
|
+
playwright-cli route "**/*" --remove-header=cookie,authorization
|
|
19
|
+
|
|
20
|
+
# List active routes
|
|
21
|
+
playwright-cli route-list
|
|
22
|
+
|
|
23
|
+
# Remove a route or all routes
|
|
24
|
+
playwright-cli unroute "**/*.jpg"
|
|
25
|
+
playwright-cli unroute
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## URL Patterns
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
**/api/users - Exact path match
|
|
32
|
+
**/api/*/details - Wildcard in path
|
|
33
|
+
**/*.{png,jpg,jpeg} - Match file extensions
|
|
34
|
+
**/search?q=* - Match query parameters
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Advanced Mocking with run-code
|
|
38
|
+
|
|
39
|
+
For conditional responses, request body inspection, response modification, or delays:
|
|
40
|
+
|
|
41
|
+
### Conditional Response Based on Request
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
playwright-cli run-code "async page => {
|
|
45
|
+
await page.route('**/api/login', route => {
|
|
46
|
+
const body = route.request().postDataJSON();
|
|
47
|
+
if (body.username === 'admin') {
|
|
48
|
+
route.fulfill({ body: JSON.stringify({ token: 'mock-token' }) });
|
|
49
|
+
} else {
|
|
50
|
+
route.fulfill({ status: 401, body: JSON.stringify({ error: 'Invalid' }) });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Modify Real Response
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
playwright-cli run-code "async page => {
|
|
60
|
+
await page.route('**/api/user', async route => {
|
|
61
|
+
const response = await route.fetch();
|
|
62
|
+
const json = await response.json();
|
|
63
|
+
json.isPremium = true;
|
|
64
|
+
await route.fulfill({ response, json });
|
|
65
|
+
});
|
|
66
|
+
}"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Simulate Network Failures
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
playwright-cli run-code "async page => {
|
|
73
|
+
await page.route('**/api/offline', route => route.abort('internetdisconnected'));
|
|
74
|
+
}"
|
|
75
|
+
# Options: connectionrefused, timedout, connectionreset, internetdisconnected
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Delayed Response
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
playwright-cli run-code "async page => {
|
|
82
|
+
await page.route('**/api/slow', async route => {
|
|
83
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
84
|
+
route.fulfill({ body: JSON.stringify({ data: 'loaded' }) });
|
|
85
|
+
});
|
|
86
|
+
}"
|
|
87
|
+
```
|