chrome-bridge-mcp 1.23.0 → 1.23.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/README.md +10 -7
- package/package.json +2 -2
- package/server/index.js +4 -2
- package/server/protocol.js +1 -1
- package/server/tools.js +98 -11
- package/server/ws-manager.js +32 -6
package/README.md
CHANGED
|
@@ -2,20 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
> By [frsorrentino](https://github.com/frsorrentino) · npm `chrome-bridge-mcp` · not affiliated with other projects named "chrome-bridge".
|
|
4
4
|
|
|
5
|
-
       [](https://chromewebstore.google.com/detail/chrome-bridge-for-claude/bioknpaeahidbelaljjohjofiloeodmb)
|
|
6
6
|
|
|
7
7
|
**Claude Code borrows a tab from the Chrome you are already using — signed in,
|
|
8
8
|
with your extensions and your cookies — works in it, and hands it back. What
|
|
9
9
|
only a person can do (a login, a 2FA code, a CAPTCHA, a choice) comes back to
|
|
10
10
|
you through `handoff`: a banner in the page, you act, the agent continues.**
|
|
11
11
|
|
|
12
|
-
Measured
|
|
13
|
-
|
|
12
|
+
Measured against the official browser extension (paired runs, 27/09/2026, n=5
|
|
13
|
+
per task, same model): filling a form, 2.5× fewer turns and 1.9× lower cost;
|
|
14
|
+
finding one row in a 1,500-row table, 2.3× lower cost in about the same number
|
|
15
|
+
of turns. ~3× the toolset and no paid plan. 60
|
|
14
16
|
web-development tools (navigation, DOM inspection, visual regression, audits,
|
|
15
17
|
network mocking) over a local WebSocket bridge, plus a headless instance for
|
|
16
18
|
CI. Self-hosted, local-only. Works on ChromeOS.
|
|
17
19
|
|
|
18
|
-

|
|
19
21
|
|
|
20
22
|
## Quickstart
|
|
21
23
|
|
|
@@ -94,9 +96,10 @@ the ChatGPT app required. Claude in Chrome documents Linux desktop since
|
|
|
94
96
|
September 2026; ChromeOS and WSL stay out. Competitor figures measured on
|
|
95
97
|
2026-09-01 and 2026-09-11 (`docs/analisi-2026-09-11-concorrenti.md`).
|
|
96
98
|
|
|
97
|
-
It wins on **round trips
|
|
98
|
-
screenshot-and-click loop, `fill_form` filling N fields in one call,
|
|
99
|
-
filtering done server-side.
|
|
99
|
+
It wins on **round trips** — short element refs instead of the
|
|
100
|
+
screenshot-and-click loop, `fill_form` filling N fields in one call — and, on
|
|
101
|
+
big pages, on **payload**: table filtering is done server-side. On the form, per single turn it actually costs
|
|
102
|
+
slightly *more*.
|
|
100
103
|
|
|
101
104
|
The full benchmark — method, every raw run including the unfavourable ones, and
|
|
102
105
|
what the harness can't measure — is in
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrome-bridge-mcp",
|
|
3
3
|
"mcpName": "io.github.frsorrentino/chrome-bridge",
|
|
4
|
-
"version": "1.23.
|
|
4
|
+
"version": "1.23.2",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "Chrome Bridge by frsorrentino: MCP server that lets Claude Code borrow a tab from your own logged-in Chrome and hand it back — logins, 2FA and CAPTCHAs stay with you (handoff). 60 tools
|
|
6
|
+
"description": "Chrome Bridge by frsorrentino: MCP server that lets Claude Code borrow a tab from your own logged-in Chrome and hand it back — logins, 2FA and CAPTCHAs stay with you (handoff). 60 tools; about half the cost of Claude in Chrome, measured; ChromeOS included.",
|
|
7
7
|
"main": "server/index.js",
|
|
8
8
|
"bin": {
|
|
9
9
|
"chrome-bridge-mcp": "server/index.js",
|
package/server/index.js
CHANGED
|
@@ -59,7 +59,7 @@ async function main() {
|
|
|
59
59
|
instructions: [
|
|
60
60
|
'Selectors on DOM tools pierce shadow DOM with ">>>" ("my-app >>> button.save").',
|
|
61
61
|
'tab_id omitted = the tab last navigated/created in this session, else the active tab. frame_id omitted = main frame (list frames with get_frames).',
|
|
62
|
-
'To find targets use get_interactives, not read_page(html); its refs (n1, n2…) are the ref param of click/type_text/hover, and navigate already returns them.',
|
|
62
|
+
'To find targets use get_interactives, not read_page(html); its refs (n1, n2…) are the ref param of click/type_text/hover and of fill_form fields, and navigate already returns them.',
|
|
63
63
|
// Il costo dominante sono i TURNI, non i byte: un turno vale ~15-30 volte
|
|
64
64
|
// un KB di output risparmiato. Queste due clausole si pagano una volta
|
|
65
65
|
// qui e valgono più di qualunque ottimizzazione di schema.
|
|
@@ -74,7 +74,9 @@ async function main() {
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
// 2. Avvia il WebSocket server
|
|
77
|
-
|
|
77
|
+
// Con --launch l'estensione arriva solo dopo l'avvio a freddo di Chrome: su
|
|
78
|
+
// una macchina carica servono decine di secondi, non i 10 s del default.
|
|
79
|
+
const wsManager = new WSManager(PORT, { host: HOST, ...(LAUNCH && !process.env.CHROME_BRIDGE_CONNECT_WAIT_MS && { connectWait: 30000 }) });
|
|
78
80
|
await wsManager.start();
|
|
79
81
|
|
|
80
82
|
// 2b. Launch mode: browser dedicato che si connette alla nostra porta.
|
package/server/protocol.js
CHANGED
package/server/tools.js
CHANGED
|
@@ -149,13 +149,25 @@ export function jsResultText(data, max) {
|
|
|
149
149
|
return fitString('result_json_prefix', JSON.stringify(value));
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
// Nome di colonna del where → chiave della riga. Il nome esatto vince; poi
|
|
153
|
+
// senza maiuscole e spazi ai bordi: con {"sku": …} contro l'intestazione
|
|
154
|
+
// "SKU" il filtro non trovava nulla e il modello ritentava (3 run su 5 del
|
|
155
|
+
// benchmark del 27/09/2026).
|
|
156
|
+
const normCol = (c) => String(c).trim().toLowerCase();
|
|
157
|
+
function tableCell(row, col) {
|
|
158
|
+
if (Object.hasOwn(row, col)) return row[col];
|
|
159
|
+
const k = normCol(col);
|
|
160
|
+
const hit = Object.keys(row).find((h) => normCol(h) === k);
|
|
161
|
+
return hit === undefined ? undefined : row[hit];
|
|
162
|
+
}
|
|
163
|
+
|
|
152
164
|
/** Una riga (oggetto colonna→valore o array di celle) soddisfa il filtro where. */
|
|
153
165
|
function tableRowMatches(row, where) {
|
|
154
166
|
return Object.entries(where).every(([col, needle]) => {
|
|
155
167
|
const n = String(needle).toLowerCase();
|
|
156
168
|
if (Array.isArray(row)) return row.some((cell) => String(cell).toLowerCase().includes(n));
|
|
157
|
-
if (col === 'any') return Object.values(row).some((cell) => String(cell).toLowerCase().includes(n));
|
|
158
|
-
const cell = row
|
|
169
|
+
if (normCol(col) === 'any') return Object.values(row).some((cell) => String(cell).toLowerCase().includes(n));
|
|
170
|
+
const cell = tableCell(row, col);
|
|
159
171
|
return cell != null && String(cell).toLowerCase().includes(n);
|
|
160
172
|
});
|
|
161
173
|
}
|
|
@@ -254,6 +266,12 @@ async function savedSummary(path, bytes, extra = {}) {
|
|
|
254
266
|
|
|
255
267
|
const selectorField = (extra = '') => z.string()
|
|
256
268
|
.describe(('CSS selector; ">>>" pierces shadow DOM. ' + extra).trim());
|
|
269
|
+
// fill_form con invio: quanto aspettare che il testo della pagina cambi, ogni
|
|
270
|
+
// quanto rileggerlo, quanto testo nuovo restituire al modello.
|
|
271
|
+
const SUBMIT_SETTLE_MS = 2000;
|
|
272
|
+
const SUBMIT_POLL_MS = 250;
|
|
273
|
+
const SUBMIT_TEXT_MAX = 800;
|
|
274
|
+
|
|
257
275
|
const waitAfter = z.enum(['none', 'navigation', 'networkidle']).optional().default('none')
|
|
258
276
|
.describe('Settle before returning: navigation waits for a page load, networkidle for quiet traffic');
|
|
259
277
|
|
|
@@ -605,6 +623,44 @@ export function registerTools(server, wsManager, caps = 'all', options = {}) {
|
|
|
605
623
|
} catch { return null; }
|
|
606
624
|
}
|
|
607
625
|
|
|
626
|
+
// Testo della pagina (o del frame) per il confronto prima/dopo un invio.
|
|
627
|
+
// Resta nel server: al modello arriva solo la differenza.
|
|
628
|
+
async function pageText(tab_id, frame_id) {
|
|
629
|
+
try {
|
|
630
|
+
const t = await send(MessageType.READ_PAGE, { mode: 'text', tab_id, frame_id });
|
|
631
|
+
return typeof t === 'string' ? t : null;
|
|
632
|
+
} catch { return null; }
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// Esito di un invio: url, titolo e le righe di testo che la pagina ha
|
|
636
|
+
// guadagnato. Il testo può arrivare dopo (fetch, redirect): si rilegge per
|
|
637
|
+
// al più SUBMIT_SETTLE_MS e, al primo cambiamento, una volta ancora dopo una
|
|
638
|
+
// pausa breve, perché un «Invio in corso…» non venga preso per l'esito.
|
|
639
|
+
const cutText = (t, max) => (t.length <= max ? t : `${t.slice(0, max)}…[+${t.length - max} chars: read_page for the rest]`);
|
|
640
|
+
|
|
641
|
+
async function submitOutcome(tab_id, frame_id, textBefore, snap) {
|
|
642
|
+
const deadline = Date.now() + SUBMIT_SETTLE_MS;
|
|
643
|
+
let text = await pageText(tab_id, frame_id);
|
|
644
|
+
while ((text == null || text === textBefore) && Date.now() < deadline) {
|
|
645
|
+
await new Promise((r) => setTimeout(r, SUBMIT_POLL_MS));
|
|
646
|
+
text = await pageText(tab_id, frame_id);
|
|
647
|
+
}
|
|
648
|
+
if (text != null && text !== textBefore) {
|
|
649
|
+
await new Promise((r) => setTimeout(r, SUBMIT_POLL_MS));
|
|
650
|
+
text = (await pageText(tab_id, frame_id)) ?? text;
|
|
651
|
+
}
|
|
652
|
+
const seen = new Set(textBefore.split('\n').map((l) => l.trim()));
|
|
653
|
+
const gained = text == null ? [] : text.split('\n').map((l) => l.trim()).filter((l) => l && !seen.has(l));
|
|
654
|
+
const snapNow = await tabSnapshot(tab_id) ?? snap;
|
|
655
|
+
return {
|
|
656
|
+
url: snapNow?.url ?? null,
|
|
657
|
+
title: snapNow?.title ?? null,
|
|
658
|
+
// truncateText suggerirebbe parametri che fill_form non ha: taglio secco.
|
|
659
|
+
new_text: gained.length ? cutText(gained.join('\n'), SUBMIT_TEXT_MAX) : null,
|
|
660
|
+
...(!gained.length && { note: text === textBefore ? 'page text unchanged after submit' : 'page text unavailable' }),
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
608
664
|
// Delta compatto dopo un'azione: solo ciò che è cambiato (url, title, conteggi
|
|
609
665
|
// DOM con segno, fuoco). Costa pochi token quando scatta, zero quando la
|
|
610
666
|
// pagina è stabile, e risparmia al client lo screenshot per capire "cosa è
|
|
@@ -1268,24 +1324,55 @@ export function registerTools(server, wsManager, caps = 'all', options = {}) {
|
|
|
1268
1324
|
server.tool(
|
|
1269
1325
|
'fill_form',
|
|
1270
1326
|
'Batch fill form fields with React-compatible events. Handles input, select, checkbox, radio, and textarea. '
|
|
1271
|
-
+ '
|
|
1327
|
+
+ 'Fields and submit take a CSS selector or a ref (n1, n2…) from navigate/get_interactives. '
|
|
1328
|
+
+ 'With submit_selector it also submits, so a repeated call submits twice — not safe to retry blindly; '
|
|
1329
|
+
+ 'after a submit, after_submit carries url, title and the text the page gained (the confirmation or the errors). '
|
|
1272
1330
|
+ 'Each field reports value_after and mismatch; page_changed carries the DOM delta.',
|
|
1273
1331
|
{
|
|
1274
1332
|
fields: z.array(z.object({
|
|
1275
|
-
selector: z.string(),
|
|
1276
|
-
|
|
1277
|
-
|
|
1333
|
+
selector: z.string().optional().describe('CSS selector; ignored when ref is given'),
|
|
1334
|
+
ref: z.string().optional().describe('From navigate or get_interactives, e.g. "n3"'),
|
|
1335
|
+
value: z.string().optional().describe('Text, option value or label; for checkbox/radio "true"/"false"'),
|
|
1336
|
+
checked: z.boolean().optional().describe('Checkbox/radio instead of value: true checks, false unchecks'),
|
|
1337
|
+
})).describe('{selector or ref, value or checked} per field'),
|
|
1278
1338
|
submit_selector: z.string().optional().describe('Submit button to click after filling'),
|
|
1339
|
+
submit_ref: z.string().optional().describe('Submit button as a ref, instead of submit_selector'),
|
|
1279
1340
|
wait_after: waitAfter,
|
|
1280
1341
|
tab_id: tabId,
|
|
1281
1342
|
frame_id: frameId,
|
|
1282
1343
|
},
|
|
1283
|
-
async ({ fields, submit_selector, wait_after, tab_id, frame_id }) => {
|
|
1344
|
+
async ({ fields, submit_selector, submit_ref, wait_after, tab_id, frame_id }) => {
|
|
1345
|
+
// I ref che navigate e get_interactives danno valevano per click,
|
|
1346
|
+
// type_text e hover ma non qui: il modello li passava comunque e
|
|
1347
|
+
// perdeva un turno sull'errore di validazione. Il ref vince sul
|
|
1348
|
+
// selettore, come negli altri tool.
|
|
1349
|
+
// checked: il modello lo scriveva per le checkbox e lo schema, che
|
|
1350
|
+
// voleva solo value, lo rifiutava (un turno, benchmark del 27/09/2026).
|
|
1351
|
+
// L'estensione capisce "true"/"false": la traduzione resta qui.
|
|
1352
|
+
const resolved = fields.map((f) => {
|
|
1353
|
+
const selector = resolveTarget(f.ref ? undefined : f.selector, f.ref, tab_id);
|
|
1354
|
+
const value = f.value ?? (typeof f.checked === 'boolean' ? String(f.checked) : undefined);
|
|
1355
|
+
if (value === undefined) throw new Error(`fill_form: field ${f.ref ?? f.selector} needs value or checked`);
|
|
1356
|
+
return { selector, value };
|
|
1357
|
+
});
|
|
1358
|
+
const submitSel = submit_ref ? resolveTarget(undefined, submit_ref, tab_id) : submit_selector;
|
|
1284
1359
|
const before = await tabSnapshot(tab_id);
|
|
1285
|
-
const
|
|
1360
|
+
const textBefore = submitSel ? await pageText(tab_id, frame_id) : null;
|
|
1361
|
+
const data = await send(MessageType.FILL_FORM, { fields: resolved, submit_selector: submitSel, tab_id, frame_id });
|
|
1286
1362
|
const waited = await applyWaitAfter(send, wait_after, tab_id);
|
|
1287
|
-
const
|
|
1288
|
-
const
|
|
1363
|
+
const after = await tabSnapshot(tab_id);
|
|
1364
|
+
const changed = pageDelta(before, after);
|
|
1365
|
+
// Dopo un invio il modello vuole sapere com'è andata: prima spendeva 1-3
|
|
1366
|
+
// turni fra find_text, extract e read_page per leggere la conferma.
|
|
1367
|
+
const afterSubmit = submitSel && textBefore != null
|
|
1368
|
+
? await submitOutcome(tab_id, frame_id, textBefore, after)
|
|
1369
|
+
: null;
|
|
1370
|
+
const out = {
|
|
1371
|
+
...data,
|
|
1372
|
+
...(waited && { wait_after: waited }),
|
|
1373
|
+
...(changed && { page_changed: changed }),
|
|
1374
|
+
...(afterSubmit && { after_submit: afterSubmit }),
|
|
1375
|
+
};
|
|
1289
1376
|
// I campi che non hanno tenuto il valore in testa, in chiaro: sono la
|
|
1290
1377
|
// riga che il modello deve leggere prima del JSON.
|
|
1291
1378
|
const mism = (data?.fields ?? []).filter((f) => f && f.mismatch);
|
|
@@ -2014,7 +2101,7 @@ export function registerTools(server, wsManager, caps = 'all', options = {}) {
|
|
|
2014
2101
|
selector: z.string().optional().default('table').describe('The table to read; ">>>" pierces shadow DOM'),
|
|
2015
2102
|
index: z.number().optional().default(0).describe('Which table to take when the selector matches several, 0-based'),
|
|
2016
2103
|
max_rows: z.number().optional().default(100).describe('Max rows returned to you (output cap).'),
|
|
2017
|
-
where: z.record(z.string(), z.string()).optional().describe('{column: substring} rows must match, case-insensitive
|
|
2104
|
+
where: z.record(z.string(), z.string()).optional().describe('{column: substring} rows must match, case-insensitive (names too). Key "any" matches any cell.'),
|
|
2018
2105
|
columns: z.array(z.string()).optional().describe('Return only these columns per row.'),
|
|
2019
2106
|
offset: z.number().optional().default(0).describe('Skip N rows of the (filtered) set before applying max_rows.'),
|
|
2020
2107
|
scan_rows: z.number().optional().default(2000).describe('Max rows materialized in-page to scan/filter; raise for very large tables.'),
|
package/server/ws-manager.js
CHANGED
|
@@ -37,6 +37,11 @@ export class WSManager {
|
|
|
37
37
|
this.pingIntervalMs = opts.pingInterval ?? PING_INTERVAL_MS;
|
|
38
38
|
this.pongGraceMs = opts.pongGrace ?? 10000;
|
|
39
39
|
this.lastPong = 0;
|
|
40
|
+
// Quanto un comando aspetta un'estensione non ancora collegata prima di
|
|
41
|
+
// fallire. Rifiutare subito costava turni: con --launch il primo navigate
|
|
42
|
+
// arrivava prima che il Chrome appena avviato si collegasse (4 run su 10
|
|
43
|
+
// del benchmark del 27/09/2026), e il modello si arrendeva o indagava.
|
|
44
|
+
this.connectWaitMs = opts.connectWait ?? (Number(process.env.CHROME_BRIDGE_CONNECT_WAIT_MS) || 10000);
|
|
40
45
|
this.stopped = false;
|
|
41
46
|
this.mode = null; // 'primary' | 'relay'
|
|
42
47
|
this.relayExtConnected = undefined; // relay mode: stato estensione riportato dal primary
|
|
@@ -101,18 +106,39 @@ export class WSManager {
|
|
|
101
106
|
* Funziona identicamente in primary e relay mode.
|
|
102
107
|
*/
|
|
103
108
|
sendCommand(type, params = {}) {
|
|
104
|
-
return
|
|
105
|
-
|
|
109
|
+
if (this.isConnected()) return this._send(type, params);
|
|
110
|
+
return this._waitConnected(this.connectWaitMs).then((ok) => {
|
|
111
|
+
if (!ok) {
|
|
106
112
|
// Un errore vago qui costa un turno intero al modello: dice cosa
|
|
107
113
|
// osservare e qual è la prossima azione.
|
|
108
|
-
|
|
114
|
+
throw new Error(
|
|
109
115
|
`Chrome extension not connected (server ${this.mode} on ${this.host}:${this.port}`
|
|
110
|
-
+ `${this.mode === 'relay' ? ', reached through another chrome-bridge instance' : ''}
|
|
116
|
+
+ `${this.mode === 'relay' ? ', reached through another chrome-bridge instance' : ''}`
|
|
117
|
+
+ `, waited ${Math.round(this.connectWaitMs / 1000)}s)`
|
|
111
118
|
+ ' — open Chrome, check the chrome-bridge extension is enabled and its port matches',
|
|
112
|
-
)
|
|
113
|
-
return;
|
|
119
|
+
);
|
|
114
120
|
}
|
|
121
|
+
return this._send(type, params);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
115
124
|
|
|
125
|
+
/** Attende che isConnected() diventi vero, al più `ms`; false allo scadere o allo stop. */
|
|
126
|
+
async _waitConnected(ms) {
|
|
127
|
+
// Un tool fa spesso più invii di fila (snapshot, comando, snapshot): dopo
|
|
128
|
+
// un'attesa appena scaduta si fallisce subito, invece di sommare N attese.
|
|
129
|
+
if (this._waitFailedAt && Date.now() - this._waitFailedAt < 5000) return false;
|
|
130
|
+
const deadline = Date.now() + ms;
|
|
131
|
+
while (!this.stopped && Date.now() < deadline) {
|
|
132
|
+
if (this.isConnected()) return true;
|
|
133
|
+
await new Promise((r) => setTimeout(r, Math.min(100, Math.max(1, deadline - Date.now()))));
|
|
134
|
+
}
|
|
135
|
+
const ok = !this.stopped && this.isConnected();
|
|
136
|
+
this._waitFailedAt = ok ? 0 : Date.now();
|
|
137
|
+
return ok;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
_send(type, params) {
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
116
142
|
const command = createCommand(type, params);
|
|
117
143
|
// Il timeout di trasporto non può essere più basso di quello chiesto dal
|
|
118
144
|
// chiamante: `wait_for --timeout 90000` moriva a 60 s con un messaggio
|