Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Agent Skill

Browser traffic to OpenAPI (Browserbase)

Turns a browser-trace capture of a website into a best-effort OpenAPI 3.1 spec: pairs requests with responses, templates URLs, infers schemas, writes a report.

name: browser-to-apiBy BrowserbaseChecked
View source on GitHub
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark

Install

Commands are pinned to commit bac30e2, the version we read, wherever the install method supports it.

npx skills

Terminal
npx skills add browserbase/skills@bac30e266488dc133cb8fa6d45638a05600acfe4 --skill browser-to-api --skill browser-trace -a claude-code

Copies both skills into .claude/skills/ in this project, pinned to the reviewed commit.

What it does

It works on traffic you have already captured; it never opens a browser itself. You first record a session with the sibling browser-trace skill, which attaches a read-only DevTools client to Chrome and writes every request and response to .o11y/<run>/cdp/network/. The agent then runs node scripts/discover.mjs --run .o11y/<run>, a five-stage pipeline: pair each request with its response, drop analytics, bot-defence and page-render noise, turn concrete URLs into templates (/items/42 becomes /items/{id}), infer JSON schemas from the bodies it saw, and emit an OpenAPI 3.1 document. GraphQL and JSON-RPC endpoints that dispatch on operationName or method are split into separate operations.

The output lands in <run>/api-spec/: openapi.yaml and openapi.json, a self-contained index.html report the agent is told to open for you, a Markdown report with curl examples, a dependency-free client.mjs, per-endpoint confidence scores and redacted samples. Response schemas only appear if you also ran browse network on during the capture, because the DevTools stream does not carry response bodies.

When to use it

You need to integrate with a web app that has no published API documentation, such as an internal tool from a vendor that went quiet or a legacy admin panel your own company still runs, and you want a starting spec rather than a week of reading the Network tab. It is also useful for documenting your own front end’s calls before a rewrite, or for checking which endpoints a single-page app really uses. The confidence file is the honest part: every endpoint carries its sample count and flags such as single-sample, so you can see what is guesswork.

When to skip it

When the site has terms of service that forbid automated access or reverse engineering, or when you do not have the right to use the API you are documenting. A generated spec makes it easy to build a client against an interface the owner never agreed to support, and that client will break without warning and may breach the agreement your account is under. Read the terms first, and prefer a published API or a partner programme where one exists.

Skip it too when the API already has documentation, when the data you want is in the rendered page (a scraper such as Firecrawl scrape is simpler), or when you cannot install browse and run Chrome with remote debugging. And treat the result as a draft: endpoints you did not click through are missing, and a field present in every sample may still be optional.

Try it

I've captured a browser-trace run at .o11y/supplier-portal while placing
an order on our supplier's portal, with browse network on. Turn it into
an OpenAPI spec for api.supplier-portal.example only, drop endpoints seen
just once, and tell me which ones have no response schema.

What it can touch

Bundles scripts
Yes
Pre-approved tools
Bash, Read, Grep
Needs
Node.js 18 or later; The browser-trace skill from the same repository, installed next to this one; The browse CLI (npm install -g browse) and a Chrome target with remote debugging, used by browser-trace to capture traffic; Optional: jq, used in the documented commands to copy captured bodies
Client-specific fields
None, spec fields only

Its scripts run with your permissions, and it may have changed since the commit we read. How to check a skill.

  • Your capture, read in full. The trace holds every header and body the browser sent, including session cookies and bearer tokens. Keep .o11y/ out of Git and delete runs you no longer need.
  • Files it writes, some unredacted. Samples, the reports and the spec examples pass through a redactor for common credential headers, password and token keys, JWTs, email addresses and phone numbers. The intermediate/paired.jsonl file is written before redaction and keeps the raw headers. client.mjs copies the first observed value of any header sent on more than half the requests, apart from cookie, authorization and x-api-key, so a CSRF or custom session header can end up in it verbatim. Check both before you share anything.
  • Shell. allowed-tools pre-approves Bash, Read and Grep in agents that honour it. The commands it runs are the Node scripts, cp, jq and open for the report.
  • Network. The scripts make no network calls. The generated client calls the target site only when you run it. Capturing traffic happens in browser-trace and your own browser session.

At commit bac30e2 the SKILL.md is 168 lines long. Alongside it:

  • scripts/ (12 entries): discover.mjs, the dispatcher, plus one script per stage (load, filter, normalize, infer, emit) and a lib/ folder for YAML output, path templating, schema merging, file handling and redaction. Node standard library only, no npm install.
  • LICENSE.txt: MIT, Browserbase 2026. The repository itself has no licence file GitHub detects.
  • package.json: marks the scripts as ES modules; no dependencies.
  • REFERENCE.md (249 lines): every flag, intermediate file format, the default exclude and redaction lists, and troubleshooting. It also documents an open-swagger-ui.mjs preview script that is not in the folder at this commit.

Alternatives

Agent browser drives a browser for you when the goal is to complete a task on the site rather than document it. Browser testing with DevTools uses the same DevTools data to debug your own app. If what you need is the page content, Firecrawl scrape returns it as Markdown with no spec in between. Once you have a spec for your own internal API, the MCP server for an internal API workflow turns it into tools an agent can call.

