browser-trace: fix bodies-snapshot dir + add helper#110
Conversation
…docs
Following the documented two-step workflow for browser-to-api ends with:
cp -r "$(browse network path | jq -r .path)" .o11y/<run>/cdp/network/bodies/
That command fails on macOS (BSD cp) before bisect-cdp.mjs has been run,
because the parent dir `cdp/network/` does not exist yet and BSD cp won't
create a parent for a trailing-slash destination. Repro: follow the
SKILL.md quickstart on macOS — the cp step exits with "No such file or
directory" and discover.mjs then runs without bodies.
Fix is two-part:
1. start-capture.mjs now creates `cdp/network/` up front (one extra
ensureDir). bisect-cdp.mjs still creates it later via writeJsonl —
this is just earlier so the snapshot step doesn't depend on bisect
having run first.
2. New helper `browser-trace/scripts/snapshot-bodies.mjs` encodes the
safe snapshot path: resolves `browse network path`, copies via
fs.cpSync (no BSD/GNU cp variance), and optionally runs `browse
network off` (`--no-off` to skip). Replaces the brittle cp one-liner
in both browser-to-api/SKILL.md and REFERENCE.md.
The manual cp pattern is kept in REFERENCE.md as commented context for
people who want to do it by hand, with the mkdir -p step it actually
needs.
Verified end-to-end against `[email protected]`: start-capture →
browse network on → drive → snapshot-bodies → stop-capture →
bisect-cdp → discover.mjs produces an OpenAPI doc with response-body
schemas.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2906b16c8a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (out.status !== 0) { | ||
| console.error('failed to resolve `browse network path`:'); | ||
| console.error(out.stderr || out.stdout); | ||
| process.exit(1); |
There was a problem hiding this comment.
Fall back when
browse network path --json exits non-zero
The script exits immediately when browse network path --json returns a non-zero status, so the documented compatibility fallback to plain browse network path never runs in the common “unknown flag” case on older browse versions. In those environments, snapshot-bodies.mjs fails even though the non-JSON command could still provide a valid path, blocking body snapshotting for the whole workflow.
Useful? React with 👍 / 👎.
Problem
Following the documented two-step workflow in browser-to-api/SKILL.md ends with this snapshot step:
On macOS (BSD
cp), this fails beforebisect-cdp.mjshas been run because the parent directorycdp/network/does not exist yet and BSDcpwill not create the parent for a trailing-slash destination.Reproduce on a clean macOS:
The current docs only suggest the manual
cpafter the snapshot step, anddiscover.mjsthen silently runs without response bodies, producing a spec with no response schemas.Fix
Two-part change, smallest surface area that closes the gap:
browser-trace/scripts/start-capture.mjs— also ensurecdp/network/exists up front (one line).bisect-cdp.mjsstill creates it later viawriteJsonl; this just moves creation earlier so the snapshot step does not depend on bisect having run first.browser-trace/scripts/snapshot-bodies.mjs(new) — encodes the safe snapshot path: resolvesbrowse network path, copies viafs.cpSync(sidesteps BSD vs GNU cp variance entirely), and by default runs `browse network off` (--no-offto skip). Replaces the brittlecpone-liner in bothbrowser-to-api/SKILL.mdandREFERENCE.md.The manual
cppattern is kept inREFERENCE.mdas commented context for hand-rolling, with themkdir -pstep it actually needs.Usage after this PR
```bash
node ../browser-trace/scripts/start-capture.mjs "$TARGET" my-site
browse network on
browse open https://example.com
node ../browser-trace/scripts/snapshot-bodies.mjs my-site # ← was a brittle cp
node ../browser-trace/scripts/stop-capture.mjs my-site
node ../browser-trace/scripts/bisect-cdp.mjs my-site
node scripts/discover.mjs --run .o11y/my-site
```
Verification
End-to-end against `@browserbasehq/[email protected]` on macOS 25.4.0:
Scope kept narrow
No other behavior changes. `bisect-cdp.mjs`, `stop-capture.mjs`, `discover.mjs`, the pipeline stages, and all output formats are untouched.