derive-client
它能做什么
这个技能在你使用网站时记录它发送和接收的内容,然后编写一个小脚本或工具,直接发出同样的请求。适合经常重复同一网站任务的人。
适用场景
- ✓当你希望在不每次打开浏览器的情况下使用网站数据的时候。
- ✓当你需要为没有官方 API 的网站构建 CLI 的时候。
- ✓当你需要查看某个网站使用了哪些内部接口的时候。
技能链接
https://github.com/vercel-labs/agent-browser/blob/main/skill-data/derive-client/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请先看我在这个网站上搜索一次航班,然后帮我构建一个脚本,替我完成同样的搜索?”
每周 5 个新技能,1 分钟读完。
工作原理
你使用网站时,浏览器会保存一个 HAR 文件,记录网络请求。AI 研究这些请求,然后编写一个直接调用接口的客户端。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Derive an API client from a recorded session
Driving a browser is the right tool for the first visit and the wrong tool for the hundredth. This skill records a site's network traffic once while you use it, then turns the captured requests into a standalone client (script, CLI, or library) that talks to the site's internal API directly.
The recording alone contains everything needed: agent-browser embeds text response bodies (JSON/HTML/JS) in the HAR by default, so endpoint shapes can be studied offline after the browser is closed.
Workflow
1. Record Start HAR capture, drive the flows you want in the client
2. Identify Find the real API endpoints among the noise
3. Extract Pull request shapes, response schemas, and auth material
4. Generate Write the client, one function per flow
5. Verify Call every endpoint for real before declaring done
1. Record
agent-browser network har start # embeds text response bodies by default
# ... drive the site: search, open a detail page, paginate, etc. ...
agent-browser network har stop /tmp/site.har
- Exercise every flow the client should support, and run each one at least twice with different inputs (two search terms, two detail pages). Diffing the recorded URLs reveals which parts are parameters.
- If the site needs login, log in before starting the HAR so credentials don't land in the recording unnecessarily. The session cookies are exported separately in step 3.
--content allembeds binary bodies too (base64);--content nonedisables embedding. Per-body cap is 2 MB.
While the session is still open, agent-browser network requests and network request <id> give the same data interactively — but only the HAR survives navigation and browser close, so prefer it for anything multi-page.
2. Identify endpoints
Query the HAR with jq:
# All JSON API calls: method, URL, status
jq -r '.log.entries[]
| select(.response.content.mimeType | test("json"))
| "\(.request.method) \(.response.status) \(.request.url)"' /tmp/site.har
Ignore analytics and infrastructure noise: telemetry endpoints (/collect, /track, /beacon, /log), third-party domains (google-analytics, segment, sentry, datadog, intercom, hotjar), and static assets. The real API is usually first-party, JSON, and correlates with the actions you performed.
3. Extract shapes and auth
# Full detail for one endpoint: request headers, POST body, response body
jq '.log.entries[] | select(.request.url | test("api/search"))
| {request: {method: .request.method, headers: .request.headers,
postData: .request.postData.text},
response: .response.content.text}' /tmp/site.har
- Response schema: read
.response.content.text— this is the real payload, use it to derive types. - Auth: compare request headers across endpoints. Look for
authorization,cookie,x-csrf-token,x-api-key, and site-specificx-*headers. Replay only the ones that matter — test by omission in step 5. - Cookies: export the live session with
agent-browser cookies get --json > cookies.jsonfor the client to load at runtime. Never hardcode cookie values into generated source.
4. Generate the client
- One function per recorded flow (
search(query),getItem(id)), typed from the observed response bodies. - Auth material (cookies, bearer tokens) loads from a file or environment variable, with a clear error telling the user to re-run the browser login when it expires.
- Reproduce the headers the API actually requires — some sites 403 without a matching
user-agent,referer, orx-requested-with. - Keep pagination, sort, and filter parameters that appeared in the recorded query strings as function options.
5. Verify
Call every generated function against the live API and compare the response shape with the recording. Common failures:
| Symptom | Cause | Fix |
|---|---|---|
| 401/403 | Expired or missing session | Re-login via agent-browser, re-export cookies |
| 403/419 on writes | CSRF token is per-session or per-form | Fetch the token endpoint first, or keep that flow browser-driven |
| Works then breaks | Signed/expiring request params | Fall back to the browser for that step; derive the rest |
| Different shape than HAR | A/B tests or geo-dependent responses | Re-record and treat the union as optional fields |
Caveats
- Internal APIs are unversioned and change without notice — keep the HAR so
常见问题
录制前我应该登录吗?
应该。技能建议在开始录制前先登录,这样凭证就不会出现在文件中。
生成的客户端会经过测试吗?
会。技能说明,在宣布完成之前,每个接口都应实际调用一次。
录制之后还需要浏览器吗?
不需要。技能说明,首次录制之后,客户端无需浏览器。
详情
作者的原始描述
Reverse-engineer a website's internal API by recording browser traffic into a HAR file, then generate a standalone client or CLI that calls the endpoints directly, with no browser needed after the first recording. Use when asked to "derive a client", "build a CLI for <site>", "reverse engineer this site's API", "record network requests", "turn this site into an API", or when the same site will be automated repeatedly and direct HTTP calls would beat driving the browser every time.
热度
- GitHub 星标
- 45k
- 排名
- #6357
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/1
评论
- …