Skip to content

feat(dx): goto、cookies、source grep、--exclude-static 等 6 项开发者体验改进 - #231

Merged
yan5xu merged 1 commit into
mainfrom
feat/developer-dx
May 28, 2026
Merged

feat(dx): goto、cookies、source grep、--exclude-static 等 6 项开发者体验改进#231
yan5xu merged 1 commit into
mainfrom
feat/developer-dx

Conversation

@yan5xu

@yan5xu yan5xu commented May 28, 2026

Copy link
Copy Markdown
Collaborator

背景

用 bb-browser 探索 cms.rflow.ai 并逆向其 API 的过程中,发现了多个工具链缺失和体验痛点:

  • 没有在已有 tab 导航的命令,只能 eval "window.location.href=..." 破坏 SPA 路由
  • trace/network 被静态资源淹没,找 API 调用如大海捞针
  • 发现 API 端点需要手动下载 JS chunks 再 grep,没有内置工具
  • 看 cookie 需要 eval "document.cookie",没有专用命令
  • open 返回 32 位长 ID,需要再查 status 才知道短 ID

新增命令

goto <url> --tab <id>

在已有 tab 中导航,使用 Page.navigate,不开新 tab。关键用途:SPA 中导航不丢失上下文。

bb-browser goto "https://example.com/dashboard" --tab 88aa
# tab: 88aa
# url: https://example.com/dashboard

cookies --tab <id> [--filter <str>]

查看页面 cookies(Network.getCookies),支持按名称/域名过滤。

bb-browser cookies --tab 88aa
# Cookies (1):
# name=cms-token  domain=cms.rflow.ai  path=/  expires=2026-06-07

bb-browser cookies --tab 88aa --filter token

source grep <pattern> --tab <id>

搜索已加载的 JS 源码。使用 Page.getResourceTree + Page.getResourceContent 获取所有脚本内容,用正则搜索。这是 SPA API 发现的杀手级功能。

bb-browser source grep "/rflow-cms/api" --tab 88aa
# === /_next/static/chunks/pages/seo/topic-e2b7ca90f307dc0a.js (1 matches) ===
#   e.post("/rflow-cms/api/topic",t)

改进

--exclude-static 过滤

trace eventsnetwork requests 新增 --exclude-static 标志,过滤掉 .js/.css/.png/.woff/.svg/.ico 以及 _next/static/ 路径。trace 同时过滤匹配的 response 事件。

# 不过滤:35 events(全是 .js)
bb-browser trace events

# 过滤后:3 events(action + HTML 请求/响应)
bb-browser trace events --exclude-static

# network 也支持
bb-browser network requests --tab 88aa --exclude-static

trace body 增强

trace body 现在同时返回 request body(POST payload)和 response body。

open 输出短 ID

open 命令输出现在显示短 tab ID(如 88aa),不再需要查 status 才知道。

改动文件

文件 改动
protocol.ts ActionType 新增 goto/cookies/source;Request 新增 excludeStatic/sourceCommand/sourcePattern;ResponseData 新增 cookies/sourceResults/requestBody
commands.ts 新增 goto/cookies/source 三个 CommandDef;trace 和 network 新增 excludeStatic 参数
command-dispatch.ts 新增 isStaticAsset() 辅助函数;新增 goto/cookies/source 三个 case;trace events 和 network requests 增加 --exclude-static 过滤(含 response 关联过滤);trace body 返回 requestBody
goto.ts (新) goto CLI 命令
cookies.ts (新) cookies CLI 命令,表格格式化输出
source.ts (新) source grep CLI 命令,按文件分组显示匹配
index.ts (cli) 路由新命令、--exclude-static flag 解析、help text 更新
open.ts 输出格式改为短 ID 优先
trace.ts 传递 excludeStatic;body 子命令显示 request body
network.ts 传递 excludeStatic

验证

  • 编译通过(pnpm build)
  • goto:tab 导航成功,保持上下文
  • cookies:正确显示 cms-token cookie
  • source grep:找到 JS 中的 API 路径
  • trace --exclude-static:35 事件过滤到 3 个(action + HTML 请求/响应)
  • network --exclude-static:只显示 Document 请求
  • open 输出短 ID
  • 向后兼容:不加 --exclude-static 时行为不变

… --exclude-static

New commands:
- goto <url> --tab: navigate existing tab via Page.navigate (keeps SPA context)
- cookies --tab [--filter]: view page cookies via Network.getCookies
- source grep <pattern> --tab: search loaded JS sources for API endpoints

Improvements:
- trace events --exclude-static: filter out .js/.css/.png/.woff and _next/static
- network requests --exclude-static: same filtering for network command
- trace --exclude-static filters both requests AND their matching responses
- trace body returns requestBody alongside responseBody for POST requests
- open command output shows short tab ID prominently
@yan5xu
yan5xu merged commit 34ada9c into main May 28, 2026
1 check failed
@yan5xu
yan5xu deleted the feat/developer-dx branch May 28, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant