@jobshimo/browser-link 0.21.0 → 0.23.0
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 +5 -0
- package/dist/agent-instructions/content.js +11 -0
- package/dist/agent-instructions/content.js.map +1 -1
- package/dist/bridge/events.d.ts +1 -1
- package/dist/bridge/events.js +6 -1
- package/dist/bridge/events.js.map +1 -1
- package/dist/bridge/ipc-client.d.ts +6 -7
- package/dist/bridge/ipc-client.js +4 -3
- package/dist/bridge/ipc-client.js.map +1 -1
- package/dist/bridge/protocol.d.ts +28 -16
- package/dist/bridge/protocol.js +23 -7
- package/dist/bridge/protocol.js.map +1 -1
- package/dist/bridge/server.d.ts +8 -10
- package/dist/bridge/server.js.map +1 -1
- package/dist/bridge/ws-bridge.d.ts +53 -18
- package/dist/bridge/ws-bridge.js +129 -21
- package/dist/bridge/ws-bridge.js.map +1 -1
- package/dist/cdp/client.d.ts +35 -0
- package/dist/cdp/client.js +149 -0
- package/dist/cdp/client.js.map +1 -0
- package/dist/cdp/flow.d.ts +178 -0
- package/dist/cdp/flow.js +217 -0
- package/dist/cdp/flow.js.map +1 -0
- package/dist/cdp/gate.d.ts +31 -0
- package/dist/cdp/gate.js +35 -0
- package/dist/cdp/gate.js.map +1 -0
- package/dist/cdp/grant.d.ts +45 -0
- package/dist/cdp/grant.js +81 -0
- package/dist/cdp/grant.js.map +1 -0
- package/dist/cdp/inpage/builders.d.ts +165 -0
- package/dist/cdp/inpage/builders.js +501 -0
- package/dist/cdp/inpage/builders.js.map +1 -0
- package/dist/cdp/inpage/deep-query.d.ts +57 -0
- package/dist/cdp/inpage/deep-query.js +325 -0
- package/dist/cdp/inpage/deep-query.js.map +1 -0
- package/dist/cdp/inpage/dom-helpers.d.ts +27 -0
- package/dist/cdp/inpage/dom-helpers.js +147 -0
- package/dist/cdp/inpage/dom-helpers.js.map +1 -0
- package/dist/cdp/keymap.d.ts +83 -0
- package/dist/cdp/keymap.js +205 -0
- package/dist/cdp/keymap.js.map +1 -0
- package/dist/cdp/settle.d.ts +38 -0
- package/dist/cdp/settle.js +76 -0
- package/dist/cdp/settle.js.map +1 -0
- package/dist/cdp/support.d.ts +26 -0
- package/dist/cdp/support.js +58 -0
- package/dist/cdp/support.js.map +1 -0
- package/dist/cdp/targets.d.ts +54 -0
- package/dist/cdp/targets.js +176 -0
- package/dist/cdp/targets.js.map +1 -0
- package/dist/cdp/transport.d.ts +31 -0
- package/dist/cdp/transport.js +531 -0
- package/dist/cdp/transport.js.map +1 -0
- package/dist/cli.js +64 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/about.js +13 -0
- package/dist/commands/about.js.map +1 -1
- package/dist/commands/cdp.d.ts +28 -0
- package/dist/commands/cdp.js +172 -0
- package/dist/commands/cdp.js.map +1 -0
- package/dist/commands/config.d.ts +97 -0
- package/dist/commands/config.js +228 -13
- package/dist/commands/config.js.map +1 -1
- package/dist/config.d.ts +89 -0
- package/dist/config.js +94 -1
- package/dist/config.js.map +1 -1
- package/dist/extension/background.js +424 -1
- package/dist/extension/background.js.map +1 -1
- package/dist/extension/flow-recording-policy.d.ts +47 -0
- package/dist/extension/flow-recording-policy.js +54 -0
- package/dist/extension/flow-recording-policy.js.map +1 -0
- package/dist/extension/inpage/recorder.d.ts +35 -0
- package/dist/extension/inpage/recorder.js +333 -0
- package/dist/extension/inpage/recorder.js.map +1 -0
- package/dist/extension/manifest.json +1 -1
- package/dist/extension/popup.html +56 -0
- package/dist/extension/popup.js +195 -4
- package/dist/extension/popup.js.map +1 -1
- package/dist/extension/recording.d.ts +158 -0
- package/dist/extension/recording.js +214 -0
- package/dist/extension/recording.js.map +1 -0
- package/dist/messages.d.ts +53 -12
- package/dist/server.js +9 -0
- package/dist/server.js.map +1 -1
- package/dist/tools/browser-definitions.js +4 -3
- package/dist/tools/browser-definitions.js.map +1 -1
- package/dist/tools/browser-dispatch.d.ts +31 -0
- package/dist/tools/browser-dispatch.js +88 -40
- package/dist/tools/browser-dispatch.js.map +1 -1
- package/dist/tools/server-instructions.js +19 -0
- package/dist/tools/server-instructions.js.map +1 -1
- package/package.json +1 -1
package/dist/bridge/ws-bridge.js
CHANGED
|
@@ -4,6 +4,8 @@ import { lookupPeerProcess } from '../auth/process-identity.js';
|
|
|
4
4
|
import { VERSION } from '../version.js';
|
|
5
5
|
import { isExtensionEventKind } from './events.js';
|
|
6
6
|
import { loadConfig } from '../config.js';
|
|
7
|
+
import { saveFlow } from '../map/queries.js';
|
|
8
|
+
import { validateFlowSteps } from '../tools/browser-dispatch.js';
|
|
7
9
|
export const WS_HOST = '127.0.0.1';
|
|
8
10
|
export const WS_PORT = 17529;
|
|
9
11
|
function log(msg) {
|
|
@@ -201,6 +203,24 @@ export function startWsBridge(tabs, pendingRequests, events) {
|
|
|
201
203
|
events.add(msg.eventKind, data);
|
|
202
204
|
return;
|
|
203
205
|
}
|
|
206
|
+
if (msg.kind === 'flow.recorded') {
|
|
207
|
+
// Defense in depth: the payload names the tab it came from, but a
|
|
208
|
+
// connection may only save flows FOR ITSELF. Reject a mismatch
|
|
209
|
+
// (or a save before this connection registered a tab) so the
|
|
210
|
+
// `flow-recorded` event log entry's tab_id is trustworthy and one
|
|
211
|
+
// tab cannot attribute a recipe to another. `assignedTabId` is
|
|
212
|
+
// the id THIS socket registered under (set in the tab.register
|
|
213
|
+
// handler above).
|
|
214
|
+
const result = assignedTabId && msg.payload.tab_id === assignedTabId
|
|
215
|
+
? handleFlowRecordedMessage(msg.payload, events)
|
|
216
|
+
: {
|
|
217
|
+
kind: 'flow.recorded.result',
|
|
218
|
+
ok: false,
|
|
219
|
+
error: 'flow.recorded: tab_id does not match this connection',
|
|
220
|
+
};
|
|
221
|
+
send(ws, result);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
204
224
|
});
|
|
205
225
|
ws.on('close', () => {
|
|
206
226
|
if (assignedTabId) {
|
|
@@ -217,37 +237,44 @@ export function startWsBridge(tabs, pendingRequests, events) {
|
|
|
217
237
|
}
|
|
218
238
|
/**
|
|
219
239
|
* Build the `settings.update` a freshly-registered tab should receive, or
|
|
220
|
-
* `null` when nothing should be sent. `idleTtlMinutes`
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
240
|
+
* `null` when nothing should be sent. Each of `idleTtlMinutes` and
|
|
241
|
+
* `flowRecordingEnabled` independently stays undefined in config.json until
|
|
242
|
+
* its own `browser-link config set` command runs at least once — a
|
|
243
|
+
* popup-only user (who never touched the CLI) never gets an unsolicited
|
|
244
|
+
* settings.update overwriting their own popup choice for that setting.
|
|
245
|
+
* Note idle-ttl's `0` ("never") and flow-recording's `false` ("off") ARE
|
|
246
|
+
* real values and MUST push — only `undefined` suppresses a given pair, and
|
|
247
|
+
* the two pairs are independent (a message can carry one, the other, or
|
|
248
|
+
* both). See messages.ts's SettingsUpdatePayload doc for the newest-wins
|
|
226
249
|
* precedence rule the extension applies on receipt. Exported so the
|
|
227
250
|
* register-path push is unit-testable without binding the fixed WS port.
|
|
228
251
|
*/
|
|
229
252
|
export function buildRegisterSettingsUpdate(cfg) {
|
|
230
|
-
|
|
253
|
+
const settings = {};
|
|
254
|
+
if (cfg.idleTtlMinutes !== undefined) {
|
|
255
|
+
settings.idleTtlMinutes = cfg.idleTtlMinutes;
|
|
256
|
+
settings.updatedAt = cfg.idleTtlUpdatedAt ?? 0;
|
|
257
|
+
}
|
|
258
|
+
if (cfg.flowRecordingEnabled !== undefined) {
|
|
259
|
+
settings.flowRecordingEnabled = cfg.flowRecordingEnabled;
|
|
260
|
+
settings.flowRecordingUpdatedAt = cfg.flowRecordingUpdatedAt ?? 0;
|
|
261
|
+
}
|
|
262
|
+
if (Object.keys(settings).length === 0)
|
|
231
263
|
return null;
|
|
232
|
-
return {
|
|
233
|
-
kind: 'settings.update',
|
|
234
|
-
settings: {
|
|
235
|
-
idleTtlMinutes: cfg.idleTtlMinutes,
|
|
236
|
-
updatedAt: cfg.idleTtlUpdatedAt ?? 0,
|
|
237
|
-
},
|
|
238
|
-
};
|
|
264
|
+
return { kind: 'settings.update', settings };
|
|
239
265
|
}
|
|
240
266
|
/**
|
|
241
267
|
* Push a `settings.update` to every currently-connected extension tab.
|
|
242
268
|
* Called from the IPC bridge's `settings.push` handler (see
|
|
243
269
|
* `bridge/server.ts`'s `pushSettings` option) when `browser-link config set
|
|
244
|
-
* idle-ttl` runs while a primary is already
|
|
245
|
-
* connected" half of the precedence contract;
|
|
246
|
-
* lives inline in `startWsBridge`'s
|
|
247
|
-
* `buildRegisterSettingsUpdate`), since a
|
|
248
|
-
* already gets the fresh value from
|
|
249
|
-
* tabs were sent the update, so the
|
|
250
|
-
* than "done" (e.g. "0 tabs
|
|
270
|
+
* idle-ttl` / `config set flow-recording` runs while a primary is already
|
|
271
|
+
* up — the "on demand, while connected" half of the precedence contract;
|
|
272
|
+
* the "on (re)connect" half lives inline in `startWsBridge`'s
|
|
273
|
+
* `tab.register` handler above (via `buildRegisterSettingsUpdate`), since a
|
|
274
|
+
* tab that connects AFTER this push already gets the fresh value from
|
|
275
|
+
* config.json directly. Returns how many tabs were sent the update, so the
|
|
276
|
+
* CLI can report something more useful than "done" (e.g. "0 tabs
|
|
277
|
+
* connected — applies next time one connects").
|
|
251
278
|
*/
|
|
252
279
|
export function pushSettingsToAllTabs(tabs, settings) {
|
|
253
280
|
let notified = 0;
|
|
@@ -259,6 +286,87 @@ export function pushSettingsToAllTabs(tabs, settings) {
|
|
|
259
286
|
}
|
|
260
287
|
return notified;
|
|
261
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Validate + persist a `flow.recorded` message from the extension (see the
|
|
291
|
+
* extension's `background.ts`'s `saveRecording`) and build the
|
|
292
|
+
* `flow.recorded.result` reply. Exported so it is unit-testable directly,
|
|
293
|
+
* without binding the fixed WS port — same rationale as
|
|
294
|
+
* `buildRegisterSettingsUpdate` above.
|
|
295
|
+
*
|
|
296
|
+
* `steps` is validated with the EXACT same `validateFlowSteps` rules
|
|
297
|
+
* `browser.flow` and `browser.map.save`'s `flows` array enforce — an
|
|
298
|
+
* invalid recording (over the step cap, a malformed step, an over-budget
|
|
299
|
+
* wait_for) is rejected here with the same actionable error message an
|
|
300
|
+
* agent would see from `browser.flow`, sent back to the popup so the user
|
|
301
|
+
* knows WHY the save failed rather than it silently vanishing.
|
|
302
|
+
* `origin` is untrusted free text from the extension and is canonicalized
|
|
303
|
+
* the normal way (`saveFlow` -> `upsertApp` -> `canonicalOrigin`), exactly
|
|
304
|
+
* like every other write path into the map.
|
|
305
|
+
*
|
|
306
|
+
* On success, emits a SERVER-OWNED `flow-recorded` bridge event (see
|
|
307
|
+
* `events.ts` — this kind is deliberately absent from
|
|
308
|
+
* `EXTENSION_EVENT_KINDS`, so it can only ever be produced by a recording
|
|
309
|
+
* that actually passed validation and landed in the map, never spoofed via
|
|
310
|
+
* a raw `bridge.event`) so `browser.events` surfaces the new recipe to any
|
|
311
|
+
* agent watching, per the mission's "agents notice new recipes" requirement.
|
|
312
|
+
*/
|
|
313
|
+
/** Length caps on the free-text fields of a recorded flow — consistent
|
|
314
|
+
* with the selector cap on the recorder side and the map's general "store
|
|
315
|
+
* UI structure, not blobs" posture. Generous enough for any real recipe
|
|
316
|
+
* name / caution note, small enough that the channel cannot be used to
|
|
317
|
+
* park large payloads in the map DB. */
|
|
318
|
+
export const MAX_FLOW_NAME_LENGTH = 200;
|
|
319
|
+
export const MAX_FLOW_DESCRIPTION_LENGTH = 2000;
|
|
320
|
+
export function handleFlowRecordedMessage(payload, events) {
|
|
321
|
+
const name = typeof payload.name === 'string' ? payload.name.trim() : '';
|
|
322
|
+
if (name.length === 0) {
|
|
323
|
+
return { kind: 'flow.recorded.result', ok: false, error: 'flow.recorded: name is required' };
|
|
324
|
+
}
|
|
325
|
+
if (name.length > MAX_FLOW_NAME_LENGTH) {
|
|
326
|
+
return {
|
|
327
|
+
kind: 'flow.recorded.result',
|
|
328
|
+
ok: false,
|
|
329
|
+
error: `flow.recorded: name exceeds ${MAX_FLOW_NAME_LENGTH} characters`,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
if (payload.description !== undefined &&
|
|
333
|
+
(typeof payload.description !== 'string' ||
|
|
334
|
+
payload.description.length > MAX_FLOW_DESCRIPTION_LENGTH)) {
|
|
335
|
+
return {
|
|
336
|
+
kind: 'flow.recorded.result',
|
|
337
|
+
ok: false,
|
|
338
|
+
error: `flow.recorded: description must be a string of at most ${MAX_FLOW_DESCRIPTION_LENGTH} characters`,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
const validated = validateFlowSteps(payload.steps);
|
|
342
|
+
if (!validated.ok) {
|
|
343
|
+
return { kind: 'flow.recorded.result', ok: false, error: `flow.recorded: ${validated.error}` };
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
const { app, flow } = saveFlow({
|
|
347
|
+
origin: payload.origin,
|
|
348
|
+
name,
|
|
349
|
+
description: payload.description ?? null,
|
|
350
|
+
steps: validated.steps,
|
|
351
|
+
});
|
|
352
|
+
events.add('flow-recorded', {
|
|
353
|
+
tab_id: payload.tab_id,
|
|
354
|
+
app_key: app.app_key,
|
|
355
|
+
origin: app.origin,
|
|
356
|
+
name: flow.name,
|
|
357
|
+
step_count: validated.steps.length,
|
|
358
|
+
});
|
|
359
|
+
return { kind: 'flow.recorded.result', ok: true, name: flow.name };
|
|
360
|
+
}
|
|
361
|
+
catch (err) {
|
|
362
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
363
|
+
return {
|
|
364
|
+
kind: 'flow.recorded.result',
|
|
365
|
+
ok: false,
|
|
366
|
+
error: `flow.recorded: could not save — ${message}`,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}
|
|
262
370
|
/** Build the callback that sends a tool.request frame to a specific tab and
|
|
263
371
|
* resolves with the matching tool.response (or rejects on timeout). Kept here
|
|
264
372
|
* because it touches the same `tabs` / `pendingRequests` maps the bridge
|
|
@@ -1 +1 @@
|
|
|
1
|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AAC;IACD,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9B,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAC3B,MAAM,CAAC,IAAI,KAAK,CAAC,SAAS,IAAI,qBAAqB,SAAS,IAAI,CAAC,CAAC,CAAC;QACrE,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QACtD,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type CdpEventHandler = (params: unknown) => void;
|
|
2
|
+
export interface CdpClientOptions {
|
|
3
|
+
/** How long `connect()` waits for the WS handshake before giving up.
|
|
4
|
+
* Default 5s — a local loopback connection should be near-instant; a
|
|
5
|
+
* long default here would make a dead/stale target hang tool calls. */
|
|
6
|
+
connectTimeoutMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class CdpClient {
|
|
9
|
+
private readonly url;
|
|
10
|
+
private readonly options;
|
|
11
|
+
private ws;
|
|
12
|
+
private nextId;
|
|
13
|
+
private readonly pending;
|
|
14
|
+
private readonly eventHandlers;
|
|
15
|
+
private closed;
|
|
16
|
+
constructor(url: string, options?: CdpClientOptions);
|
|
17
|
+
/** Open the WebSocket and wait for it to be ready. Rejects on a bind
|
|
18
|
+
* failure or on timeout — never leaves the caller waiting forever on a
|
|
19
|
+
* target that vanished between discovery and connect. */
|
|
20
|
+
connect(): Promise<void>;
|
|
21
|
+
private handleMessage;
|
|
22
|
+
private handleClose;
|
|
23
|
+
/** Whether the underlying WebSocket is open and this client has not been
|
|
24
|
+
* explicitly closed. Used by the transport's connection cache to decide
|
|
25
|
+
* whether a cached client is still worth reusing. */
|
|
26
|
+
get isOpen(): boolean;
|
|
27
|
+
/** Send one CDP command and wait for its matching response. */
|
|
28
|
+
send<T = unknown>(method: string, params?: Record<string, unknown>, timeoutMs?: number): Promise<T>;
|
|
29
|
+
/** Subscribe to a CDP event by method name (e.g. `Page.loadEventFired`).
|
|
30
|
+
* Returns an unsubscribe function. Multiple handlers for the same method
|
|
31
|
+
* may be registered independently. */
|
|
32
|
+
on(method: string, handler: CdpEventHandler): () => void;
|
|
33
|
+
close(): void;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { WebSocket } from 'ws';
|
|
2
|
+
function frameToText(raw) {
|
|
3
|
+
if (typeof raw === 'string')
|
|
4
|
+
return raw;
|
|
5
|
+
if (Buffer.isBuffer(raw))
|
|
6
|
+
return raw.toString('utf8');
|
|
7
|
+
if (Array.isArray(raw))
|
|
8
|
+
return Buffer.concat(raw).toString('utf8');
|
|
9
|
+
return Buffer.from(raw).toString('utf8');
|
|
10
|
+
}
|
|
11
|
+
export class CdpClient {
|
|
12
|
+
url;
|
|
13
|
+
options;
|
|
14
|
+
ws = null;
|
|
15
|
+
nextId = 1;
|
|
16
|
+
pending = new Map();
|
|
17
|
+
eventHandlers = new Map();
|
|
18
|
+
closed = false;
|
|
19
|
+
constructor(url, options = {}) {
|
|
20
|
+
this.url = url;
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
/** Open the WebSocket and wait for it to be ready. Rejects on a bind
|
|
24
|
+
* failure or on timeout — never leaves the caller waiting forever on a
|
|
25
|
+
* target that vanished between discovery and connect. */
|
|
26
|
+
connect() {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
let settled = false;
|
|
29
|
+
const ws = new WebSocket(this.url);
|
|
30
|
+
const timeoutMs = this.options.connectTimeoutMs ?? 5_000;
|
|
31
|
+
const timer = setTimeout(() => {
|
|
32
|
+
if (settled)
|
|
33
|
+
return;
|
|
34
|
+
settled = true;
|
|
35
|
+
ws.terminate();
|
|
36
|
+
reject(new Error(`cdp-direct: connection to ${this.url} timed out after ${timeoutMs}ms`));
|
|
37
|
+
}, timeoutMs);
|
|
38
|
+
ws.once('open', () => {
|
|
39
|
+
if (settled)
|
|
40
|
+
return;
|
|
41
|
+
settled = true;
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
this.ws = ws;
|
|
44
|
+
resolve();
|
|
45
|
+
});
|
|
46
|
+
ws.once('error', (err) => {
|
|
47
|
+
if (settled)
|
|
48
|
+
return;
|
|
49
|
+
settled = true;
|
|
50
|
+
clearTimeout(timer);
|
|
51
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
52
|
+
});
|
|
53
|
+
ws.on('message', (raw) => {
|
|
54
|
+
this.handleMessage(raw);
|
|
55
|
+
});
|
|
56
|
+
ws.on('close', () => {
|
|
57
|
+
this.handleClose();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
handleMessage(raw) {
|
|
62
|
+
let msg;
|
|
63
|
+
try {
|
|
64
|
+
msg = JSON.parse(frameToText(raw));
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (typeof msg.id === 'number') {
|
|
70
|
+
const pending = this.pending.get(msg.id);
|
|
71
|
+
if (!pending)
|
|
72
|
+
return;
|
|
73
|
+
this.pending.delete(msg.id);
|
|
74
|
+
if (msg.error) {
|
|
75
|
+
pending.reject(new Error(msg.error.message ?? 'CDP command failed'));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
pending.resolve(msg.result);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (typeof msg.method === 'string') {
|
|
83
|
+
const handlers = this.eventHandlers.get(msg.method);
|
|
84
|
+
if (handlers)
|
|
85
|
+
for (const handler of handlers)
|
|
86
|
+
handler(msg.params);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
handleClose() {
|
|
90
|
+
this.closed = true;
|
|
91
|
+
const err = new Error('cdp-direct: connection closed');
|
|
92
|
+
for (const pending of this.pending.values())
|
|
93
|
+
pending.reject(err);
|
|
94
|
+
this.pending.clear();
|
|
95
|
+
}
|
|
96
|
+
/** Whether the underlying WebSocket is open and this client has not been
|
|
97
|
+
* explicitly closed. Used by the transport's connection cache to decide
|
|
98
|
+
* whether a cached client is still worth reusing. */
|
|
99
|
+
get isOpen() {
|
|
100
|
+
return !this.closed && this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
101
|
+
}
|
|
102
|
+
/** Send one CDP command and wait for its matching response. */
|
|
103
|
+
send(method, params = {}, timeoutMs = 15_000) {
|
|
104
|
+
if (!this.ws || this.closed) {
|
|
105
|
+
return Promise.reject(new Error('cdp-direct: client is not connected'));
|
|
106
|
+
}
|
|
107
|
+
const id = this.nextId++;
|
|
108
|
+
const ws = this.ws;
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const timer = setTimeout(() => {
|
|
111
|
+
this.pending.delete(id);
|
|
112
|
+
reject(new Error(`cdp-direct: command "${method}" timed out after ${timeoutMs}ms`));
|
|
113
|
+
}, timeoutMs);
|
|
114
|
+
this.pending.set(id, {
|
|
115
|
+
resolve: (value) => {
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
resolve(value);
|
|
118
|
+
},
|
|
119
|
+
reject: (err) => {
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
reject(err);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
ws.send(JSON.stringify({ id, method, params }));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/** Subscribe to a CDP event by method name (e.g. `Page.loadEventFired`).
|
|
128
|
+
* Returns an unsubscribe function. Multiple handlers for the same method
|
|
129
|
+
* may be registered independently. */
|
|
130
|
+
on(method, handler) {
|
|
131
|
+
let set = this.eventHandlers.get(method);
|
|
132
|
+
if (!set) {
|
|
133
|
+
set = new Set();
|
|
134
|
+
this.eventHandlers.set(method, set);
|
|
135
|
+
}
|
|
136
|
+
set.add(handler);
|
|
137
|
+
return () => set.delete(handler);
|
|
138
|
+
}
|
|
139
|
+
close() {
|
|
140
|
+
this.closed = true;
|
|
141
|
+
try {
|
|
142
|
+
this.ws?.close();
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
/* best effort */
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/cdp/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAmC/B,SAAS,WAAW,CAAC,GAAY;IAC/B,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACtD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,GAAe,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/E,OAAO,MAAM,CAAC,IAAI,CAAC,GAAkB,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,OAAO,SAAS;IAQD;IACA;IARX,EAAE,GAAqB,IAAI,CAAC;IAC5B,MAAM,GAAG,CAAC,CAAC;IACF,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IACzC,aAAa,GAAG,IAAI,GAAG,EAAgC,CAAC;IACjE,MAAM,GAAG,KAAK,CAAC;IAEvB,YACmB,GAAW,EACX,UAA4B,EAAE;QAD9B,QAAG,GAAH,GA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AK,EAAE,EAAE;oBACjB,YAAY,CAAC,KAAK,CAAC,CAAC;oBACpB,OAAO,CAAC,KAAU,CAAC,CAAC;gBACtB,CAAC;gBACD,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;oBACd,YAAY,CAAC,KAAK,CAAC,CAAC;oBACpB,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,CAAC;aACF,CAAC,CAAC;YACH,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;0CAEsC;IACtC,EAAE,CAAC,MAAc,EAAE,OAAwB;QACzC,IAAI,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;YAChB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACtC,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACjB,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC;YACH,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;QAAC,MAAM,CAAC;YACP,iBAAiB;QACnB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Independent copy of `packages/extension/src/flow.ts` — see
|
|
3
|
+
* `inpage/deep-query.ts`'s header comment for why this package duplicates
|
|
4
|
+
* rather than imports extension-side modules. Byte-identical logic, so
|
|
5
|
+
* `browser.flow` behaves identically whether the target tab is reached
|
|
6
|
+
* through the extension or through cdp-direct. Kept transport-agnostic ON
|
|
7
|
+
* PURPOSE — it does NOT re-check the cdp-direct gate per step; a mid-flow
|
|
8
|
+
* `cdp revoke` is grandfathered until the flow finishes (bounded ≤60s by
|
|
9
|
+
* the flow budget), documented in the README's cdp-direct section.
|
|
10
|
+
* `cdp/drift.test.ts` asserts `MAX_FLOW_STEPS` stays in lockstep with the
|
|
11
|
+
* sibling at `packages/extension/src/flow.ts`.
|
|
12
|
+
*
|
|
13
|
+
* browser.flow step sequencing — the logic behind the composite action
|
|
14
|
+
* tool. Runs a short, declarative list of find/click/type/press/wait_for
|
|
15
|
+
* steps strictly in order, fails fast on the first step that does not
|
|
16
|
+
* succeed, and threads an "implicit target" from a `find` step into the
|
|
17
|
+
* very next click/type/press step that omits its own `selector`.
|
|
18
|
+
*
|
|
19
|
+
* Deliberately decoupled from any transport: every side effect goes
|
|
20
|
+
* through the `FlowDeps` the caller injects. `cdp/transport.ts` wires the
|
|
21
|
+
* real perform* functions (already closed over the CDP client); tests wire
|
|
22
|
+
* fakes. This is what makes the sequencing logic — step-shape validation,
|
|
23
|
+
* implicit-target threading, fail-fast, result shaping — unit-testable
|
|
24
|
+
* without a real Chrome target.
|
|
25
|
+
*/
|
|
26
|
+
/** Structured success/failure outcome shared by every perform* function in
|
|
27
|
+
* `cdp/transport.ts`. `ok:false` carries the exact same error string the
|
|
28
|
+
* standalone tool.response would have returned for that failure — both the
|
|
29
|
+
* thin case wrappers and this module's step executor consume this shape,
|
|
30
|
+
* so the two call paths can never drift. */
|
|
31
|
+
export type ActionOutcome<T> = {
|
|
32
|
+
ok: true;
|
|
33
|
+
result: T;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
error: string;
|
|
37
|
+
};
|
|
38
|
+
/** Hard cap on steps per flow — mirrors the `maxItems: 20` on the MCP
|
|
39
|
+
* schema (`browser-definitions.ts`) and the server-side validation
|
|
40
|
+
* (`browser-dispatch.ts`). Enforced again here so cdp-direct never runs an
|
|
41
|
+
* oversized flow even if a future caller bypasses the server's own check. */
|
|
42
|
+
export declare const MAX_FLOW_STEPS = 20;
|
|
43
|
+
export interface FindStepParams {
|
|
44
|
+
text: string;
|
|
45
|
+
role?: string;
|
|
46
|
+
exact?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface FindStepResult {
|
|
49
|
+
matched: boolean;
|
|
50
|
+
reason?: string;
|
|
51
|
+
candidates?: {
|
|
52
|
+
selector: string;
|
|
53
|
+
text: string;
|
|
54
|
+
tag: string;
|
|
55
|
+
}[];
|
|
56
|
+
/** Up to 3 near-miss candidates on a `not-found` result — see
|
|
57
|
+
* `buildFindJs` in `inpage/builders.ts` for the ranking rules. Not
|
|
58
|
+
* consumed by `runFlow` today (the flow failure message stays as-is);
|
|
59
|
+
* carried through so a future caller of the raw `performFind` outcome
|
|
60
|
+
* (or a richer flow error message) can use it without a shape change. */
|
|
61
|
+
near_misses?: {
|
|
62
|
+
text: string;
|
|
63
|
+
selector: string;
|
|
64
|
+
role?: string;
|
|
65
|
+
}[];
|
|
66
|
+
/** Human-readable detail on a `not-found` result — currently only set
|
|
67
|
+
* when `role` excluded matches that existed under a broader scan. */
|
|
68
|
+
error?: string;
|
|
69
|
+
selector?: string;
|
|
70
|
+
ambiguous?: boolean;
|
|
71
|
+
tag?: string;
|
|
72
|
+
text?: string;
|
|
73
|
+
coords?: {
|
|
74
|
+
x: number;
|
|
75
|
+
y: number;
|
|
76
|
+
};
|
|
77
|
+
frame?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface ClickStepParams {
|
|
80
|
+
selector?: string;
|
|
81
|
+
force?: boolean;
|
|
82
|
+
settle_ms?: number;
|
|
83
|
+
}
|
|
84
|
+
export interface ClickStepResult {
|
|
85
|
+
clicked: string;
|
|
86
|
+
tag: string;
|
|
87
|
+
settle?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
export interface TypeStepParams {
|
|
90
|
+
selector?: string;
|
|
91
|
+
text: string;
|
|
92
|
+
clear?: boolean;
|
|
93
|
+
settle_ms?: number;
|
|
94
|
+
}
|
|
95
|
+
export interface TypeStepResult {
|
|
96
|
+
typed: number;
|
|
97
|
+
selector?: string;
|
|
98
|
+
settle?: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
export interface PressStepParams {
|
|
101
|
+
key: string;
|
|
102
|
+
modifiers?: string[];
|
|
103
|
+
selector?: string;
|
|
104
|
+
settle_ms?: number;
|
|
105
|
+
}
|
|
106
|
+
export interface PressStepResult {
|
|
107
|
+
key: string;
|
|
108
|
+
modifiers: string[];
|
|
109
|
+
settle?: Record<string, unknown>;
|
|
110
|
+
}
|
|
111
|
+
export interface WaitForStepParams {
|
|
112
|
+
selector?: string;
|
|
113
|
+
expression?: string;
|
|
114
|
+
network_url?: string;
|
|
115
|
+
condition?: string;
|
|
116
|
+
timeout_ms?: number;
|
|
117
|
+
poll_interval_ms?: number;
|
|
118
|
+
}
|
|
119
|
+
export interface WaitForStepResult {
|
|
120
|
+
matched: boolean;
|
|
121
|
+
elapsed_ms: number;
|
|
122
|
+
checks: number;
|
|
123
|
+
reason?: string;
|
|
124
|
+
}
|
|
125
|
+
export type FlowStep = {
|
|
126
|
+
find: FindStepParams;
|
|
127
|
+
} | {
|
|
128
|
+
click: ClickStepParams;
|
|
129
|
+
} | {
|
|
130
|
+
type: TypeStepParams;
|
|
131
|
+
} | {
|
|
132
|
+
press: PressStepParams;
|
|
133
|
+
} | {
|
|
134
|
+
wait_for: WaitForStepParams;
|
|
135
|
+
};
|
|
136
|
+
/** Everything the step executor needs from the outside world. `cdp/transport.ts`
|
|
137
|
+
* binds each method to the real perform* function; tests bind fakes.
|
|
138
|
+
* `buildRecoverySnapshot` is called only on failure, and always renders the
|
|
139
|
+
* same focused view (`only_interactive:true, max_interactive:40`) via the
|
|
140
|
+
* shared `buildSnapshotJs` builder — same DOM walk `browser.snapshot` uses,
|
|
141
|
+
* just pre-filtered so the agent sees where the flow stopped without a
|
|
142
|
+
* follow-up round trip. */
|
|
143
|
+
export interface FlowDeps {
|
|
144
|
+
performFind(params: FindStepParams): Promise<ActionOutcome<FindStepResult>>;
|
|
145
|
+
performClick(params: ClickStepParams & {
|
|
146
|
+
selector: string;
|
|
147
|
+
}): Promise<ActionOutcome<ClickStepResult>>;
|
|
148
|
+
performType(params: TypeStepParams): Promise<ActionOutcome<TypeStepResult>>;
|
|
149
|
+
performPress(params: PressStepParams): Promise<ActionOutcome<PressStepResult>>;
|
|
150
|
+
performWaitFor(params: WaitForStepParams): Promise<ActionOutcome<WaitForStepResult>>;
|
|
151
|
+
buildRecoverySnapshot(): Promise<unknown>;
|
|
152
|
+
}
|
|
153
|
+
export interface FlowSuccess {
|
|
154
|
+
ok: true;
|
|
155
|
+
steps_completed: number;
|
|
156
|
+
results: unknown[];
|
|
157
|
+
}
|
|
158
|
+
export interface FlowFailure {
|
|
159
|
+
ok: false;
|
|
160
|
+
failed_step: number;
|
|
161
|
+
step_kind: string;
|
|
162
|
+
error: string;
|
|
163
|
+
steps_completed: number;
|
|
164
|
+
recovery_snapshot: unknown;
|
|
165
|
+
}
|
|
166
|
+
export type FlowResult = FlowSuccess | FlowFailure;
|
|
167
|
+
/**
|
|
168
|
+
* Run a declarative sequence of steps strictly in order, stopping at the
|
|
169
|
+
* first failure. See the module doc comment for the implicit-target and
|
|
170
|
+
* result-shaping rules.
|
|
171
|
+
*
|
|
172
|
+
* `steps` is typed as `FlowStep[]` for ergonomic test-writing, but every
|
|
173
|
+
* element is re-validated at runtime via `stepKind()` before use — the
|
|
174
|
+
* array may originate from an untrusted JSON payload cast at the wire
|
|
175
|
+
* boundary in `cdp/transport.ts`, and a malformed entry must fail the flow
|
|
176
|
+
* cleanly rather than throw.
|
|
177
|
+
*/
|
|
178
|
+
export declare function runFlow(steps: readonly FlowStep[], deps: FlowDeps): Promise<FlowResult>;
|