41 Commits

Author SHA1 Message Date
yan5xu cb28e815aa feat(cli): add --mcp flag to start MCP server
`bb-browser --mcp` spawns the MCP server with stdio transport.
Users can configure AI tools with: npx -y bb-browser --mcp

Also fixes root tsup bundling to properly exclude ws while
bundling all other deps (MCP SDK, ajv, zod).

Bump version to 0.4.1.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:15:33 +08:00
yan5xu c3fa112624 fix(cli): daemon command works in npm-published layout
Replace broken `import("@bb-browser/daemon")` with `spawn(getDaemonPath())`
so `bb-browser daemon` works both in dev monorepo and npm install scenarios.

- Export getDaemonPath() from daemon-manager
- daemon command uses spawn with stdio: "inherit" for foreground mode
- Pass --host flag through to daemon process

Fixes #6, fixes #10

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:49:39 +08:00
yan5xu a882809abc fix(cli): --tab flag works correctly for all commands
- parseArgs: remove `&& !result.command` guard so --tab value is not
  leaked into command args (e.g. network filter)
- site: respect --tab, stop calling tab_select (no foreground steal)
- fetch: stop calling tab_select (no foreground steal)
- site --json: wrap output in standard {id, success, data} envelope

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:46:42 +08:00
yan5xu a2e1f29daa feat: network requests --with-body captures full request/response data
Via CDP Network.loadingFinished + Network.getResponseBody, capture:
- Request headers and body (POST data)
- Response headers, body, and mimeType
- Memory management: 256KB/response, 64KB/request, 8MB/tab total
- Eviction: oldest bodies removed first when over budget
- Graceful error handling: bodyError field for failed captures

