bb-browser 0.4.1 → 0.4.3
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/dist/cli.js +99 -8
- package/dist/cli.js.map +1 -1
- package/dist/mcp.js +82 -18
- package/dist/mcp.js.map +1 -1
- package/extension/background.js +700 -543
- package/extension/background.js.map +1 -1
- package/extension/dist/manifest.json +1 -1
- package/extension/manifest.json +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -31,7 +31,14 @@ async function sendCommand(request) {
|
|
|
31
31
|
return {
|
|
32
32
|
id: request.id,
|
|
33
33
|
success: false,
|
|
34
|
-
error:
|
|
34
|
+
error: [
|
|
35
|
+
"Chrome extension not connected.",
|
|
36
|
+
"",
|
|
37
|
+
"1. Download extension: https://github.com/epiral/bb-browser/releases/latest",
|
|
38
|
+
"2. Unzip the downloaded file",
|
|
39
|
+
"3. Open chrome://extensions/ \u2192 Enable Developer Mode",
|
|
40
|
+
'4. Click "Load unpacked" \u2192 select the unzipped folder'
|
|
41
|
+
].join("\n")
|
|
35
42
|
};
|
|
36
43
|
}
|
|
37
44
|
return {
|
|
@@ -52,7 +59,15 @@ async function sendCommand(request) {
|
|
|
52
59
|
};
|
|
53
60
|
}
|
|
54
61
|
if (error.message.includes("fetch failed") || error.message.includes("ECONNREFUSED")) {
|
|
55
|
-
throw new Error(
|
|
62
|
+
throw new Error([
|
|
63
|
+
"Cannot connect to daemon.",
|
|
64
|
+
"",
|
|
65
|
+
"Start the daemon first:",
|
|
66
|
+
" bb-browser daemon",
|
|
67
|
+
"",
|
|
68
|
+
"Then load the Chrome extension:",
|
|
69
|
+
" chrome://extensions/ \u2192 Developer Mode \u2192 Load unpacked \u2192 node_modules/bb-browser/extension/"
|
|
70
|
+
].join("\n"));
|
|
56
71
|
}
|
|
57
72
|
throw error;
|
|
58
73
|
}
|
|
@@ -1845,9 +1860,13 @@ async function siteRun(name, args, options) {
|
|
|
1845
1860
|
const evalReq = { id: generateId(), action: "eval", script, tabId: targetTabId };
|
|
1846
1861
|
const evalResp = await sendCommand(evalReq);
|
|
1847
1862
|
if (!evalResp.success) {
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1863
|
+
const hint = site.domain ? `Open https://${site.domain} in your browser, make sure you are logged in, then retry.` : void 0;
|
|
1864
|
+
if (options.json) {
|
|
1865
|
+
console.log(JSON.stringify({ id: evalReq.id, success: false, error: evalResp.error || "eval failed", hint }));
|
|
1866
|
+
} else {
|
|
1867
|
+
console.error(`[error] site ${name}: ${evalResp.error || "eval failed"}`);
|
|
1868
|
+
if (hint) console.error(` Hint: ${hint}`);
|
|
1869
|
+
}
|
|
1851
1870
|
process.exit(1);
|
|
1852
1871
|
}
|
|
1853
1872
|
const result = evalResp.data?.result;
|
|
@@ -1867,11 +1886,18 @@ async function siteRun(name, args, options) {
|
|
|
1867
1886
|
}
|
|
1868
1887
|
if (typeof parsed === "object" && parsed !== null && "error" in parsed) {
|
|
1869
1888
|
const errObj = parsed;
|
|
1889
|
+
const checkText = `${errObj.error} ${errObj.hint || ""}`;
|
|
1890
|
+
const isAuthError = /401|403|unauthorized|forbidden|not.?logged|login.?required|sign.?in|auth/i.test(checkText);
|
|
1891
|
+
const loginHint = isAuthError && site.domain ? `Please log in to https://${site.domain} in your browser first, then retry.` : void 0;
|
|
1892
|
+
const hint = loginHint || errObj.hint;
|
|
1893
|
+
const reportHint = `If this is an adapter bug, report via: gh issue create --repo epiral/bb-sites --title "[${name}] <description>" OR: bb-browser site github/issue-create epiral/bb-sites --title "[${name}] <description>"`;
|
|
1870
1894
|
if (options.json) {
|
|
1871
|
-
console.log(JSON.stringify({ id: evalReq.id, success: false, error: errObj.error, hint
|
|
1895
|
+
console.log(JSON.stringify({ id: evalReq.id, success: false, error: errObj.error, hint, reportHint }));
|
|
1872
1896
|
} else {
|
|
1873
1897
|
console.error(`[error] site ${name}: ${errObj.error}`);
|
|
1874
|
-
if (
|
|
1898
|
+
if (hint) console.error(` Hint: ${hint}`);
|
|
1899
|
+
console.error(` Report: gh issue create --repo epiral/bb-sites --title "[${name}] ..."`);
|
|
1900
|
+
console.error(` or: bb-browser site github/issue-create epiral/bb-sites --title "[${name}] ..."`);
|
|
1875
1901
|
}
|
|
1876
1902
|
process.exit(1);
|
|
1877
1903
|
}
|
|
@@ -1902,7 +1928,12 @@ async function siteCommand(args, options = {}) {
|
|
|
1902
1928
|
bb-browser site list
|
|
1903
1929
|
bb-browser site reddit/thread https://www.reddit.com/r/LocalLLaMA/comments/...
|
|
1904
1930
|
bb-browser site twitter/user yan5xu
|
|
1905
|
-
bb-browser site search reddit
|
|
1931
|
+
bb-browser site search reddit
|
|
1932
|
+
|
|
1933
|
+
Adapter \u7ED3\u679C\u4E0D\u7B26\u5408\u9884\u671F\uFF1F\u62A5\u544A\u95EE\u9898\uFF1A
|
|
1934
|
+
gh issue create --repo epiral/bb-sites --title "[adapter-name] \u63CF\u8FF0"
|
|
1935
|
+
\u6216: https://github.com/epiral/bb-sites/issues
|
|
1936
|
+
\u8D21\u732E\u65B0 adapter: https://github.com/epiral/bb-sites`);
|
|
1906
1937
|
return;
|
|
1907
1938
|
}
|
|
1908
1939
|
switch (subCommand) {
|
|
@@ -2428,6 +2459,66 @@ async function main() {
|
|
|
2428
2459
|
await siteCommand(parsed.args, { json: parsed.flags.json, tabId: globalTabId });
|
|
2429
2460
|
break;
|
|
2430
2461
|
}
|
|
2462
|
+
case "guide": {
|
|
2463
|
+
console.log(`How to turn any website into a bb-browser site adapter
|
|
2464
|
+
=======================================================
|
|
2465
|
+
|
|
2466
|
+
1. REVERSE ENGINEER the API
|
|
2467
|
+
bb-browser network clear --tab <tabId>
|
|
2468
|
+
bb-browser refresh --tab <tabId>
|
|
2469
|
+
bb-browser network requests --filter "api" --with-body --json --tab <tabId>
|
|
2470
|
+
|
|
2471
|
+
2. TEST if direct fetch works (Tier 1)
|
|
2472
|
+
bb-browser eval "fetch('/api/endpoint',{credentials:'include'}).then(r=>r.json())" --tab <tabId>
|
|
2473
|
+
|
|
2474
|
+
If it works \u2192 Tier 1 (Cookie auth, like Reddit/GitHub/Zhihu/Bilibili)
|
|
2475
|
+
If needs extra headers \u2192 Tier 2 (like Twitter: Bearer + CSRF token)
|
|
2476
|
+
If needs request signing \u2192 Tier 3 (like Xiaohongshu: Pinia store actions)
|
|
2477
|
+
|
|
2478
|
+
3. WRITE the adapter (one JS file per operation)
|
|
2479
|
+
|
|
2480
|
+
/* @meta
|
|
2481
|
+
{
|
|
2482
|
+
"name": "platform/command",
|
|
2483
|
+
"description": "What it does",
|
|
2484
|
+
"domain": "www.example.com",
|
|
2485
|
+
"args": { "query": {"required": true, "description": "Search query"} },
|
|
2486
|
+
"readOnly": true,
|
|
2487
|
+
"example": "bb-browser site platform/command value"
|
|
2488
|
+
}
|
|
2489
|
+
*/
|
|
2490
|
+
async function(args) {
|
|
2491
|
+
if (!args.query) return {error: 'Missing argument: query'};
|
|
2492
|
+
const resp = await fetch('/api/search?q=' + encodeURIComponent(args.query), {credentials: 'include'});
|
|
2493
|
+
if (!resp.ok) return {error: 'HTTP ' + resp.status, hint: 'Not logged in?'};
|
|
2494
|
+
return await resp.json();
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
4. TEST it
|
|
2498
|
+
Save to ~/.bb-browser/sites/platform/command.js (private, takes priority)
|
|
2499
|
+
bb-browser site platform/command "test query" --json
|
|
2500
|
+
|
|
2501
|
+
5. CONTRIBUTE
|
|
2502
|
+
Option A (with gh CLI):
|
|
2503
|
+
git clone https://github.com/epiral/bb-sites && cd bb-sites
|
|
2504
|
+
git checkout -b feat-platform
|
|
2505
|
+
# add adapter files
|
|
2506
|
+
git push -u origin feat-platform
|
|
2507
|
+
gh pr create --repo epiral/bb-sites
|
|
2508
|
+
|
|
2509
|
+
Option B (without gh CLI, using bb-browser itself):
|
|
2510
|
+
bb-browser site github/fork epiral/bb-sites
|
|
2511
|
+
git clone https://github.com/YOUR_USER/bb-sites && cd bb-sites
|
|
2512
|
+
git checkout -b feat-platform
|
|
2513
|
+
# add adapter files
|
|
2514
|
+
git push -u origin feat-platform
|
|
2515
|
+
bb-browser site github/pr-create epiral/bb-sites --title "feat(platform): add adapters" --head "YOUR_USER:feat-platform"
|
|
2516
|
+
|
|
2517
|
+
Private adapters: ~/.bb-browser/sites/<platform>/<command>.js
|
|
2518
|
+
Community: ~/.bb-browser/bb-sites/ (via bb-browser site update)
|
|
2519
|
+
Full guide: https://github.com/epiral/bb-sites/blob/main/SKILL.md`);
|
|
2520
|
+
break;
|
|
2521
|
+
}
|
|
2431
2522
|
default: {
|
|
2432
2523
|
console.error(`\u9519\u8BEF\uFF1A\u672A\u77E5\u547D\u4EE4 "${parsed.command}"`);
|
|
2433
2524
|
console.error("\u8FD0\u884C bb-browser --help \u67E5\u770B\u53EF\u7528\u547D\u4EE4");
|