Skip to content

browser-trace: fix bodies-snapshot dir + add helper#110

Open
skyzer wants to merge 1 commit into
browserbase:mainfrom
skyzer:fix/snapshot-bodies-dir
Open

browser-trace: fix bodies-snapshot dir + add helper#110
skyzer wants to merge 1 commit into
browserbase:mainfrom
skyzer:fix/snapshot-bodies-dir

Conversation

@skyzer
Copy link
Copy Markdown

@skyzer skyzer commented May 15, 2026

Problem

Following the documented two-step workflow in browser-to-api/SKILL.md ends with this snapshot step:

cp -r "$(browse network path | jq -r .path)" .o11y/<run>/cdp/network/bodies/

On macOS (BSD cp), this fails before bisect-cdp.mjs has been run because the parent directory cdp/network/ does not exist yet and BSD cp will not create the parent for a trailing-slash destination.

Reproduce on a clean macOS:

node scripts/start-capture.mjs 9222 demo
browse network on
browse open https://example.com
cp -r "$(browse network path | jq -r .path)" .o11y/demo/cdp/network/bodies/
# cp: .o11y/demo/cdp/network/bodies/: No such file or directory

The current docs only suggest the manual cp after the snapshot step, and discover.mjs then silently runs without response bodies, producing a spec with no response schemas.

Fix

Two-part change, smallest surface area that closes the gap:

  1. browser-trace/scripts/start-capture.mjs — also ensure cdp/network/ exists up front (one line). bisect-cdp.mjs still creates it later via writeJsonl; this just moves creation earlier so the snapshot step does not depend on bisect having run first.

  2. browser-trace/scripts/snapshot-bodies.mjs (new) — encodes the safe snapshot path: resolves browse network path, copies via fs.cpSync (sidesteps BSD vs GNU cp variance entirely), and by default 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 hand-rolling, with the mkdir -p step 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:

  • `start-capture` now creates `.o11y//cdp/network/` as part of the initial dir setup ✓
  • `snapshot-bodies ` produces `{"bodies_dest":"...","files":466,"ran_off":true}` ✓
  • `snapshot-bodies --no-off` skips the `browse network off` call ✓
  • `discover.mjs` picks up the bodies automatically and infers response schemas ✓
  • All previously documented jq + query.mjs recipes still work against the bisected output ✓

Scope kept narrow

No other behavior changes. `bisect-cdp.mjs`, `stop-capture.mjs`, `discover.mjs`, the pipeline stages, and all output formats are untouched.

…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.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +50 to +53
if (out.status !== 0) {
console.error('failed to resolve `browse network path`:');
console.error(out.stderr || out.stdout);
process.exit(1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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