SKILL.md

The file exactly as published at the reviewed commit, reproduced under its MIT licence.

skills/browser-to-api/SKILL.md
---
name: browser-to-api
description: Turn a website's observable HTTP traffic into a best-effort OpenAPI 3.1 spec by analyzing a `browser-trace` capture. Use when the user wants to discover/extract API endpoints from a browser session, build an OpenAPI doc from network traffic, or document a third-party site's XHR/fetch surface for client integration.
compatibility: "Requires Node 18+ and a `browser-trace` run directory (`.o11y/<run>/`) produced by the sibling `browser-trace` skill. The scripts use only the Node standard library — no `npm install` step. `jq` is referenced in docs for ad-hoc querying but is not required by the scripts."
license: MIT
allowed-tools: Bash, Read, Grep
---

# Browser to API

Replay-driven API discovery. Consume a `browser-trace` capture, pair its CDP request / response events, templatize observed URLs, infer JSON schemas from samples, and emit an **OpenAPI 3.1** document plus a human-readable coverage report.

This skill **does not capture traffic**. It is purely offline post-processing on top of `browser-trace`'s `cdp/network/*.jsonl` buckets. The two skills compose:

```
browser-trace    →  .o11y/<run>/cdp/network/{requests,responses}.jsonl
browser-to-api   →  .o11y/<run>/api-spec/index.html + openapi.yaml + client.mjs
```

## When to use

- The user wants an OpenAPI document for a third-party or undocumented website API.
- The user has a `browser-trace` run and wants endpoints + schemas extracted from it.
- The user is building a client/SDK against a site that doesn't publish a spec.
- The user wants a coverage report showing which flows would broaden the spec.

If the user wants to **capture** traffic, send them to `browser-trace` first.

## Two-step workflow

### 1. Capture with `browser-trace` (and optionally bodies via `browse network on`)

```bash
# Local example against an existing debuggable Chrome target
TARGET=9222

node ../browser-trace/scripts/start-capture.mjs "$TARGET" my-site
browse open about:blank --cdp "$TARGET"
browse network on                                    # capture request/response bodies
browse open https://example.com
# ...drive whatever flows you want covered...

# Snapshot the bodies dir BEFORE turning capture off (the temp dir is shared
# per-session, so subsequent `browse network on` runs would mix your bodies
# with whatever a future capture writes if you skip this step).
cp -r "$(browse network path | jq -r .path)" .o11y/my-site/cdp/network/bodies/
browse network off

node ../browser-trace/scripts/stop-capture.mjs my-site
node ../browser-trace/scripts/bisect-cdp.mjs my-site
```

`browse network on` is **optional but strongly recommended** — without it, the spec has no response-body schemas (the CDP firehose used by `browse cdp` does not embed bodies). With it, both request bodies (already captured by CDP) *and* response bodies are joined into the trace by CDP `requestId`.

### 2. Generate the spec

```bash
node scripts/discover.mjs --run .o11y/my-site
# → .o11y/my-site/api-spec/index.html          ← open this
#   .o11y/my-site/api-spec/client.mjs
#   .o11y/my-site/api-spec/openapi.yaml
#   .o11y/my-site/api-spec/openapi.json
#   .o11y/my-site/api-spec/report.md
#   .o11y/my-site/api-spec/confidence.json
#   .o11y/my-site/api-spec/samples/*.json
#   .o11y/my-site/api-spec/intermediate/*.jsonl
```

