Skip to content

Commit 2d0fb34

Browse files
committed
fix(browser): harden multi-tab routing and target isolation
- make daemon command ids collision-resistant and retry duplicate pending ids\n- add explicit tab targeting with validated select/close flows and saved default targets\n- scope browser network detail cache per target and clear stale page bindings on close\n- document the tab workflow and add unit/e2e coverage for concurrent multi-tab execution
1 parent b38eaef commit 2d0fb34

19 files changed

Lines changed: 2168 additions & 921 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ In practice:
9595
- start with `opencli-explorer` when the agent needs a reusable command for a site (it covers both automated and manual flows)
9696
- use `opencli-browser` when the agent needs to inspect or steer the page directly
9797

98-
Available browser commands include `open`, `state`, `click`, `type`, `select`, `keys`, `wait`, `get`, `screenshot`, `scroll`, `back`, `eval`, `network`, `init`, `verify`, and `close`.
98+
Available browser commands include `open`, `state`, `click`, `type`, `select`, `keys`, `wait`, `get`, `screenshot`, `scroll`, `back`, `eval`, `network`, `tab list`, `tab new`, `tab select`, `tab close`, `init`, `verify`, and `close`.
99+
100+
Use `opencli browser tab list` to inspect tab target IDs, then pass `--tab <targetId>` to route a command to a specific tab. `tab new` creates a new tab without changing the default browser target; only `tab select <targetId>` promotes that tab to the default target for later untargeted `opencli browser ...` commands.
99101

100102
## Core Concepts
101103

README.zh-CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ npx skills add jackwener/opencli --skill opencli-oneshot
9393
- 需要把某个站点收成可复用命令时,优先走 `opencli-explorer`(涵盖自动和手动两种路径)
9494
- 需要直接检查页面、操作页面时,再走 `opencli-browser`
9595

96-
`browser` 可用命令包括:`open``state``click``type``select``keys``wait``get``screenshot``scroll``back``eval``network``init``verify``close`
96+
`browser` 可用命令包括:`open``state``click``type``select``keys``wait``get``screenshot``scroll``back``eval``network``tab list``tab new``tab select``tab close``init``verify``close`
97+
98+
可以先用 `opencli browser tab list` 查看 tab 的 target ID,再通过 `--tab <targetId>` 把命令明确路由到某个 tab。`tab new` 只会新建 tab,不会改变默认浏览器目标;只有显式执行 `tab select <targetId>`,才会把该 tab 设为后续未指定 target 的 `opencli browser ...` 命令的默认目标。
9799

98100
## 核心概念
99101

docs/guide/browser-bridge.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ That's it! The daemon auto-starts when you run any browser command. No tokens, n
2525
opencli doctor # Check extension + daemon connectivity
2626
```
2727

28+
## Tab Targeting
29+
30+
Browser commands run inside the shared `browser:default` workspace unless you explicitly choose another tab target.
31+
32+
```bash
33+
opencli browser tab list
34+
opencli browser tab new https://www.baidu.com/
35+
opencli browser eval --tab <targetId> 'document.title'
36+
opencli browser tab select <targetId>
37+
opencli browser get title
38+
opencli browser tab close <targetId>
39+
```
40+
41+
Key rules:
42+
43+
- `opencli browser tab list` prints the current tab `targetId` values.
44+
- `--tab <targetId>` routes a single browser command to that specific tab.
45+
- `tab new` creates a new tab but does not change the default browser target.
46+
- `tab select <targetId>` makes that tab the default target for later untargeted `opencli browser ...` commands.
47+
- `tab close <targetId>` removes the tab; if it was the current default target, the stored default is cleared.
48+
2849
## How It Works
2950

3051
```

docs/zh/guide/browser-bridge.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ OpenCLI 通过轻量级 **Browser Bridge** Chrome 扩展 + 微守护进程连接
2323
opencli doctor # 检查扩展 + 守护进程连接
2424
```
2525

26+
## 多 Tab 定位
27+
28+
浏览器命令默认运行在共享的 `browser:default` workspace 中;如果需要操作指定 tab,可以显式传目标 target。
29+
30+
```bash
31+
opencli browser tab list
32+
opencli browser tab new https://www.baidu.com/
33+
opencli browser eval --tab <targetId> 'document.title'
34+
opencli browser tab select <targetId>
35+
opencli browser get title
36+
opencli browser tab close <targetId>
37+
```
38+
39+
规则如下:
40+
41+
- `opencli browser tab list` 会打印当前 tab 的 `targetId`
42+
- `--tab <targetId>` 会把单条 browser 命令路由到对应 tab。
43+
- `tab new` 只会新建 tab,不会改变默认浏览器目标。
44+
- `tab select <targetId>` 会把该 tab 设为后续未显式指定 target 的 `opencli browser ...` 命令默认目标。
45+
- `tab close <targetId>` 会关闭该 tab;如果它正好是当前默认目标,会一并清掉这条默认绑定。
46+
2647
## Daemon 生命周期
2748

2849
Daemon 在首次运行浏览器命令时自动启动,之后保持常驻运行。

0 commit comments

Comments
 (0)