arena-bridge 0.8.0 → 0.8.1
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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/browser.mjs +80 -3
- package/src/direct.mjs +1 -1
- package/src/hub.mjs +1 -1
- package/src/mcp.mjs +1 -1
- package/src/prompt.mjs +1 -1
- package/src/ws.mjs +32 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,22 @@ All notable changes to this project are documented here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/) and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## 0.8.1
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- Browser sessions no longer die after a short idle period: the WebSocket handshake timeout
|
|
11
|
+
is cleared once the DevTools connection is up (it used to destroy the socket after 10 s
|
|
12
|
+
without traffic), TCP keepalive and WebSocket pings keep the connection alive, and the
|
|
13
|
+
Python read loop treats an idle-socket timeout as "keep waiting" instead of closing.
|
|
14
|
+
- If Chrome still drops a DevTools socket, the browser session now survives: the manager
|
|
15
|
+
reconnects in the background (Node) or lazily on the next call (Python), re-attaches all
|
|
16
|
+
tabs and keeps the same `session_id`, tab ids and observations.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- `chrome_activate`: make a tab active inside its Chrome window without moving the user's
|
|
20
|
+
cursor or stealing OS focus (background tabs may pause rendering, so activating the tab
|
|
21
|
+
you are about to work with makes interactions more reliable).
|
|
22
|
+
|
|
7
23
|
## 0.8.0
|
|
8
24
|
|
|
9
25
|
### Added
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arena-bridge",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Give a cloud AI agent (Arena.ai Agent Mode, Claude, Cursor, ...) controlled access to your own machine over HTTP/MCP: files, shell, Chrome and the macOS desktop, with an approval gate, trust windows and an audit log.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/browser.mjs
CHANGED
|
@@ -175,6 +175,7 @@ export class BrowserManager {
|
|
|
175
175
|
headless: s.headless,
|
|
176
176
|
port: s.port,
|
|
177
177
|
profile: s.profile,
|
|
178
|
+
disconnected: !!s.disconnected,
|
|
178
179
|
tabs: [...s.tabs.values()].map((t) => ({ tab_id: t.targetId, title: t.title, url: t.url })),
|
|
179
180
|
created_at: s.createdAt,
|
|
180
181
|
}));
|
|
@@ -215,14 +216,71 @@ export class BrowserManager {
|
|
|
215
216
|
tabs: new Map(),
|
|
216
217
|
observe: new Map(),
|
|
217
218
|
createdAt: Date.now(),
|
|
219
|
+
disconnected: false,
|
|
220
|
+
terminated: false,
|
|
221
|
+
reconnecting: false,
|
|
222
|
+
reconnects: 0,
|
|
218
223
|
};
|
|
219
224
|
this.sessions.set(id, session);
|
|
220
|
-
|
|
221
|
-
this.sessions.delete(id);
|
|
222
|
-
});
|
|
225
|
+
this._wireCdp(session);
|
|
223
226
|
return session;
|
|
224
227
|
}
|
|
225
228
|
|
|
229
|
+
_wireCdp(session) {
|
|
230
|
+
session.cdp.on('close', () => {
|
|
231
|
+
if (session.terminated) {
|
|
232
|
+
this.sessions.delete(session.id);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
// Chrome may drop an idle DevTools socket while the browser itself is
|
|
236
|
+
// fine. Keep the session (tabs, observations) and reconnect in the
|
|
237
|
+
// background instead of failing every later call with a dead session.
|
|
238
|
+
session.disconnected = true;
|
|
239
|
+
void this._reconnect(session);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async _reconnect(session) {
|
|
244
|
+
if (session.reconnecting || session.terminated || !session.port) return;
|
|
245
|
+
session.reconnecting = true;
|
|
246
|
+
try {
|
|
247
|
+
for (let attempt = 0; attempt < 60 && !session.terminated; attempt++) {
|
|
248
|
+
await sleep(1000);
|
|
249
|
+
try {
|
|
250
|
+
const wsUrl = await browserWsUrl(session.port);
|
|
251
|
+
const cdp = new CDPClient(wsUrl);
|
|
252
|
+
await cdp.connect();
|
|
253
|
+
if (session.terminated) {
|
|
254
|
+
cdp.close();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
session.cdp = cdp;
|
|
258
|
+
this._wireCdp(session);
|
|
259
|
+
const { targetInfos } = await cdp.send('Target.getTargets');
|
|
260
|
+
const alive = new Set();
|
|
261
|
+
for (const t of targetInfos) {
|
|
262
|
+
if (t.type !== 'page') continue;
|
|
263
|
+
alive.add(t.targetId);
|
|
264
|
+
const tab = await this._attachTarget(session, t.targetId);
|
|
265
|
+
tab.title = t.title;
|
|
266
|
+
tab.url = t.url;
|
|
267
|
+
}
|
|
268
|
+
for (const targetId of [...session.tabs.keys()]) {
|
|
269
|
+
if (!alive.has(targetId)) session.tabs.delete(targetId);
|
|
270
|
+
}
|
|
271
|
+
session.disconnected = false;
|
|
272
|
+
session.reconnects++;
|
|
273
|
+
return;
|
|
274
|
+
} catch {
|
|
275
|
+
/* Chrome not reachable yet — keep retrying */
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
this.sessions.delete(session.id);
|
|
279
|
+
} finally {
|
|
280
|
+
session.reconnecting = false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
226
284
|
async _collectTabs(session) {
|
|
227
285
|
const { targetInfos } = await session.cdp.send('Target.getTargets');
|
|
228
286
|
for (const t of targetInfos) {
|
|
@@ -376,6 +434,7 @@ export class BrowserManager {
|
|
|
376
434
|
if (!s.managed) {
|
|
377
435
|
return { ok: false, error: 'refusing to stop an attached (user) browser', session_id: s.id };
|
|
378
436
|
}
|
|
437
|
+
s.terminated = true;
|
|
379
438
|
try {
|
|
380
439
|
s.cdp.close();
|
|
381
440
|
} catch {
|
|
@@ -644,6 +703,24 @@ export class BrowserManager {
|
|
|
644
703
|
};
|
|
645
704
|
},
|
|
646
705
|
},
|
|
706
|
+
{
|
|
707
|
+
name: 'chrome_activate',
|
|
708
|
+
description:
|
|
709
|
+
'Make a tab the active one inside its Chrome window (Target.activateTarget). This does NOT move the ' +
|
|
710
|
+
"user's mouse cursor and does not steal OS focus — the window is not raised; only the selected tab " +
|
|
711
|
+
'changes. Some pages pause timers/rendering in background tabs, so activating the tab you are about ' +
|
|
712
|
+
'to work with makes interactions more reliable.',
|
|
713
|
+
approval: true,
|
|
714
|
+
approvalFor: requiresApproval,
|
|
715
|
+
schema: S({ session_id: { type: 'string' }, tab_id: { type: 'string' } }, []),
|
|
716
|
+
required: [],
|
|
717
|
+
handler: async (args, ctx) => {
|
|
718
|
+
const session = needSession(args, ctx);
|
|
719
|
+
const tab = await this._tab(session, args.tab_id);
|
|
720
|
+
await session.cdp.send('Target.activateTarget', { targetId: tab.targetId });
|
|
721
|
+
return { ok: true, session_id: session.id, tab_id: tab.targetId };
|
|
722
|
+
},
|
|
723
|
+
},
|
|
647
724
|
{
|
|
648
725
|
name: 'chrome_open',
|
|
649
726
|
description: 'Open a URL in the browser (new tab by default).',
|
package/src/direct.mjs
CHANGED
package/src/hub.mjs
CHANGED
package/src/mcp.mjs
CHANGED
|
@@ -48,7 +48,7 @@ export async function handleMcp(req, res, ctx) {
|
|
|
48
48
|
mcpResponse(id, {
|
|
49
49
|
protocolVersion: PROTOCOL_VERSION,
|
|
50
50
|
capabilities: { tools: { listChanged: false } },
|
|
51
|
-
serverInfo: { name: 'arena-bridge', version: '0.8.
|
|
51
|
+
serverInfo: { name: 'arena-bridge', version: '0.8.1' },
|
|
52
52
|
instructions:
|
|
53
53
|
'Tools operate the user\'s own machine. Dangerous operations may return ' +
|
|
54
54
|
'PROTECTED and require a local human approval.',
|
package/src/prompt.mjs
CHANGED
|
@@ -75,7 +75,7 @@ ${tools.join('\n')}
|
|
|
75
75
|
verifying the result (\`expect\` / \`chrome_wait_for\`) over screenshots and coordinates.
|
|
76
76
|
1. \`chrome_launch\` starts a browser that belongs to you — own profile, no personal data.
|
|
77
77
|
\`{"headless": true, "url": "https://example.com"}\` (headless=false opens a visible window).
|
|
78
|
-
2. Then \`chrome_open\` → \`chrome_observe\` → \`chrome_click\` by ref / \`chrome_fill_editor\` → verify with \`expect\`.
|
|
78
|
+
2. Then \`chrome_open\` → \`chrome_activate\` (makes the tab active without touching the user's cursor or OS focus — background tabs may pause rendering) → \`chrome_observe\` → \`chrome_click\` by ref / \`chrome_fill_editor\` → verify with \`expect\`.
|
|
79
79
|
\`chrome_snapshot\` with \`{"mode": "ax"}\` returns roles, names and element states; \`chrome_screenshot\` is for when the DOM is ambiguous.
|
|
80
80
|
3. \`chrome_attach\` connects to the user's own Chrome (default port 9222, with their logged-in sessions).
|
|
81
81
|
Actions on an attached browser require a local approval — ask for it instead of retrying.
|
package/src/ws.mjs
CHANGED
|
@@ -21,6 +21,7 @@ export class WebSocketClient extends EventEmitter {
|
|
|
21
21
|
this._key = crypto.randomBytes(16).toString('base64');
|
|
22
22
|
this._openResolve = null;
|
|
23
23
|
this._openReject = null;
|
|
24
|
+
this._pingTimer = null;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
connect(timeoutMs = 10000) {
|
|
@@ -49,6 +50,7 @@ export class WebSocketClient extends EventEmitter {
|
|
|
49
50
|
socket.on('error', (err) => this._fail(err));
|
|
50
51
|
socket.on('close', () => {
|
|
51
52
|
this.closed = true;
|
|
53
|
+
this._stopPing();
|
|
52
54
|
this.emit('close');
|
|
53
55
|
});
|
|
54
56
|
});
|
|
@@ -80,6 +82,17 @@ export class WebSocketClient extends EventEmitter {
|
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
82
84
|
this.upgraded = true;
|
|
85
|
+
// The handshake timeout must not outlive the handshake: net sockets
|
|
86
|
+
// destroy themselves after `timeout` ms of inactivity, which used to
|
|
87
|
+
// kill idle DevTools connections between agent actions. From here on
|
|
88
|
+
// the connection is kept alive with TCP keepalive + WS pings instead.
|
|
89
|
+
this.socket.setTimeout(0);
|
|
90
|
+
try {
|
|
91
|
+
this.socket.setKeepAlive(true);
|
|
92
|
+
} catch {
|
|
93
|
+
/* ignore */
|
|
94
|
+
}
|
|
95
|
+
this._startPing();
|
|
83
96
|
if (this._openResolve) {
|
|
84
97
|
const r = this._openResolve;
|
|
85
98
|
this._openResolve = null;
|
|
@@ -151,6 +164,24 @@ export class WebSocketClient extends EventEmitter {
|
|
|
151
164
|
this.fragmentOpcode = null;
|
|
152
165
|
}
|
|
153
166
|
|
|
167
|
+
_startPing() {
|
|
168
|
+
this._stopPing();
|
|
169
|
+
this._pingTimer = setInterval(() => {
|
|
170
|
+
if (this.closed) return;
|
|
171
|
+
try {
|
|
172
|
+
this._sendFrame(0x9, Buffer.alloc(0));
|
|
173
|
+
} catch {
|
|
174
|
+
/* the close handler reports the failure */
|
|
175
|
+
}
|
|
176
|
+
}, 30000);
|
|
177
|
+
this._pingTimer.unref?.();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_stopPing() {
|
|
181
|
+
if (this._pingTimer) clearInterval(this._pingTimer);
|
|
182
|
+
this._pingTimer = null;
|
|
183
|
+
}
|
|
184
|
+
|
|
154
185
|
send(text) {
|
|
155
186
|
this._sendFrame(0x1, Buffer.from(String(text), 'utf8'));
|
|
156
187
|
}
|
|
@@ -181,6 +212,7 @@ export class WebSocketClient extends EventEmitter {
|
|
|
181
212
|
close() {
|
|
182
213
|
if (this.closed) return;
|
|
183
214
|
this.closed = true;
|
|
215
|
+
this._stopPing();
|
|
184
216
|
try {
|
|
185
217
|
this._sendFrame(0x8, Buffer.alloc(0));
|
|
186
218
|
} catch {
|