This enables a new paradigm for site adapters: instead of reverse-engineering
API signing (like Xiaohongshu's X-s), just navigate to a page and read the
response bodies from requests the page already made with proper authentication.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 20:44:22 +08:00
yan5xu f63a1f4c9d refactor: recipe → site, fix Codex review criticals
Rename:
- recipe.ts → site.ts, command `recipe` → `site`
- bb-recipes → bb-sites, ~/.bb-browser/bb-recipes → bb-sites

Codex review fixes (fetch.ts):
- Fix headers injection: validate as JSON instead of string interpolation
- Fix origin matching: exact hostname comparison instead of includes()
- Fix method normalization: toUpperCase() + exclude HEAD from body
- Fix JSON parse on 204: skip resp.json() for empty responses
- Remove duplicate --json/non-json output branches

Codex review fixes (site.ts):
- Parse /* @meta JSON */ block comment format (with @tag fallback)
- Structured args: required/optional per-arg, skip optional in validation
- Fix arg parsing: separate --flag values from positional args
- Fix tab routing: exact origin match via URL parsing
- Capture tabId from new tab and pass to eval
- Surface adapter {error, hint} as CLI errors instead of normal output

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 17:16:14 +08:00
yan5xu 56684707da feat: add fetch and recipe commands
- `bb-browser fetch <url>`: browser-native fetch with auto same-origin tab routing.
  Like curl but with browser login state. No API keys, no anti-bot.

- `bb-browser recipe`: manage and run community/private fetch recipes.
  - recipe list: scan ~/.bb-browser/recipes/ (local) and ~/.bb-browser/bb-recipes/ (community)
  - recipe search <query>: keyword search across recipes
  - recipe run <name> [args]: execute a recipe via eval
  - recipe update: git clone/pull community recipes from epiral/bb-recipes
  - recipe <name> [args]: shorthand for recipe run

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 16:54:09 +08:00
yan5xu 4e85c29728 chore: bump version to 0.3.0
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-13 20:03:04 +08:00
yan5xu e66256a138 feat: 切换 snapshot 到 CDP Accessibility Tree
- 新增 ax-tree-formatter.ts:将 CDP AXNode[] 格式化为语义化 accessibility 树文本
- cdp-dom-service.ts:getSnapshot 改用 Accessibility.getFullAXTree,元素操作改用 backendDOMNodeId
- 支持新参数:--compact/-c(移除空结构节点)、--depth/-d(限制树深度)、--selector/-s(CSS 范围)
- link 内联 /url:,heading 标记 [level=N],重复元素标记 [nth=N]
- GitHub 页面 snapshot 从 56KB 降到 31KB(-45%)

Closes #4

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-13 19:55:34 +08:00
yan5xu 7acd596073 feat: 全局 --tab 参数支持多 tab 并发隔离
- CLI: 全局 --tab <tabId> 参数,透传给所有子命令
- Extension: resolveTab() 按 tabId 定位目标 tab,fallback activeTab
- Extension: 状态 (refs/frame) 按 tabId 隔离
- Extension: SSE 去除 await,支持并发处理命令
- bump version to 0.1.2
2026-02-06 10:41:41 +08:00
yan5xu 1acfb6031b feat: tab select/close 支持按 tabId 操作
- 协议 Request 新增 tabId 字段(优先于 index,向下兼容)
- Extension handleTabSelect/handleTabClose 支持 tabId 直接定位
- CLI 新增 tab select --id <tabId> 和 tab close --id <tabId> 语法
- 解决多调用方共用时 index 重编号导致的 tab 错位问题
2026-02-06 09:35:33 +08:00
yan5xu 67bfe2ac9a chore: 更新仓库地址为 yan5xu/bb-browser 2026-01-31 11:56:15 +08:00
yan5xu 9582e1034a feat: open 命令支持 --tab 参数,解决并发打开页面冲突
- 默认行为改为创建新 tab(并发安全)
- --tab current: 在当前活动 tab 中导航
- --tab <tabId>: 在指定 tab 中导航
- 返回 tabId 供 AI Agent 追踪管理
2026-01-30 17:24:53 +08:00
yan5xu f02b081f48 feat: 添加 trace 命令 - 录制用户操作 2026-01-30 15:58:09 +08:00
yan5xu 02edcb4c85 feat: 添加 network/console/errors 调试命令
- network requests [filter]: 查看网络请求
- network route <url> [--abort|--body]: 拦截/mock 请求
- network unroute [url]: 移除拦截规则
- network clear: 清空请求记录
- console: 查看控制台消息(log/info/warn/error)
- console --clear: 清空控制台
- errors: 查看 JS 异常
- errors --clear: 清空错误记录

扩展通过 CDP Network/Fetch/Runtime/Log 域实现监控和拦截
2026-01-30 12:34:33 +08:00
yan5xu 0052ec5c31 merge: feat/dialogs - 添加 dialog 命令 2026-01-30 10:36:55 +08:00
yan5xu fb726aec3c merge: feat/frames - 添加 frame 命令 2026-01-30 10:32:37 +08:00
yan5xu 394d7e7dc3 feat: 添加 frame 命令(切换 iframe) 2026-01-30 10:28:48 +08:00
yan5xu 8d6e6c1d75 feat: 添加 dialog 命令(accept/dismiss) 2026-01-30 10:26:52 +08:00
yan5xu a608124f06 feat: 添加 tab 命令(list/new/select/close) 2026-01-30 10:26:31 +08:00
yan5xu bbfda3fc62 feat: 添加 Phase 3 命令 (eval/type/check/uncheck/select) 2026-01-30 10:02:53 +08:00
yan5xu f871763630 merge: 合并 check/uncheck 命令到 main 2026-01-30 09:59:49 +08:00
yan5xu 67d0a2cabe Merge branch 'feat/type' 2026-01-30 09:58:35 +08:00
yan5xu 638527916f feat: 添加 check/uncheck 命令 - 复选框操作 2026-01-30 09:58:25 +08:00
yan5xu de2223587e feat: 添加 type 命令 - 逐字符输入 2026-01-30 09:58:23 +08:00
yan5xu 7e6bf96aba feat: 添加 eval 命令 - 执行 JavaScript 2026-01-30 09:58:22 +08:00
yan5xu 9b5ea1f24f merge: 合并 nav 命令 (back/forward/refresh) 到 main 2026-01-30 09:36:32 +08:00
yan5xu 22d3a36d84 Merge branch 'feat/hover' 2026-01-30 09:35:10 +08:00
yan5xu 839cac81aa merge: 合并 scroll 命令到 main 2026-01-30 09:35:05 +08:00
yan5xu 260e8cedf7 feat: 实现 hover 命令 2026-01-30 09:32:12 +08:00
yan5xu 91a33983e6 feat: 实现导航命令 (back/forward/refresh) 2026-01-30 09:31:53 +08:00
yan5xu 16f3d842f3 feat: 实现 press 命令 2026-01-30 09:31:44 +08:00
yan5xu 0d60f938df feat: 实现 scroll 命令 2026-01-30 09:31:40 +08:00
yan5xu ef9b9fc5fb merge: 合并 wait 命令到 main 2026-01-29 22:03:57 +08:00
yan5xu e2e0fba0de merge: 合并 screenshot 命令到 main 2026-01-29 22:01:13 +08:00
yan5xu ebddd36aa8 merge: 合并 get 命令到 main 2026-01-29 21:59:15 +08:00
yan5xu 247e21cda1 feat: 实现 wait 命令 2026-01-29 21:57:03 +08:00
yan5xu 028478b562 feat: 实现 get 命令组 (text/url/title) 2026-01-29 21:56:48 +08:00
yan5xu 29c335e51d feat: 实现 screenshot 命令 2026-01-29 21:56:37 +08:00
yan5xu b92a8b184e feat: 实现 close 命令 2026-01-29 21:56:13 +08:00
yan5xu 530e992caa feat: 添加 reload 命令支持 CDP 热重载扩展 2026-01-29 21:51:40 +08:00
yan5xu 601f4ae813 feat: 实现 bb-browser 核心功能
- CLI: open, snapshot, click, fill, status, stop 命令
- Extension: buildDomTree 移植, DOM 服务, SSE 通信
- Daemon: HTTP SSE 架构, 请求管理
- Shared: 通信协议类型定义

snapshot 支持两种模式:
- 默认完整树模式 (含文本节点)
- -i 交互元素模式 (只含可交互元素)

已验证: 推特/Reddit 登录态页面访问正常
2026-01-29 21:17:28 +08:00