@browserbridge/bbx 1.12.0 → 1.12.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/PRIVACY.md CHANGED
@@ -82,6 +82,7 @@ You should review the privacy and retention practices of any connected agent, ID
82
82
  Browser Bridge keeps data only as long as needed for the current local session and feature behavior.
83
83
 
84
84
  - Window enablement state is stored in session storage and cleared when disabled or when the browser session ends.
85
+ - To warn about access enabled elsewhere, the daemon shares enabled-window IDs, bounded titles, enablement timestamps, browser names, and session profile labels with connected local Browser Bridge extensions. The side panel uses this in-memory metadata for its other-enabled-windows counter. It does not include page contents or disabled-window details, and disconnecting an extension removes its entry.
85
86
  - Action log entries are stored for the current browser session only.
86
87
  - Incidental action/log URLs remove credentials and fragments and redact query values; sensitive structured fields and local path prefixes are reduced before persistence.
87
88
  - Console and fetch/XHR network buffers are bounded in memory and cleared when disabled or when the page state is reset.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbridge/bbx",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "agent-tools",
@@ -32,6 +32,7 @@ import {
32
32
  parseJsonLines,
33
33
  RecoveryTelemetryCollector,
34
34
  normalizeRecoveryTelemetrySummary,
35
+ sanitizeIncidentalText,
35
36
  sanitizeIncidentalValue,
36
37
  setProtocolPackageVersion,
37
38
  validateBridgeRequest,
@@ -54,6 +55,7 @@ import {
54
55
  import { normalizeDaemonLogger } from './daemon-logger.js';
55
56
  import { DomBaselineOwnerRegistry, isValidBaselineId } from './dom-baseline-owners.js';
56
57
  import { writeJsonLine } from './framing.js';
58
+ import { WindowActionRouter } from './window-actions.js';
57
59
 
58
60
  const DAEMON_VERSION = loadDaemonVersion();
59
61
  setProtocolPackageVersion(DAEMON_VERSION);
@@ -65,7 +67,7 @@ setProtocolPackageVersion(DAEMON_VERSION);
65
67
  /** @typedef {import('./config.js').BridgeTransport} BridgeTransport */
66
68
  /** @typedef {import('./daemon-logger.js').DaemonLoggerLike} DaemonLoggerLike */
67
69
  /** @typedef {'agent' | 'extension'} SocketRole */
68
- /** @typedef {import('node:net').Socket & { readonly __role?: SocketRole, __localControl?: boolean, __registrationTimeoutId?: NodeJS.Timeout, __invalidLineCount?: number, __clientId?: string, __extensionId?: string, __browserName?: string, __profileLabel?: string, __browserExtensionId?: string, __accessEnabled?: boolean, __lastActiveAt?: number }} ClientSocket */
70
+ /** @typedef {import('node:net').Socket & { readonly __role?: SocketRole, __localControl?: boolean, __registrationTimeoutId?: NodeJS.Timeout, __invalidLineCount?: number, __clientId?: string, __extensionId?: string, __browserName?: string, __profileLabel?: string, __browserExtensionId?: string, __accessEnabled?: boolean, __windowAccessUpdates?: boolean, __windowActions?: boolean, __enabledWindow?: import('../../protocol/src/window-access.js').EnabledWindowInfo | null, __lastActiveAt?: number }} ClientSocket */
69
71
  /** @typedef {{ socket: ClientSocket, timeoutId: NodeJS.Timeout, source?: string, mcpEra?: string, method?: string, protocolVersion?: string, baselineId?: string | null, automaticMcpRetry?: boolean, targets: Set<ClientSocket>, lastErrorResponse?: import('../../protocol/src/types.js').BridgeResponse }} PendingEntry */
70
72
  /**
71
73
  * @typedef {{
@@ -410,12 +412,20 @@ export function isWindowsNamedPipePath(socketPath) {
410
412
  * entry?: Record<string, unknown>,
411
413
  * request?: BridgeRequest,
412
414
  * status?: SetupStatus,
413
- * error?: { message?: string },
415
+ * error?: { message?: string } | string,
414
416
  * response?: import('../../protocol/src/types.js').BridgeResponse,
415
417
  * browserName?: string,
416
418
  * profileLabel?: string,
417
419
  * browserExtensionId?: string,
418
420
  * accessEnabled?: boolean,
421
+ * enabledWindow?: unknown,
422
+ * windowAccessUpdates?: boolean,
423
+ * windowActions?: boolean,
424
+ * action?: unknown,
425
+ * windowId?: unknown,
426
+ * enabledAt?: unknown,
427
+ * extensionId?: unknown,
428
+ * ok?: unknown,
419
429
  * authToken?: string,
420
430
  * at?: number
421
431
  * artifactId?: string,
@@ -466,6 +476,7 @@ export class BridgeDaemon {
466
476
  this.serverAddress = null;
467
477
  /** @type {Map<string, ClientSocket>} */
468
478
  this.extensionSockets = new Map();
479
+ this.windowActions = new WindowActionRouter(this.extensionSockets);
469
480
  /** @type {Map<string, ClientSocket>} */
470
481
  this.agentSockets = new Map();
471
482
  /** @type {Set<ClientSocket>} */
@@ -788,7 +799,9 @@ export class BridgeDaemon {
788
799
  if (typedSocket.destroyed) return;
789
800
  const message = /** @type {DaemonMessage} */ (raw);
790
801
  const admitted =
791
- message?.type === 'agent.request' || message?.type === 'extension.setup_status.request';
802
+ message?.type === 'agent.request' ||
803
+ message?.type === 'extension.setup_status.request' ||
804
+ message?.type === 'extension.window_action.request';
792
805
  const active = this.activeHandlers.get(typedSocket) ?? 0;
793
806
  if (
794
807
  admitted &&
@@ -882,6 +895,7 @@ export class BridgeDaemon {
882
895
  * @returns {Promise<void>}
883
896
  */
884
897
  async stopInternal() {
898
+ this.windowActions.clear();
885
899
  for (const pending of this.pendingRequests.values()) {
886
900
  clearTimeout(pending.timeoutId);
887
901
  }
@@ -978,6 +992,17 @@ export class BridgeDaemon {
978
992
  return this.handleExtensionAccessUpdate(socket, message);
979
993
  }
980
994
 
995
+ if (
996
+ message?.type === 'extension.window_action.request' ||
997
+ message?.type === 'extension.window_action.result'
998
+ ) {
999
+ if (socket.__role !== 'extension') return this.rejectMessageForRole(socket, message);
1000
+ if (message.type === 'extension.window_action.request')
1001
+ return this.windowActions.request(socket, message);
1002
+ this.windowActions.result(socket, message);
1003
+ return;
1004
+ }
1005
+
981
1006
  if (message?.type === 'extension.activity') {
982
1007
  if (socket.__role !== 'extension') {
983
1008
  return this.rejectMessageForRole(socket, message);
@@ -1380,6 +1405,7 @@ export class BridgeDaemon {
1380
1405
  if (target.__extensionId && this.extensionSockets.get(target.__extensionId) === target) {
1381
1406
  this.extensionSockets.delete(target.__extensionId);
1382
1407
  this.invalidateConnectedExtensionsCache();
1408
+ this.broadcastWindowAccess();
1383
1409
  }
1384
1410
  target.destroy(error instanceof Error ? error : undefined);
1385
1411
  await this.finishPendingRequestIfExhausted(request.id, pending);
@@ -1495,6 +1521,10 @@ export class BridgeDaemon {
1495
1521
  */
1496
1522
  handleExtensionIdentity(socket, message) {
1497
1523
  let changed = false;
1524
+ if (message.windowAccessUpdates === true) {
1525
+ socket.__windowAccessUpdates = true;
1526
+ }
1527
+ if (message.windowActions === true) socket.__windowActions = true;
1498
1528
  const browserName = normalizeRoutingLabel(message.browserName);
1499
1529
  if (browserName) {
1500
1530
  changed = changed || socket.__browserName !== browserName;
@@ -1513,6 +1543,7 @@ export class BridgeDaemon {
1513
1543
  if (changed) {
1514
1544
  this.invalidateConnectedExtensionsCache();
1515
1545
  }
1546
+ this.broadcastWindowAccess();
1516
1547
  }
1517
1548
 
1518
1549
  /**
@@ -1522,6 +1553,24 @@ export class BridgeDaemon {
1522
1553
  */
1523
1554
  handleExtensionAccessUpdate(socket, message) {
1524
1555
  const accessEnabled = Boolean(message.accessEnabled);
1556
+ const value = message.enabledWindow;
1557
+ const window =
1558
+ value && typeof value === 'object' ? /** @type {Record<string, unknown>} */ (value) : null;
1559
+ socket.__enabledWindow =
1560
+ accessEnabled &&
1561
+ window &&
1562
+ typeof window.windowId === 'number' &&
1563
+ Number.isInteger(window.windowId) &&
1564
+ window.windowId > 0 &&
1565
+ typeof window.title === 'string' &&
1566
+ typeof window.enabledAt === 'number' &&
1567
+ Number.isFinite(window.enabledAt)
1568
+ ? {
1569
+ windowId: window.windowId,
1570
+ title: sanitizeIncidentalText(window.title).slice(0, 200),
1571
+ enabledAt: window.enabledAt,
1572
+ }
1573
+ : null;
1525
1574
  if (!accessEnabled && socket.__extensionId) {
1526
1575
  this.artifactStore.deleteByExtension(socket.__extensionId);
1527
1576
  this.domBaselines.clearForSocket(socket);
@@ -1529,9 +1578,32 @@ export class BridgeDaemon {
1529
1578
  if (socket.__accessEnabled !== accessEnabled) {
1530
1579
  socket.__accessEnabled = accessEnabled;
1531
1580
  this.invalidateConnectedExtensionsCache();
1532
- return;
1533
1581
  }
1534
1582
  socket.__accessEnabled = accessEnabled;
1583
+ this.broadcastWindowAccess();
1584
+ }
1585
+
1586
+ /** Broadcast access metadata only to locally authenticated extension connections.
1587
+ * @returns {void}
1588
+ */
1589
+ broadcastWindowAccess() {
1590
+ /** @type {import('../../protocol/src/window-access.js').BrowserWindowAccess[]} */
1591
+ const enabledWindows = [...this.extensionSockets.entries()]
1592
+ .filter(([, socket]) => socket.__accessEnabled === true && !socket.destroyed)
1593
+ .map(([extensionId, socket]) => ({
1594
+ extensionId,
1595
+ browserName: socket.__browserName ?? null,
1596
+ profileLabel: socket.__profileLabel ?? null,
1597
+ window: socket.__enabledWindow ?? null,
1598
+ ...(socket.__windowActions ? { canControl: true } : {}),
1599
+ }));
1600
+ for (const [extensionId, socket] of this.extensionSockets) {
1601
+ if (socket.destroyed || !socket.__windowAccessUpdates) continue;
1602
+ void writeJsonLine(socket, {
1603
+ type: 'extension.window_access',
1604
+ otherEnabledWindows: enabledWindows.filter((window) => window.extensionId !== extensionId),
1605
+ }).catch(() => socket.destroy());
1606
+ }
1535
1607
  }
1536
1608
 
1537
1609
  /**
@@ -1787,6 +1859,7 @@ export class BridgeDaemon {
1787
1859
  * @returns {void}
1788
1860
  */
1789
1861
  handleSocketClose(socket) {
1862
+ this.windowActions.disconnect(socket);
1790
1863
  this.clientSockets.delete(socket);
1791
1864
  if (socket.__registrationTimeoutId) {
1792
1865
  clearTimeout(socket.__registrationTimeoutId);
@@ -1799,6 +1872,7 @@ export class BridgeDaemon {
1799
1872
  if (this.extensionSockets.get(socket.__extensionId) === socket) {
1800
1873
  this.extensionSockets.delete(socket.__extensionId);
1801
1874
  this.invalidateConnectedExtensionsCache();
1875
+ this.broadcastWindowAccess();
1802
1876
  }
1803
1877
  }
1804
1878
 
@@ -34,14 +34,17 @@ import { createNativeMessageReader, createNativeMessageWriter, writeJsonLine } f
34
34
  * type?: string,
35
35
  * browserName?: string,
36
36
  * profileLabel?: string,
37
- * browserExtensionId?: string
37
+ * browserExtensionId?: string,
38
+ * windowAccessUpdates?: boolean,
39
+ * windowActions?: boolean
38
40
  * }} HostIdentityMessage
39
41
  */
40
42
 
41
43
  /**
42
44
  * @typedef {{
43
45
  * type?: string,
44
- * accessEnabled: boolean
46
+ * accessEnabled: boolean,
47
+ * enabledWindow?: unknown
45
48
  * }} HostAccessUpdateMessage
46
49
  */
47
50
 
@@ -187,6 +190,23 @@ export async function runNativeHost({
187
190
  });
188
191
  return;
189
192
  }
193
+ if (message.type === 'extension.window_access') {
194
+ await writeNativeMessageQueued({
195
+ type: 'host.window_access',
196
+ otherEnabledWindows: message.otherEnabledWindows,
197
+ });
198
+ return;
199
+ }
200
+ if (
201
+ message.type === 'extension.window_action.command' ||
202
+ message.type === 'extension.window_action.response'
203
+ ) {
204
+ await writeNativeMessageQueued({
205
+ ...message,
206
+ type: message.type.replace(/^extension\./u, 'host.'),
207
+ });
208
+ return;
209
+ }
190
210
  if (
191
211
  message.type === 'extension.setup_status.response' ||
192
212
  message.type === 'extension.setup_status.error'
@@ -244,6 +264,8 @@ export async function runNativeHost({
244
264
  browserName: message.browserName,
245
265
  profileLabel: message.profileLabel,
246
266
  browserExtensionId: message.browserExtensionId,
267
+ ...(message.windowAccessUpdates === true ? { windowAccessUpdates: true } : {}),
268
+ ...(message.windowActions === true ? { windowActions: true } : {}),
247
269
  });
248
270
  return;
249
271
  }
@@ -251,6 +273,9 @@ export async function runNativeHost({
251
273
  await writeJsonLine(socket, {
252
274
  type: 'extension.access_update',
253
275
  accessEnabled: message.accessEnabled,
276
+ ...(message.enabledWindow !== undefined
277
+ ? { enabledWindow: message.enabledWindow }
278
+ : {}),
254
279
  });
255
280
  return;
256
281
  }
@@ -261,6 +286,19 @@ export async function runNativeHost({
261
286
  });
262
287
  return;
263
288
  }
289
+ if (message && typeof message === 'object') {
290
+ const record = /** @type {Record<string, unknown>} */ (message);
291
+ if (
292
+ record.type === 'host.window_action.request' ||
293
+ record.type === 'host.window_action.result'
294
+ ) {
295
+ await writeJsonLine(socket, {
296
+ ...record,
297
+ type: record.type.replace(/^host\./u, 'extension.'),
298
+ });
299
+ return;
300
+ }
301
+ }
264
302
  if (isHostArtifactMessage(message)) {
265
303
  const record = /** @type {Record<string, unknown>} */ (message);
266
304
  await writeJsonLine(socket, {
@@ -0,0 +1,115 @@
1
+ // @ts-check
2
+
3
+ import { randomUUID } from 'node:crypto';
4
+ import { sanitizeIncidentalText } from '../../protocol/src/index.js';
5
+ import { parseWindowActionRequest } from '../../protocol/src/window-actions.js';
6
+ import { writeJsonLine } from './framing.js';
7
+
8
+ /** @typedef {import('./daemon.js').ClientSocket} ClientSocket */
9
+ /** @typedef {{ source: ClientSocket, target: ClientSocket, finish: (error: string | null) => void }} PendingWindowAction */
10
+
11
+ /** Relay only user UI actions between authenticated local extensions. */
12
+ export class WindowActionRouter {
13
+ /** @param {Map<string, ClientSocket>} extensions */
14
+ constructor(extensions) {
15
+ this.extensions = extensions;
16
+ /** @type {Map<string, PendingWindowAction>} */
17
+ this.pending = new Map();
18
+ }
19
+
20
+ /**
21
+ * @param {ClientSocket} source
22
+ * @param {Record<string, unknown>} message
23
+ * @returns {Promise<void>}
24
+ */
25
+ async request(source, message) {
26
+ const request = parseWindowActionRequest(message);
27
+ const target = request ? this.extensions.get(request.extensionId) : null;
28
+ /** @type {string | null} */
29
+ let error = null;
30
+ if (
31
+ !request ||
32
+ source.__role !== 'extension' ||
33
+ !source.__windowActions ||
34
+ this.extensions.get(source.__extensionId ?? '') !== source
35
+ ) {
36
+ error = 'Invalid window action request.';
37
+ } else if (!target || target.destroyed || target === source) {
38
+ error = 'The other browser disconnected. Refresh the list and try again.';
39
+ } else if (!target.__windowActions || !target.__enabledWindow) {
40
+ error = "Update the other browser's extension and native host to control its window.";
41
+ } else if (
42
+ !target.__accessEnabled ||
43
+ target.__enabledWindow.windowId !== request.windowId ||
44
+ target.__enabledWindow.enabledAt !== request.enabledAt
45
+ ) {
46
+ error = 'Window access changed. Refresh the list and try again.';
47
+ } else if (
48
+ this.pending.size >= 64 ||
49
+ [...this.pending.values()].filter((entry) => entry.source === source).length >= 16
50
+ ) {
51
+ error = 'Too many window actions are pending. Try again shortly.';
52
+ } else {
53
+ const requestId = randomUUID();
54
+ error = await new Promise((resolve) => {
55
+ const timer = setTimeout(
56
+ () => finish('The other browser did not respond. Try again.'),
57
+ 5_000
58
+ );
59
+ /** @param {string | null} failure */
60
+ const finish = (failure) => {
61
+ if (!this.pending.delete(requestId)) return;
62
+ clearTimeout(timer);
63
+ resolve(failure);
64
+ };
65
+ this.pending.set(requestId, { source, target, finish });
66
+ void writeJsonLine(target, {
67
+ type: 'extension.window_action.command',
68
+ ...request,
69
+ requestId,
70
+ }).catch(() => finish('The other browser disconnected. Try again.'));
71
+ });
72
+ }
73
+ if (!source.destroyed) {
74
+ await writeJsonLine(source, {
75
+ type: 'extension.window_action.response',
76
+ requestId:
77
+ request?.requestId ??
78
+ (typeof message.requestId === 'string' ? message.requestId.slice(0, 80) : 'invalid'),
79
+ ok: error === null,
80
+ ...(error ? { error } : {}),
81
+ });
82
+ }
83
+ }
84
+
85
+ /**
86
+ * @param {ClientSocket} source
87
+ * @param {Record<string, unknown>} message
88
+ * @returns {void}
89
+ */
90
+ result(source, message) {
91
+ const pending =
92
+ typeof message.requestId === 'string' ? this.pending.get(message.requestId) : null;
93
+ if (!pending || pending.target !== source) return;
94
+ pending.finish(
95
+ message.ok === true
96
+ ? null
97
+ : typeof message.error === 'string'
98
+ ? sanitizeIncidentalText(message.error).slice(0, 200) || 'Window action failed.'
99
+ : 'Window action failed.'
100
+ );
101
+ }
102
+
103
+ /** @param {ClientSocket} socket @returns {void} */
104
+ disconnect(socket) {
105
+ for (const pending of this.pending.values()) {
106
+ if (pending.source === socket || pending.target === socket)
107
+ pending.finish('The browser disconnected. Try again.');
108
+ }
109
+ }
110
+
111
+ /** @returns {void} */
112
+ clear() {
113
+ for (const pending of this.pending.values()) pending.finish('The daemon stopped. Try again.');
114
+ }
115
+ }
@@ -0,0 +1,29 @@
1
+ /** Window access metadata shared by the native relay and extension UI. */
2
+ export type EnabledWindowInfo = {
3
+ windowId: number;
4
+ title: string;
5
+ enabledAt: number;
6
+ };
7
+
8
+ export type BrowserWindowAccess = {
9
+ extensionId: string;
10
+ browserName: string | null;
11
+ profileLabel: string | null;
12
+ window: EnabledWindowInfo | null;
13
+ canControl?: boolean;
14
+ };
15
+
16
+ /** Local extension UI actions. These are not agent RPC methods. */
17
+ export type WindowAction = 'focus' | 'disable';
18
+
19
+ export type WindowActionCommand = {
20
+ requestId: string;
21
+ action: WindowAction;
22
+ windowId: number;
23
+ enabledAt: number;
24
+ };
25
+
26
+ export type WindowActionRequest = WindowActionCommand & { extensionId: string };
27
+
28
+ export type WindowActionResult = { requestId: string; ok: boolean; error?: string };
29
+ export type WindowActionUiResult = { action: WindowAction; ok: boolean; error?: string };
@@ -0,0 +1,46 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @param {unknown} value
5
+ * @returns {import('./window-access.js').WindowActionCommand | null}
6
+ */
7
+ export function parseWindowActionCommand(value) {
8
+ if (!value || typeof value !== 'object') return null;
9
+ const message = /** @type {Record<string, unknown>} */ (value);
10
+ if (
11
+ typeof message.requestId !== 'string' ||
12
+ !message.requestId ||
13
+ message.requestId.length > 80 ||
14
+ (message.action !== 'focus' && message.action !== 'disable') ||
15
+ typeof message.windowId !== 'number' ||
16
+ !Number.isSafeInteger(message.windowId) ||
17
+ message.windowId <= 0 ||
18
+ typeof message.enabledAt !== 'number' ||
19
+ !Number.isFinite(message.enabledAt) ||
20
+ message.enabledAt < 0
21
+ )
22
+ return null;
23
+ return {
24
+ requestId: message.requestId,
25
+ action: message.action,
26
+ windowId: message.windowId,
27
+ enabledAt: message.enabledAt,
28
+ };
29
+ }
30
+
31
+ /**
32
+ * @param {unknown} value
33
+ * @returns {import('./window-access.js').WindowActionRequest | null}
34
+ */
35
+ export function parseWindowActionRequest(value) {
36
+ const command = parseWindowActionCommand(value);
37
+ if (!command) return null;
38
+ const message = /** @type {Record<string, unknown>} */ (value);
39
+ if (
40
+ typeof message.extensionId !== 'string' ||
41
+ !message.extensionId ||
42
+ message.extensionId.length > 80
43
+ )
44
+ return null;
45
+ return { ...command, extensionId: message.extensionId };
46
+ }