Skip to content

Commit 8d48b00

Browse files
committed
Fix profile JSON output and guidance
1 parent a1ad60b commit 8d48b00

4 files changed

Lines changed: 62 additions & 22 deletions

File tree

cmd/open-browser-use/main.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,16 +1446,6 @@ func renderProfilesList(writer io.Writer, profiles []installedChromeProfile, con
14461446
return err
14471447
}
14481448
fmt.Fprintln(writer, string(payload))
1449-
if showConnected {
1450-
// Surface any connected host whose instanceId didn't resolve to a known
1451-
// installed profile (rare; would happen if the install registered
1452-
// extension state under an unknown directory layout).
1453-
for _, info := range connected {
1454-
if info.Directory == "" && info.InstanceID != "" {
1455-
fmt.Fprintf(writer, "// unresolved connected host: socket=%s instance=%s\n", info.SocketPath, info.InstanceID)
1456-
}
1457-
}
1458-
}
14591449
return nil
14601450
}
14611451
if len(profiles) == 0 {

cmd/open-browser-use/main_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,35 @@ func TestProfilesCommandJSONOutput(t *testing.T) {
630630
}
631631
}
632632

633+
func TestProfilesJSONOutputRemainsValidWithUnresolvedHost(t *testing.T) {
634+
profiles := []installedChromeProfile{{
635+
Directory: "Default",
636+
DisplayName: "Eva",
637+
ExtensionID: defaultChromeExtensionID,
638+
Version: "0.1.10",
639+
Source: "/tmp/manifest.json",
640+
}}
641+
connected := []connectedProfileInfo{{
642+
SocketPath: "/tmp/open-browser-use/unresolved.sock",
643+
InstanceID: "11111111-aaaa-bbbb-cccc-1234567890ab",
644+
}}
645+
646+
var output bytes.Buffer
647+
if err := renderProfilesList(&output, profiles, connected, true, true); err != nil {
648+
t.Fatal(err)
649+
}
650+
var got []map[string]any
651+
if err := json.Unmarshal(output.Bytes(), &got); err != nil {
652+
t.Fatalf("expected strict JSON output, got %q: %v", output.String(), err)
653+
}
654+
if len(got) != 1 {
655+
t.Fatalf("expected one installed profile row, got %+v", got)
656+
}
657+
if _, ok := got[0]["connected"]; ok {
658+
t.Fatalf("unresolved host should not mark installed profile connected: %+v", got[0])
659+
}
660+
}
661+
633662
func TestProfilesCommandHumanOutput(t *testing.T) {
634663
if runtime.GOOS == "windows" {
635664
t.Skip("Chrome profile detection is not implemented on windows")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## [2026-05-14 18:05] | Task: 收口 profile 指引与 JSON 输出
2+
3+
用户诉求:检查 profile PR 合并后的发现,并一起处理需要修的问题。目标是多
4+
profile 且都装了插件时,任务开始前如果用户没指定 profile 就先询问,后续
5+
整轮固定使用所选 profile;代码层面只需要支持切换或连接到不同 profile。
6+
7+
主要改动:
8+
9+
- 修正 `obu profiles --connected --json`:JSON 模式不再追加 `// unresolved
10+
connected host` footer,保证输出始终是可被脚本和 agent 解析的严格 JSON。
11+
- 补充回归测试,覆盖存在 unresolved connected host 时 JSON 输出仍可
12+
`json.Unmarshal`
13+
- 简化 `skills/open-browser-use/SKILL.md` 的多 profile 指引:多个已安装
14+
profile 时先问用户选哪个;选定后整个任务持续传 `--profile`;只有所选
15+
profile 未连接时才要求用户打开对应 Chrome,不自动切到其他 profile。
16+
17+
影响文件:
18+
19+
- `cmd/open-browser-use/main.go`
20+
- `cmd/open-browser-use/main_test.go`
21+
- `skills/open-browser-use/SKILL.md`

skills/open-browser-use/SKILL.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ picking whatever Chrome window happens to be active.
5252
(whether that profile's host is currently reachable). JSON output is
5353
available via `--json`.
5454

55-
2. If exactly one profile is installed and its `CONNECTED` column is `yes`,
56-
proceed without asking.
57-
58-
3. If a profile is installed but `CONNECTED` is `-`, the user's Chrome is not
59-
open on that profile. Ask the user to open Chrome on that profile (naming it
60-
by display name so it is unambiguous) before retrying — do not run browser
61-
commands yet, the connection will just fail.
62-
63-
4. If more than one profile is installed and connected, ask the user which to
64-
use unless the user already specified one in the original task ("use my work
65-
profile", "do this on cookiy.com"). When asking, list both directory name
66-
and display name so the user can recognize them.
55+
2. If exactly one profile is installed and connected, proceed without asking.
56+
If it is installed but not connected, ask the user to open Chrome on that
57+
profile before running browser commands.
58+
59+
3. If multiple profiles are installed and the user did not already specify
60+
which one to use, ask before the first browser command. List both directory
61+
name and display name so the user can recognize them, and include whether
62+
each profile is connected.
63+
64+
4. If the chosen profile is not connected, ask the user to open Chrome on that
65+
profile before retrying. Do not silently fall back to a different connected
66+
profile.
6767

6868
5. After the user has chosen, pass `--profile <selector>` to every CLI / MCP
6969
command for the rest of the task. The selector accepts either the directory

0 commit comments

Comments
 (0)