claude-browser-bridge 3.0.0 → 3.0.2
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/index.js +61 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -17,14 +17,20 @@ import WebSocket, { WebSocketServer } from "ws";
|
|
|
17
17
|
|
|
18
18
|
const PORT = Number(process.env.BRIDGE_PORT) || 8787;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
// F2 FIX: Re-read token on every auth attempt so `init` token regeneration
|
|
21
|
+
// takes effect without restarting the server.
|
|
22
|
+
const TOKEN_PATH = new URL("./.bridge-token", import.meta.url);
|
|
23
|
+
function readToken() {
|
|
24
|
+
try {
|
|
25
|
+
return readFileSync(TOKEN_PATH, "utf8").trim();
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!readToken()) {
|
|
25
31
|
console.error(
|
|
26
|
-
"[bridge] WARNING: server/.bridge-token is missing — run `
|
|
27
|
-
"
|
|
32
|
+
"[bridge] WARNING: server/.bridge-token is missing — run `claude-browser-bridge init` " +
|
|
33
|
+
"or `node gen-token.js`. Refusing all extension connections until then."
|
|
28
34
|
);
|
|
29
35
|
}
|
|
30
36
|
|
|
@@ -87,7 +93,7 @@ function setupOwner(wss) {
|
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
if (!role) {
|
|
90
|
-
if (msg.type === "auth" &&
|
|
96
|
+
if (msg.type === "auth" && readToken() && msg.token === readToken()) {
|
|
91
97
|
role = msg.role === "relay" ? "relay" : "extension";
|
|
92
98
|
clearTimeout(authTimer);
|
|
93
99
|
if (role === "extension") {
|
|
@@ -150,7 +156,7 @@ function connectRelay() {
|
|
|
150
156
|
mode = "relay";
|
|
151
157
|
const ws = new WebSocket(`ws://127.0.0.1:${PORT}`);
|
|
152
158
|
ws.on("open", () => {
|
|
153
|
-
ws.send(JSON.stringify({ type: "auth", token:
|
|
159
|
+
ws.send(JSON.stringify({ type: "auth", token: readToken(), role: "relay" }));
|
|
154
160
|
upstream = ws;
|
|
155
161
|
console.error(`[bridge] relay mode: forwarding through the session that owns port ${PORT}`);
|
|
156
162
|
});
|
|
@@ -211,10 +217,48 @@ establish();
|
|
|
211
217
|
|
|
212
218
|
// --- MCP server exposed to Claude Code -------------------------------------
|
|
213
219
|
|
|
220
|
+
const HELP_TOOL = {
|
|
221
|
+
name: "browser_bridge_help",
|
|
222
|
+
description:
|
|
223
|
+
"Returns the complete usage guide for all 57 browser-bridge tools. Call this ONCE at the start of any session where you need to use browser tools, to learn the optimal workflows and avoid slow anti-patterns.",
|
|
224
|
+
inputSchema: { type: "object", properties: {} },
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const HELP_TEXT = `# Claude Browser Bridge — 57 Tools Usage Guide
|
|
228
|
+
|
|
229
|
+
## CRITICAL RULES (read before using ANY tool):
|
|
230
|
+
1. ALWAYS start with \`diagnose\` — it returns snapshot + console errors + network failures + API responses in ONE call. NEVER call snapshot, get_console, get_network separately.
|
|
231
|
+
2. Use \`batch\` for 2+ independent calls — e.g. batch([{name:"get_cookies"}, {name:"get_storage"}]).
|
|
232
|
+
3. Pin with \`select_tab\` once, then stop passing tab_id — the pin persists.
|
|
233
|
+
4. Use \`new_tab\` for research — NEVER navigate away from the app tab.
|
|
234
|
+
5. After EVERY CSS/UI code change, take a \`screenshot\` to verify. Never claim "this should work" without seeing it.
|
|
235
|
+
6. Use \`inject_css\` to test CSS fixes instantly without rebuilding, then write to file once confirmed.
|
|
236
|
+
7. After 3 failed fix attempts, search the web: new_tab({url:"https://google.com/search?q=..."}).
|
|
237
|
+
|
|
238
|
+
## Tool Categories:
|
|
239
|
+
- Core: diagnose, batch, select_tab, snapshot, eval, screenshot, full_page_screenshot, get_page_text, get_html, get_page_info
|
|
240
|
+
- Interaction: click, fill, hover, scroll, press_key, select_option, upload_file, highlight_element
|
|
241
|
+
- Navigation: navigate, new_tab, close_tab, go_back, go_forward, reload, list_tabs, wait_for
|
|
242
|
+
- Debugging: get_console, get_grouped_console, get_network, search_network_bodies, get_styles, get_cookies, get_storage, get_clipboard, watch_dom_changes, generate_selector
|
|
243
|
+
- Performance: performance_trace, heap_snapshot_summary, get_load_timeline
|
|
244
|
+
- Accessibility: get_accessibility_tree, check_contrast
|
|
245
|
+
- Emulation: emulate_device, network_throttle, set_geolocation, toggle_dark_mode
|
|
246
|
+
- Testing: visual_diff, inject_css, mock_network, record_actions, replay_actions, handle_dialog
|
|
247
|
+
- Productivity: save_form_profile, load_form_profile, save_tab_session, restore_tab_session, edit_cookie, export_pdf
|
|
248
|
+
|
|
249
|
+
## Key Workflows:
|
|
250
|
+
- Investigate a page: diagnose → read errors → fix → screenshot to verify
|
|
251
|
+
- Visual bug fix: batch([screenshot, get_styles]) → edit code → screenshot → compare → iterate
|
|
252
|
+
- Performance audit: batch([performance_trace, heap_snapshot_summary, get_load_timeline])
|
|
253
|
+
- Accessibility check: batch([get_accessibility_tree, check_contrast])
|
|
254
|
+
- Test error states: mock_network({url_pattern:"/api/x", status_code:500}) → reload → screenshot
|
|
255
|
+
- Record regression test: record_actions → reproduce bug → stop → fix → replay_actions to verify
|
|
256
|
+
`;
|
|
257
|
+
|
|
214
258
|
const BATCH_TOOL = {
|
|
215
259
|
name: "batch",
|
|
216
260
|
description:
|
|
217
|
-
"Execute multiple tool calls in a single round-trip for speed. Pass an array of {name, arguments} objects. All calls run in parallel and results are returned in the same order. Use this when you need to call 2+ tools that don't depend on each other.",
|
|
261
|
+
"Execute multiple tool calls in a single round-trip for speed. Pass an array of {name, arguments} objects. All calls run in parallel and results are returned in the same order. Use this when you need to call 2+ tools that don't depend on each other. ALWAYS prefer this over sequential calls.",
|
|
218
262
|
inputSchema: {
|
|
219
263
|
type: "object",
|
|
220
264
|
properties: {
|
|
@@ -502,7 +546,7 @@ const TOOLS = [
|
|
|
502
546
|
{
|
|
503
547
|
name: "diagnose",
|
|
504
548
|
description:
|
|
505
|
-
"
|
|
549
|
+
"⚡ CALL THIS FIRST on any page. Returns snapshot (interactive elements with refs for click/fill) + console errors with stacks + failed network requests with response bodies + recent successful API responses + CAPTCHA detection + cross-origin iframe warnings + localStorage keys — ALL in ONE call. Replaces 4-5 sequential tool calls. After this, use refs from the snapshot to click/fill elements.",
|
|
506
550
|
inputSchema: {
|
|
507
551
|
type: "object",
|
|
508
552
|
properties: {
|
|
@@ -809,7 +853,7 @@ const server = new Server(
|
|
|
809
853
|
{ capabilities: { tools: {} } }
|
|
810
854
|
);
|
|
811
855
|
|
|
812
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [BATCH_TOOL, ...TOOLS] }));
|
|
856
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [HELP_TOOL, BATCH_TOOL, ...TOOLS] }));
|
|
813
857
|
|
|
814
858
|
function formatResult(name, result) {
|
|
815
859
|
if ((name === "screenshot" || name === "full_page_screenshot") && result?.dataUrl) {
|
|
@@ -837,6 +881,11 @@ function formatResult(name, result) {
|
|
|
837
881
|
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
838
882
|
const { name, arguments: args } = req.params;
|
|
839
883
|
try {
|
|
884
|
+
// Help: return the full usage guide (no extension needed).
|
|
885
|
+
if (name === "browser_bridge_help") {
|
|
886
|
+
return { content: [{ type: "text", text: HELP_TEXT }] };
|
|
887
|
+
}
|
|
888
|
+
|
|
840
889
|
// Batch: run multiple calls in one round-trip through the extension.
|
|
841
890
|
if (name === "batch") {
|
|
842
891
|
const calls = args?.calls;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-browser-bridge",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Connect your live Chrome tabs to Claude Code — 57 tools for debugging, performance, accessibility, device emulation, and browser automation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|