`discover.mjs` auto-detects `<run>/cdp/network/bodies/`. To use a body capture from elsewhere (e.g. didn't snapshot, want the live `browse network` dir), pass `--bodies <path>` explicitly.

### 3. Open the HTML report

After `discover.mjs` finishes, **always open the generated HTML report**:

```bash
open .o11y/my-site/api-spec/index.html
```

The report is a self-contained HTML file (no server needed) that shows each discovered operation as an expandable card with variables, client usage, request/response examples, and a generated `client.mjs` snippet at the bottom. This is the primary deliverable — always open it for the user.

## CLI flags

| Flag | Required | Meaning |
|---|---|---|
| `--run <path>` | yes | Path to a `browser-trace` run directory |
| `--out <path>` | no | Output dir; default `<run>/api-spec/` |
| `--bodies <path>` | no | `browse network` capture dir to join into the trace (auto-detected from `<run>/cdp/network/bodies/` when present) |
| `--include <regex>` | no | Only include URLs matching regex (repeatable) |
| `--exclude <regex>` | no | Exclude URLs matching regex (repeatable; in addition to defaults) |
| `--origins <list>` | no | Comma-separated origin allow-list (e.g. `api.example.com,example.com`) |
| `--format <yaml\|json\|both>` | no | Output format. Default `both` |
| `--title <string>` | no | OpenAPI `info.title`. Default derived from primary origin |
| `--redact <list>` | no | Extra header names / JSON keys to redact (comma-separated) |
| `--min-samples <n>` | no | Minimum samples per endpoint to include. Default `1` |
| `--stage <name>` | no | Run only one stage: `load`, `filter`, `normalize`, `infer`, `emit` |


## Output layout

```
<run>/api-spec/
├── index.html                visual report — open this (self-contained, no server)
├── client.mjs                zero-dep fetch client with typed functions per operation
├── openapi.yaml              machine-readable spec
├── openapi.json              mirror
├── report.md                 markdown summary + curl examples
├── confidence.json           per-endpoint confidence + normalization flags
├── samples/                  redacted request/response examples
│   └── <method>__<path-hash>.json
└── intermediate/             pipeline byproducts (paired/filtered/endpoints jsonl)
```

## What you get from `browse cdp` and `browse network`

Two complementary capture sources:

| Source | Provides | Limitation |
|---|---|---|
| `browse cdp` (used by `browser-trace`) | request method/URL/headers/`postData`, response status/headers/mimeType, full event timing | **Does not embed response bodies.** Bodies must be pulled with `Network.getResponseBody`, which the firehose doesn't do. |
| `browse network on` (separate command) | request bodies AND response bodies on disk, keyed by CDP `requestId` | Capture dir is shared per `browse` session; snapshot before another `browse network on` overwrites it. |

`discover.mjs` will pull bodies from a `browse network` dir if you pass `--bodies <path>` (or stash them under `<run>/cdp/network/bodies/`, which is auto-detected). The matching is by `requestId` — `browse network` writes that into each `request.json` as `id`, and we join directly.

What changes when bodies are present:

- ✅ Path templating, query-param schemas, status codes, content-types — same either way.
- ✅ Request-body schemas — `postData` from CDP is enough; bodies dir is a nice-to-have for non-`postData` cases.
- ✅ **Response-body schemas** — fully inferred from real samples. Without bodies you get `{ description, content: <mimeType> }` skeletons.

The report flags every endpoint that has no response-body sample.

## Automatic noise filtering

The normalize stage automatically classifies and drops infrastructure noise:

- **Tracking / analytics** — paths containing `/track`, `/pixel`, `/beacon`, `/impression`, `/pageview`, `/dag/v*`
- **Bot defense** — Akamai (`/akam/`), fingerprint payloads (`sensor_data`), obfuscated multi-segment paths
- **Session plumbing** — `/session`, `/authenticate/start`, cookie consent, A/B experiment endpoints
- **HTML page renders** — `GET` requests returning `text/html` (the rendered page, not the API)

This typically drops 60-80% of captured traffic. The `--include` flag can rescue a false positive.

## GraphQL / multiplexed endpoint decomposition

When a single endpoint (like `/dapi/fe/gql`) is called with different `operationName` values, the skill automatically splits it into separate logical operations. Each gets its own:
- OpenAPI path entry (e.g. `/dapi/fe/gql [Autocomplete]`)
- Request/response schema inferred from only that operation's samples
- Curl example and variables table in the report

Detection works on body fields (`operationName`, `method`, `action`) and query params (`opname`, `op`). This covers GraphQL (APQ and inline), JSON-RPC, and similar dispatch patterns.

## Limitations

- **Coverage is bounded by the captured flow.** Endpoints not exercised in the trace will not appear. The skill cannot prove completeness.
- **Schemas are inductive, not contractual.** A field might be optional on the server even if every sample contained it.
- **Auth is observed, not specified.** The skill records auth-shaped headers in an `x-observed-auth` extension but won't claim a security scheme.
- **Path templating is heuristic.** Numeric / UUID / hex / slug patterns are detected per segment. Ambiguous URLs are flagged in `confidence.json`.
- **Redaction is best-effort.** Default redactions cover common credentials, but app-specific secrets may slip through; use `--redact` for known custom headers/keys.

## Best practices

1. **Drive the flows you want documented.** The richer the browser-trace, the richer the spec.
2. **Use `--origins` for noisy sites.** A marketing page hits dozens of analytics hosts; restrict to the API origin you care about.
3. **Inspect `report.md` first.** It has curl-ready examples and response samples for every discovered operation.
4. **Bump `--min-samples` to 2+** when you want only confidently-shaped endpoints in the final doc — drop the long tail.
5. **Pair with `browse network on`** when response-body schemas matter. The CDP firehose alone has request bodies but not response bodies.

For pipeline internals and the file format reference, see [REFERENCE.md](REFERENCE.md).
  • agent-browser

    A discovery stub for Vercel's agent-browser CLI: it tells the agent to load the version-matched usage guide from the installed CLI before automating.

    Testing and QAVercel LabsChecked at 25b5d76

  • Browser testing with DevTools (Addy Osmani)

    Addy Osmani's skill that uses the Chrome DevTools MCP server to check real pages: DOM, console errors, network requests, performance traces and screenshots.

    Testing and QAChecked at 8c99fa3

  • Firecrawl scrape

    Reads a known web page as clean Markdown or structured JSON through the Firecrawl CLI, including JS rendering, batch URLs and schema extraction.

    Checked at 1d4b072