bb-browser-api 0.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,377 @@
1
+ <div align="center">
2
+
3
+ # bb-browser-api
4
+
5
+ ### BadBoy Browser API
6
+
7
+ **Your browser is the API. No keys. No bots. No scrapers.**
8
+
9
+ [![npm](https://img.shields.io/npm/v/bb-browser-api?color=CB3837&logo=npm&logoColor=white)](https://www.npmjs.com/package/bb-browser-api)
10
+ [![Node.js](https://img.shields.io/badge/Node.js-18+-339933?logo=node.js&logoColor=white)](https://nodejs.org)
11
+ [![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
12
+
13
+ [English](README.md) · [中文](README.zh-CN.md)
14
+
15
+ </div>
16
+
17
+ ---
18
+
19
+ > **Fork Note (skVPN/bb-browser-api):** This fork adds three new HTTP API endpoints to the daemon and changes the default port to **18888**. Install with `npm install -g bb-browser-api`. See [What's Changed in This Fork](#whats-changed-in-this-fork) for details.
20
+ >
21
+ > **Original Project:** [epiral/bb-browser](https://github.com/epiral/bb-browser)
22
+
23
+ ---
24
+
25
+ You're already logged into Twitter, Reddit, YouTube, Zhihu, Bilibili, LinkedIn, GitHub — bb-browser lets AI agents **use that directly**.
26
+
27
+ ```bash
28
+ bb-browser-api site twitter/search "AI agent" # search tweets
29
+ bb-browser-api site zhihu/hot # trending on Zhihu
30
+ bb-browser-api site arxiv/search "transformer" # search papers
31
+ bb-browser-api site eastmoney/stock "茅台" # real-time stock quote
32
+ bb-browser-api site boss/search "AI engineer" # search jobs
33
+ bb-browser site wikipedia/summary "Python" # Wikipedia summary
34
+ bb-browser site youtube/transcript VIDEO_ID # full transcript
35
+ bb-browser site stackoverflow/search "async" # search SO questions
36
+ ```
37
+
38
+ **103 commands across 36 platforms.** All using your real browser's login state. [Full list →](https://github.com/epiral/bb-sites)
39
+
40
+ ## The idea
41
+
42
+ The internet was built for browsers. AI agents have been trying to access it through APIs — but 99% of websites don't offer one.
43
+
44
+ bb-browser flips this: **instead of forcing websites to provide machine interfaces, let machines use the human interface directly.** The adapter runs `eval` inside your browser tab, calls `fetch()` with your cookies, or invokes the page's own webpack modules. The website thinks it's you. Because it **is** you.
45
+
46
+ | | Playwright / Selenium | Scraping libs | bb-browser |
47
+ |---|---|---|---|
48
+ | Browser | Headless, isolated | No browser | Your real Chrome |
49
+ | Login state | None, must re-login | Cookie extraction | Already there |
50
+ | Anti-bot | Detected easily | Cat-and-mouse | Invisible — it IS the user |
51
+ | Complex auth | Can't replicate | Reverse engineer | Page handles it itself |
52
+
53
+ ## Quick Start
54
+
55
+ ### Install
56
+
57
+ ```bash
58
+ npm install -g bb-browser-api
59
+ ```
60
+
61
+ ### Use
62
+
63
+ ```bash
64
+ bb-browser-api site update # pull community adapters
65
+ bb-browser-api site recommend # see which adapters match your browsing habits
66
+ bb-browser-api site zhihu/hot # go
67
+ ```
68
+
69
+ ### OpenClaw (no extension needed)
70
+
71
+ If you use [OpenClaw](https://openclaw.ai), bb-browser-api runs directly through OpenClaw's built-in browser — no Chrome extension or daemon required:
72
+
73
+ ```bash
74
+ bb-browser-api site reddit/hot --openclaw
75
+ bb-browser-api site xueqiu/hot-stock 5 --openclaw --jq '.items[] | {name, changePercent}'
76
+ ```
77
+
78
+ Skill on ClawHub: [bb-browser-openclaw](https://clawhub.ai/yan5xu/bb-browser)
79
+
80
+ ### MCP (Claude Code / Cursor)
81
+
82
+ ```json
83
+ {
84
+ "mcpServers": {
85
+ "bb-browser-api": {
86
+ "command": "npx",
87
+ "args": ["-y", "bb-browser-api", "--mcp"]
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ ## 36 platforms, 103 commands
94
+
95
+ Community-driven via [bb-sites](https://github.com/epiral/bb-sites). One JS file per command.
96
+
97
+ | Category | Platforms | Commands |
98
+ |----------|-----------|----------|
99
+ | **Search** | Google, Baidu, Bing, DuckDuckGo, Sogou WeChat | search |
100
+ | **Social** | Twitter/X, Reddit, Weibo, Xiaohongshu, Jike, LinkedIn, Hupu | search, feed, thread, user, notifications, hot |
101
+ | **News** | BBC, Reuters, 36kr, Toutiao, Eastmoney | headlines, search, newsflash, hot |
102
+ | **Dev** | GitHub, StackOverflow, HackerNews, CSDN, cnblogs, V2EX, Dev.to, npm, PyPI, arXiv | search, issues, repo, top, thread, package |
103
+ | **Video** | YouTube, Bilibili | search, video, transcript, popular, comments, feed |
104
+ | **Entertainment** | Douban, IMDb, Genius, Qidian | movie, search, top250 |
105
+ | **Finance** | Xueqiu, Eastmoney, Yahoo Finance | stock, hot stocks, feed, watchlist, search |
106
+ | **Jobs** | BOSS Zhipin, LinkedIn | search, detail, profile |
107
+ | **Knowledge** | Wikipedia, Zhihu, Open Library | search, summary, hot, question |
108
+ | **Shopping** | SMZDM | search deals |
109
+ | **Tools** | Youdao, GSMArena, Product Hunt, Ctrip | translate, phone specs, trending products |
110
+
111
+ ## 10 minutes to add any website
112
+
113
+ ```bash
114
+ bb-browser guide # full tutorial
115
+ ```
116
+
117
+ Tell your AI agent: *"turn XX website into a CLI"*. It reads the guide, reverse-engineers the API with `network --with-body`, writes the adapter, tests it, and submits a PR. All autonomously.
118
+
119
+ Three tiers of adapter complexity:
120
+
121
+ | Tier | Auth method | Example | Time |
122
+ |------|-------------|---------|------|
123
+ | **1** | Cookie (fetch directly) | Reddit, GitHub, V2EX | ~1 min |
124
+ | **2** | Bearer + CSRF token | Twitter, Zhihu | ~3 min |
125
+ | **3** | Webpack injection / Pinia store | Twitter search, Xiaohongshu | ~10 min |
126
+
127
+ We tested this: **20 AI agents ran in parallel, each independently reverse-engineered a website and produced a working adapter.** The marginal cost of adding a new website to the agent-accessible internet is approaching zero.
128
+
129
+ ## What this means for AI agents
130
+
131
+ Without bb-browser, an AI agent's world is: **files + terminal + a few APIs with keys.**
132
+
133
+ With bb-browser: **files + terminal + the entire internet.**
134
+
135
+ An agent can now, in under a minute:
136
+
137
+ ```bash
138
+ # Cross-platform research on any topic
139
+ bb-browser site arxiv/search "retrieval augmented generation"
140
+ bb-browser site twitter/search "RAG"
141
+ bb-browser site github search rag-framework
142
+ bb-browser site stackoverflow/search "RAG implementation"
143
+ bb-browser site zhihu/search "RAG"
144
+ bb-browser site 36kr/newsflash
145
+ ```
146
+
147
+ Six platforms, six dimensions, structured JSON. Faster and broader than any human researcher.
148
+
149
+ ## Also a full browser automation tool
150
+
151
+ ```bash
152
+ bb-browser-api open https://example.com
153
+ bb-browser-api snapshot -i # accessibility tree
154
+ bb-browser-api click @3 # click element
155
+ bb-browser-api fill @5 "hello" # fill input
156
+ bb-browser-api eval "document.title" # run JS
157
+ bb-browser-api fetch URL --json # authenticated fetch
158
+ bb-browser-api network requests --with-body --json # capture traffic
159
+ bb-browser-api screenshot # take screenshot
160
+ ```
161
+
162
+ All commands support `--json` output, `--jq <expr>` for inline filtering, and `--tab <id>` for concurrent multi-tab operations.
163
+
164
+ ```bash
165
+ bb-browser-api site xueqiu/hot-stock 5 --jq '.items[] | {name, changePercent}'
166
+ # {"name":"云天化","changePercent":"2.08%"}
167
+ # {"name":"东吴股份","changePercent":"-7.60%"}
168
+
169
+ bb-browser-api site info xueqiu/stock # view adapter args, example, domain
170
+ ```
171
+
172
+ ## HTTP API for programmatic access
173
+
174
+ The daemon exposes an HTTP API for direct integration. **Default port: `18888`** (changed from upstream's `19824`).
175
+
176
+ ```bash
177
+ # Start daemon
178
+ bb-browser-api daemon start
179
+
180
+ # Fetch API — execute a request inside the browser context
181
+ curl -X POST http://localhost:18888/api/fetch \
182
+ -H "Content-Type: application/json" \
183
+ -d '{
184
+ "url": "https://api.github.com/users/octocat",
185
+ "method": "GET",
186
+ "credentials": "include"
187
+ }'
188
+
189
+ # Capture API — visit a URL and capture matching network requests
190
+ curl "http://localhost:18888/api/capture?url=https://example.com&pattern=api"
191
+
192
+ # Storage API — read cookies / localStorage / sessionStorage for a domain
193
+ curl "http://localhost:18888/api/storage?domain=example.com"
194
+ ```
195
+
196
+ **Key advantage:** Executes in your real browser context with cookies and login state automatically included.
197
+
198
+ ### Node.js example
199
+
200
+ ```javascript
201
+ const response = await fetch('http://localhost:18888/api/fetch', {
202
+ method: 'POST',
203
+ headers: { 'Content-Type': 'application/json' },
204
+ body: JSON.stringify({
205
+ url: 'https://www.reddit.com/api/me.json',
206
+ credentials: 'include', // send cookies
207
+ }),
208
+ });
209
+ const result = await response.json();
210
+ console.log(result.body); // Your Reddit user data
211
+ ```
212
+
213
+ ### Python example
214
+
215
+ ```python
216
+ import requests
217
+
218
+ response = requests.post('http://localhost:18888/api/fetch', json={
219
+ 'url': 'https://api.github.com/users/octocat',
220
+ })
221
+ result = response.json()
222
+ print(result['body'])
223
+ ```
224
+
225
+ **Documentation:** [API Fetch Guide](docs/api-fetch.md) · [Capture & Storage Guide](docs/api-capture-storage.md)
226
+
227
+ ## Daemon configuration
228
+
229
+ The daemon binds to `127.0.0.1:18888` by default. You can customize the host with `--host`:
230
+
231
+ ```bash
232
+ bb-browser-api daemon --host 127.0.0.1 # IPv4 only (fix macOS IPv6 issues)
233
+ bb-browser-api daemon --host 0.0.0.0 # listen on all interfaces (for Tailscale / ZeroTier remote access)
234
+ ```
235
+
236
+ ## Architecture
237
+
238
+ ```
239
+ AI Agent (Claude Code, Codex, Cursor, etc.)
240
+ ┆ CLI or MCP (stdio)
241
+
242
+ bb-browser CLI ──HTTP──▶ Daemon ──CDP WebSocket──▶ Your Real Browser
243
+
244
+ ┌──────┴──────┐
245
+ │ Per-tab │
246
+ │ event cache │
247
+ │ (network, │
248
+ │ console, │
249
+ │ errors) │
250
+ └─────────────┘
251
+ ```
252
+
253
+ ---
254
+
255
+ ## What's Changed in This Fork
256
+
257
+ This fork ([skVPN/bb-browser-api](https://github.com/skVPN/bb-browser-api)) adds the following changes on top of the upstream [epiral/bb-browser](https://github.com/epiral/bb-browser):
258
+
259
+ ### 1. Default port changed: `19824` → `18888`
260
+
261
+ **File:** `packages/shared/src/constants.ts`
262
+
263
+ ```diff
264
+ - export const DAEMON_PORT = 19824;
265
+ + export const DAEMON_PORT = 18888;
266
+ ```
267
+
268
+ ### 2. New HTTP API: `POST /api/fetch`
269
+
270
+ Execute an HTTP request inside the browser context (with cookies, login state, etc.).
271
+
272
+ **File:** `packages/daemon/src/http-server.ts`, `packages/daemon/src/command-dispatch.ts`
273
+
274
+ **Request:**
275
+ ```json
276
+ POST http://localhost:18888/api/fetch
277
+ {
278
+ "url": "https://api.example.com/data",
279
+ "method": "GET",
280
+ "headers": { "Accept": "application/json" },
281
+ "credentials": "include",
282
+ "body": ""
283
+ }
284
+ ```
285
+
286
+ | Field | Type | Required | Description |
287
+ |-------|------|----------|-------------|
288
+ | `url` | string | ✅ | Target URL |
289
+ | `method` | string | — | HTTP method, default `GET` |
290
+ | `headers` | object | — | Custom request headers |
291
+ | `credentials` | `omit` \| `same-origin` \| `include` | — | Cookie behavior, default `omit` |
292
+ | `body` | string | — | Request body (for POST/PUT) |
293
+ | `tabId` | string \| number | — | Specific tab to use |
294
+
295
+ **Response:**
296
+ ```json
297
+ {
298
+ "status": 200,
299
+ "contentType": "application/json",
300
+ "body": { ... }
301
+ }
302
+ ```
303
+
304
+ > **Note on `credentials`:** `Sec-Fetch-*` headers are set by the browser automatically and cannot be overridden via JavaScript — this is a browser security requirement. The `credentials` field controls whether cookies are sent.
305
+
306
+ ### 3. New HTTP API: `GET /api/capture`
307
+
308
+ Visit a URL and capture network requests matching a pattern.
309
+
310
+ **File:** `packages/daemon/src/http-server.ts`
311
+
312
+ ```
313
+ GET http://localhost:18888/api/capture?url=https://example.com&pattern=api\.&timeout=5000
314
+ ```
315
+
316
+ | Parameter | Required | Description |
317
+ |-----------|----------|-------------|
318
+ | `url` | ✅ | Page URL to visit |
319
+ | `pattern` | — | Regex to filter captured requests |
320
+ | `timeout` | — | Wait time in ms, default `5000` |
321
+
322
+ **Response:**
323
+ ```json
324
+ {
325
+ "requests": [
326
+ {
327
+ "url": "https://example.com/api/data",
328
+ "method": "GET",
329
+ "status": 200,
330
+ "responseBody": "..."
331
+ }
332
+ ]
333
+ }
334
+ ```
335
+
336
+ ### 4. New HTTP API: `GET /api/storage`
337
+
338
+ Read cookies, localStorage, and sessionStorage for a domain.
339
+
340
+ **File:** `packages/daemon/src/http-server.ts`
341
+
342
+ ```
343
+ GET http://localhost:18888/api/storage?domain=example.com
344
+ ```
345
+
346
+ | Parameter | Required | Description |
347
+ |-----------|----------|-------------|
348
+ | `domain` | ✅ | Domain to read storage from |
349
+
350
+ **Response:**
351
+ ```json
352
+ {
353
+ "cookies": [ { "name": "session", "value": "...", "domain": "example.com" } ],
354
+ "localStorage": { "key": "value" },
355
+ "sessionStorage": { "key": "value" }
356
+ }
357
+ ```
358
+
359
+ ### 5. `credentials` field added to `Request` protocol
360
+
361
+ **File:** `packages/shared/src/protocol.ts`
362
+
363
+ ```typescript
364
+ export interface Request {
365
+ // ...existing fields...
366
+ /** fetch credentials option: omit | same-origin | include (default: omit) */
367
+ credentials?: "omit" | "same-origin" | "include";
368
+ }
369
+ ```
370
+
371
+ Previously the fetch implementation hardcoded `credentials: 'include'`. It now defaults to `'omit'` and respects the caller's choice.
372
+
373
+ ---
374
+
375
+ ## License
376
+
377
+ MIT