@monoes/monobrowse 1.0.13 → 1.0.14
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/dist/src/__tests__/bridge-instruments.test.d.ts +2 -0
- package/dist/src/__tests__/bridge-instruments.test.d.ts.map +1 -0
- package/dist/src/__tests__/bridge-instruments.test.js +132 -0
- package/dist/src/__tests__/bridge-instruments.test.js.map +1 -0
- package/dist/src/__tests__/bridge-transport.test.d.ts +2 -0
- package/dist/src/__tests__/bridge-transport.test.d.ts.map +1 -0
- package/dist/src/__tests__/bridge-transport.test.js +287 -0
- package/dist/src/__tests__/bridge-transport.test.js.map +1 -0
- package/dist/src/__tests__/cdp-transport.test.d.ts +2 -0
- package/dist/src/__tests__/cdp-transport.test.d.ts.map +1 -0
- package/dist/src/__tests__/cdp-transport.test.js +167 -0
- package/dist/src/__tests__/cdp-transport.test.js.map +1 -0
- package/dist/src/browser/bridge.d.ts +119 -0
- package/dist/src/browser/bridge.d.ts.map +1 -0
- package/dist/src/browser/bridge.js +264 -0
- package/dist/src/browser/bridge.js.map +1 -0
- package/dist/src/browser/cdp.d.ts +11 -1
- package/dist/src/browser/cdp.d.ts.map +1 -1
- package/dist/src/browser/cdp.js +60 -56
- package/dist/src/browser/cdp.js.map +1 -1
- package/dist/src/browser/index.d.ts +2 -0
- package/dist/src/browser/index.d.ts.map +1 -1
- package/dist/src/browser/index.js +2 -0
- package/dist/src/browser/index.js.map +1 -1
- package/dist/src/browser/transport.d.ts +62 -0
- package/dist/src/browser/transport.d.ts.map +1 -0
- package/dist/src/browser/transport.js +65 -0
- package/dist/src/browser/transport.js.map +1 -0
- package/dist/src/cli/commander-adapter.d.ts +16 -0
- package/dist/src/cli/commander-adapter.d.ts.map +1 -0
- package/dist/src/cli/commander-adapter.js +68 -0
- package/dist/src/cli/commander-adapter.js.map +1 -0
- package/dist/src/cli/commands-context.d.ts +14 -0
- package/dist/src/cli/commands-context.d.ts.map +1 -0
- package/dist/src/cli/commands-context.js +351 -0
- package/dist/src/cli/commands-context.js.map +1 -0
- package/dist/src/cli/commands-data.d.ts +12 -0
- package/dist/src/cli/commands-data.d.ts.map +1 -0
- package/dist/src/cli/commands-data.js +246 -0
- package/dist/src/cli/commands-data.js.map +1 -0
- package/dist/src/cli/commands-element.d.ts +15 -0
- package/dist/src/cli/commands-element.d.ts.map +1 -0
- package/dist/src/cli/commands-element.js +262 -0
- package/dist/src/cli/commands-element.js.map +1 -0
- package/dist/src/cli/commands-files.d.ts +9 -0
- package/dist/src/cli/commands-files.d.ts.map +1 -0
- package/dist/src/cli/commands-files.js +207 -0
- package/dist/src/cli/commands-files.js.map +1 -0
- package/dist/src/cli/commands-input.d.ts +26 -0
- package/dist/src/cli/commands-input.d.ts.map +1 -0
- package/dist/src/cli/commands-input.js +399 -0
- package/dist/src/cli/commands-input.js.map +1 -0
- package/dist/src/cli/commands-navigate.d.ts +12 -0
- package/dist/src/cli/commands-navigate.d.ts.map +1 -0
- package/dist/src/cli/commands-navigate.js +389 -0
- package/dist/src/cli/commands-navigate.js.map +1 -0
- package/dist/src/cli/commands-page.d.ts +25 -0
- package/dist/src/cli/commands-page.d.ts.map +1 -0
- package/dist/src/cli/commands-page.js +377 -0
- package/dist/src/cli/commands-page.js.map +1 -0
- package/dist/src/cli/commands-report.d.ts +8 -0
- package/dist/src/cli/commands-report.d.ts.map +1 -0
- package/dist/src/cli/commands-report.js +256 -0
- package/dist/src/cli/commands-report.js.map +1 -0
- package/dist/src/cli/commands-script.d.ts +43 -0
- package/dist/src/cli/commands-script.d.ts.map +1 -0
- package/dist/src/cli/commands-script.js +168 -0
- package/dist/src/cli/commands-script.js.map +1 -0
- package/dist/src/cli/commands-session.d.ts +15 -0
- package/dist/src/cli/commands-session.d.ts.map +1 -0
- package/dist/src/cli/commands-session.js +357 -0
- package/dist/src/cli/commands-session.js.map +1 -0
- package/dist/src/cli/commands-trace.d.ts +12 -0
- package/dist/src/cli/commands-trace.d.ts.map +1 -0
- package/dist/src/cli/commands-trace.js +347 -0
- package/dist/src/cli/commands-trace.js.map +1 -0
- package/dist/src/cli/commands.d.ts +22 -42
- package/dist/src/cli/commands.d.ts.map +1 -1
- package/dist/src/cli/commands.js +42 -3648
- package/dist/src/cli/commands.js.map +1 -1
- package/dist/src/cli/session.d.ts +47 -0
- package/dist/src/cli/session.d.ts.map +1 -0
- package/dist/src/cli/session.js +343 -0
- package/dist/src/cli/session.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/__tests__/bridge-instruments.test.ts +180 -0
- package/src/__tests__/bridge-transport.test.ts +365 -0
- package/src/__tests__/cdp-transport.test.ts +198 -0
- package/src/browser/bridge.ts +354 -0
- package/src/browser/cdp.ts +57 -52
- package/src/browser/index.ts +2 -0
- package/src/browser/transport.ts +111 -0
- package/src/cli/commander-adapter.ts +65 -0
- package/src/cli/commands-context.ts +367 -0
- package/src/cli/commands-data.ts +248 -0
- package/src/cli/commands-element.ts +305 -0
- package/src/cli/commands-files.ts +248 -0
- package/src/cli/commands-input.ts +434 -0
- package/src/cli/commands-navigate.ts +442 -0
- package/src/cli/commands-page.ts +420 -0
- package/src/cli/commands-report.ts +275 -0
- package/src/cli/commands-script.ts +183 -0
- package/src/cli/commands-session.ts +376 -0
- package/src/cli/commands-trace.ts +349 -0
- package/src/cli/commands.ts +95 -3943
- package/src/cli/session.ts +412 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cdp-transport.test.js","sourceRoot":"","sources":["../../../src/__tests__/cdp-transport.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAElD,8EAA8E;AAC9E,IAAI,UAAU,GAAkB,IAAI,CAAC;AAErC,MAAM,MAAM;IAMS,GAAG;IALtB,QAAQ,GAAG,IAAI,GAAG,EAA4C,CAAC;IAC/D,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W,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC3D,MAAM,CAAC,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC/B,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QACjC,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAChF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { CdpClient } from './cdp.js';
|
|
2
|
+
import type { CdpTransport, CdpTransportHandlers } from './transport.js';
|
|
3
|
+
/**
|
|
4
|
+
* CDP over the MonoAgent extension bridge.
|
|
5
|
+
*
|
|
6
|
+
* The extension already holds Chrome's `debugger` permission and attaches to
|
|
7
|
+
* tabs with `chrome.debugger.attach`; mono-agent's Go server already owns the
|
|
8
|
+
* WebSocket to it. This transport puts CDP frames on that path — out through
|
|
9
|
+
* the relay's `/monoagent/cdp` socket, into `chrome.debugger.sendCommand`,
|
|
10
|
+
* and back — so a CdpClient can drive the browser the user is actually
|
|
11
|
+
* signed into rather than a headless Chrome we launched. Every instrument
|
|
12
|
+
* built on CdpClient (console, network, HAR, vitals, trace, CPU profiler,
|
|
13
|
+
* snapshot, screenshot, emulation) comes along unchanged.
|
|
14
|
+
*
|
|
15
|
+
* Two mismatches have to be reconciled here, and they are the whole job:
|
|
16
|
+
*
|
|
17
|
+
* **Sessions.** Against a raw socket, monobrowse attaches to a target and
|
|
18
|
+
* carries the resulting `sessionId` on every command and every event.
|
|
19
|
+
* `chrome.debugger` has no such id for the tab: the debuggee *is* the page
|
|
20
|
+
* session, and a `sessionId` on the wire means a *child* session (an
|
|
21
|
+
* out-of-process iframe). So this transport mints a stable synthetic id for
|
|
22
|
+
* the tab, strips it on the way out, stamps it onto relayed events on the
|
|
23
|
+
* way in, and passes any other id through untouched for real child sessions.
|
|
24
|
+
*
|
|
25
|
+
* **Attachment.** A socket is opened; a debuggee is attached. open() does the
|
|
26
|
+
* attach and fails if it cannot, rather than handing back a transport whose
|
|
27
|
+
* first command would fail. close() detaches, which is what takes Chrome's
|
|
28
|
+
* "…started debugging this browser" banner off the user's tab.
|
|
29
|
+
*
|
|
30
|
+
* Known gaps, which are Chrome's and not this file's: `chrome.debugger`
|
|
31
|
+
* exposes a fixed set of domains, and `HeapProfiler` and `Browser` are not
|
|
32
|
+
* among them, so heap snapshots and `Browser.close` fail over the bridge.
|
|
33
|
+
*/
|
|
34
|
+
/** Header the Go relay authenticates with; mirrors internal/extension/token.go. */
|
|
35
|
+
export declare const BRIDGE_TOKEN_HEADER = "X-Monoagent-Extension-Token";
|
|
36
|
+
/** Default relay endpoint; mirrors the extension server's default port. */
|
|
37
|
+
export declare const DEFAULT_BRIDGE_URL = "ws://127.0.0.1:9222/monoagent/cdp";
|
|
38
|
+
/** The synthetic target id standing in for a Chrome tab. */
|
|
39
|
+
export declare function bridgeTargetId(tabId: number): string;
|
|
40
|
+
/** The synthetic session id standing in for a tab's page session. */
|
|
41
|
+
export declare function bridgeSessionId(tabId: number): string;
|
|
42
|
+
/** True for ids this transport minted, as opposed to real CDP child sessions. */
|
|
43
|
+
export declare function isBridgeSessionId(sessionId: string | undefined): boolean;
|
|
44
|
+
export interface BridgeTransportOptions {
|
|
45
|
+
/**
|
|
46
|
+
* The Chrome tab to drive. Omit it to drive whichever tab the user is
|
|
47
|
+
* looking at: the extension resolves the active tab and reports the id
|
|
48
|
+
* back on attach, which is the normal way in — the caller has no tab ids
|
|
49
|
+
* to hand, only a browser with the user's session in it.
|
|
50
|
+
*/
|
|
51
|
+
tabId?: number;
|
|
52
|
+
/** Relay endpoint. Defaults to DEFAULT_BRIDGE_URL. */
|
|
53
|
+
url?: string;
|
|
54
|
+
/** Relay token, from ~/.monoagent (the Go side writes it). */
|
|
55
|
+
token?: string;
|
|
56
|
+
/** Attach-handshake budget in ms. */
|
|
57
|
+
attachTimeoutMs?: number;
|
|
58
|
+
/**
|
|
59
|
+
* The byte pipe underneath. Defaults to a WebSocket to `url`; tests inject
|
|
60
|
+
* a scripted one so they can be the relay.
|
|
61
|
+
*/
|
|
62
|
+
socket?: CdpTransport;
|
|
63
|
+
}
|
|
64
|
+
export declare class BridgeTransport implements CdpTransport {
|
|
65
|
+
/** 0 until the extension resolves the active tab (see open()). */
|
|
66
|
+
private tabId;
|
|
67
|
+
private readonly socket;
|
|
68
|
+
private readonly attachTimeoutMs;
|
|
69
|
+
private handlers;
|
|
70
|
+
private nextEnvelopeId;
|
|
71
|
+
private readonly pending;
|
|
72
|
+
private closed;
|
|
73
|
+
constructor(opts: BridgeTransportOptions);
|
|
74
|
+
open(handlers: CdpTransportHandlers): Promise<void>;
|
|
75
|
+
/** The tab this transport is driving; valid once open() has resolved. */
|
|
76
|
+
get attachedTabId(): number;
|
|
77
|
+
/** The session id every instrument should use against this transport. */
|
|
78
|
+
get sessionId(): string;
|
|
79
|
+
send(frame: string): Promise<void>;
|
|
80
|
+
close(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Commands this transport answers itself. `Target.attachToTarget` against
|
|
83
|
+
* the tab is the one that matters: monobrowse's connect path asks for a
|
|
84
|
+
* session, and over the bridge there is nothing to ask — the debuggee is
|
|
85
|
+
* already the session. Any *other* target id is a genuine child target and
|
|
86
|
+
* goes to Chrome.
|
|
87
|
+
*/
|
|
88
|
+
private answerLocally;
|
|
89
|
+
private command;
|
|
90
|
+
private onBridgeMessage;
|
|
91
|
+
private relayEvent;
|
|
92
|
+
private deliver;
|
|
93
|
+
private onGone;
|
|
94
|
+
private failPending;
|
|
95
|
+
}
|
|
96
|
+
/** What a bridge connection hands back: the same shape connectToTarget gives. */
|
|
97
|
+
export interface BridgeConnection {
|
|
98
|
+
client: CdpClient;
|
|
99
|
+
sessionId: string;
|
|
100
|
+
tabId: number;
|
|
101
|
+
transport: BridgeTransport;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Connect a CdpClient to the user's real Chrome through the extension
|
|
105
|
+
* bridge, with the same domains enabled that a local session gets. This is
|
|
106
|
+
* the whole of the "point the instruments at the logged-in browser" story
|
|
107
|
+
* at the call site:
|
|
108
|
+
*
|
|
109
|
+
* const { client, sessionId } = await connectBridge({ token });
|
|
110
|
+
* const vitals = await collectVitals(client, sessionId);
|
|
111
|
+
*
|
|
112
|
+
* `enableDomains` is on by default for parity with connectToTarget. Turn it
|
|
113
|
+
* off for a caller that wants to choose its own domains (a bridge attach is
|
|
114
|
+
* visible to the user, so a lighter footprint is sometimes the point).
|
|
115
|
+
*/
|
|
116
|
+
export declare function connectBridge(opts?: BridgeTransportOptions & {
|
|
117
|
+
enableDomains?: boolean;
|
|
118
|
+
}): Promise<BridgeConnection>;
|
|
119
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../src/browser/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,mFAAmF;AACnF,eAAO,MAAM,mBAAmB,gCAAgC,CAAC;AAEjE,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,sCAAsC,CAAC;AAKtE,4DAA4D;AAC5D,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,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,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,WAAW;CAMpB;AAED,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,eAAe,CAAC;CAC5B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,CACjC,IAAI,GAAE,sBAAsB,GAAG;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9D,OAAO,CAAC,gBAAgB,CAAC,CAS3B"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { enableSessionDomains } from './browser.js';
|
|
2
|
+
import { CdpClient } from './cdp.js';
|
|
3
|
+
import { WebSocketTransport } from './transport.js';
|
|
4
|
+
/**
|
|
5
|
+
* CDP over the MonoAgent extension bridge.
|
|
6
|
+
*
|
|
7
|
+
* The extension already holds Chrome's `debugger` permission and attaches to
|
|
8
|
+
* tabs with `chrome.debugger.attach`; mono-agent's Go server already owns the
|
|
9
|
+
* WebSocket to it. This transport puts CDP frames on that path — out through
|
|
10
|
+
* the relay's `/monoagent/cdp` socket, into `chrome.debugger.sendCommand`,
|
|
11
|
+
* and back — so a CdpClient can drive the browser the user is actually
|
|
12
|
+
* signed into rather than a headless Chrome we launched. Every instrument
|
|
13
|
+
* built on CdpClient (console, network, HAR, vitals, trace, CPU profiler,
|
|
14
|
+
* snapshot, screenshot, emulation) comes along unchanged.
|
|
15
|
+
*
|
|
16
|
+
* Two mismatches have to be reconciled here, and they are the whole job:
|
|
17
|
+
*
|
|
18
|
+
* **Sessions.** Against a raw socket, monobrowse attaches to a target and
|
|
19
|
+
* carries the resulting `sessionId` on every command and every event.
|
|
20
|
+
* `chrome.debugger` has no such id for the tab: the debuggee *is* the page
|
|
21
|
+
* session, and a `sessionId` on the wire means a *child* session (an
|
|
22
|
+
* out-of-process iframe). So this transport mints a stable synthetic id for
|
|
23
|
+
* the tab, strips it on the way out, stamps it onto relayed events on the
|
|
24
|
+
* way in, and passes any other id through untouched for real child sessions.
|
|
25
|
+
*
|
|
26
|
+
* **Attachment.** A socket is opened; a debuggee is attached. open() does the
|
|
27
|
+
* attach and fails if it cannot, rather than handing back a transport whose
|
|
28
|
+
* first command would fail. close() detaches, which is what takes Chrome's
|
|
29
|
+
* "…started debugging this browser" banner off the user's tab.
|
|
30
|
+
*
|
|
31
|
+
* Known gaps, which are Chrome's and not this file's: `chrome.debugger`
|
|
32
|
+
* exposes a fixed set of domains, and `HeapProfiler` and `Browser` are not
|
|
33
|
+
* among them, so heap snapshots and `Browser.close` fail over the bridge.
|
|
34
|
+
*/
|
|
35
|
+
/** Header the Go relay authenticates with; mirrors internal/extension/token.go. */
|
|
36
|
+
export const BRIDGE_TOKEN_HEADER = 'X-Monoagent-Extension-Token';
|
|
37
|
+
/** Default relay endpoint; mirrors the extension server's default port. */
|
|
38
|
+
export const DEFAULT_BRIDGE_URL = 'ws://127.0.0.1:9222/monoagent/cdp';
|
|
39
|
+
/** How long the attach handshake may take before open() gives up. */
|
|
40
|
+
const DEFAULT_ATTACH_TIMEOUT_MS = 15_000;
|
|
41
|
+
/** The synthetic target id standing in for a Chrome tab. */
|
|
42
|
+
export function bridgeTargetId(tabId) {
|
|
43
|
+
return `bridge-tab-${tabId}`;
|
|
44
|
+
}
|
|
45
|
+
/** The synthetic session id standing in for a tab's page session. */
|
|
46
|
+
export function bridgeSessionId(tabId) {
|
|
47
|
+
return `bridge-session-${tabId}`;
|
|
48
|
+
}
|
|
49
|
+
/** True for ids this transport minted, as opposed to real CDP child sessions. */
|
|
50
|
+
export function isBridgeSessionId(sessionId) {
|
|
51
|
+
return typeof sessionId === 'string' && sessionId.startsWith('bridge-session-');
|
|
52
|
+
}
|
|
53
|
+
export class BridgeTransport {
|
|
54
|
+
/** 0 until the extension resolves the active tab (see open()). */
|
|
55
|
+
tabId;
|
|
56
|
+
socket;
|
|
57
|
+
attachTimeoutMs;
|
|
58
|
+
handlers = null;
|
|
59
|
+
nextEnvelopeId = 1;
|
|
60
|
+
pending = new Map();
|
|
61
|
+
closed = false;
|
|
62
|
+
constructor(opts) {
|
|
63
|
+
this.tabId = opts.tabId ?? 0;
|
|
64
|
+
this.attachTimeoutMs = opts.attachTimeoutMs ?? DEFAULT_ATTACH_TIMEOUT_MS;
|
|
65
|
+
this.socket =
|
|
66
|
+
opts.socket ??
|
|
67
|
+
new WebSocketTransport(opts.url ?? DEFAULT_BRIDGE_URL, opts.token ? { [BRIDGE_TOKEN_HEADER]: opts.token } : undefined);
|
|
68
|
+
}
|
|
69
|
+
async open(handlers) {
|
|
70
|
+
this.handlers = handlers;
|
|
71
|
+
await this.socket.open({
|
|
72
|
+
message: (data) => this.onBridgeMessage(data),
|
|
73
|
+
close: (err) => this.onGone(err ?? new Error('extension bridge closed')),
|
|
74
|
+
error: (err) => this.onGone(err),
|
|
75
|
+
});
|
|
76
|
+
const reply = await this.command('cdp_attach', undefined, this.attachTimeoutMs);
|
|
77
|
+
if (reply.success === false) {
|
|
78
|
+
this.socket.close();
|
|
79
|
+
const where = this.tabId ? `tab ${this.tabId}` : 'the active tab';
|
|
80
|
+
throw new Error(`bridge attach to ${where} failed: ${reply.error ?? 'unknown'}`);
|
|
81
|
+
}
|
|
82
|
+
// The extension answers with the tab it actually attached to, which is
|
|
83
|
+
// the only way to learn the id when we asked for "whatever is active".
|
|
84
|
+
if (typeof reply.data?.tabId === 'number')
|
|
85
|
+
this.tabId = reply.data.tabId;
|
|
86
|
+
if (!this.tabId) {
|
|
87
|
+
this.socket.close();
|
|
88
|
+
throw new Error('bridge attach did not report a tab id');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The tab this transport is driving; valid once open() has resolved. */
|
|
92
|
+
get attachedTabId() {
|
|
93
|
+
return this.tabId;
|
|
94
|
+
}
|
|
95
|
+
/** The session id every instrument should use against this transport. */
|
|
96
|
+
get sessionId() {
|
|
97
|
+
return bridgeSessionId(this.tabId);
|
|
98
|
+
}
|
|
99
|
+
async send(frame) {
|
|
100
|
+
const cdp = JSON.parse(frame);
|
|
101
|
+
if (this.answerLocally(cdp))
|
|
102
|
+
return;
|
|
103
|
+
const params = {
|
|
104
|
+
method: cdp.method,
|
|
105
|
+
params: cdp.params ?? {},
|
|
106
|
+
};
|
|
107
|
+
// A synthetic id means "the tab itself", which chrome.debugger addresses
|
|
108
|
+
// by its debuggee alone. Anything else is a real child session id and
|
|
109
|
+
// has to travel, or the command lands in the wrong frame.
|
|
110
|
+
if (cdp.sessionId !== undefined && !isBridgeSessionId(cdp.sessionId)) {
|
|
111
|
+
params.sessionId = cdp.sessionId;
|
|
112
|
+
}
|
|
113
|
+
const reply = await this.command('cdp', params);
|
|
114
|
+
if (reply.success === false) {
|
|
115
|
+
this.deliver({
|
|
116
|
+
id: cdp.id,
|
|
117
|
+
// -32000 is CDP's own "server error" code; the bridge has no richer
|
|
118
|
+
// one to offer, and the message is what a caller actually reads.
|
|
119
|
+
error: { code: -32000, message: reply.error ?? 'bridge command failed' },
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this.deliver({ id: cdp.id, result: reply.data?.result ?? {} });
|
|
124
|
+
}
|
|
125
|
+
close() {
|
|
126
|
+
if (this.closed)
|
|
127
|
+
return;
|
|
128
|
+
this.closed = true;
|
|
129
|
+
// Best effort, and deliberately not awaited: leaving the debugger
|
|
130
|
+
// attached leaves Chrome's debugging banner on the user's tab. The
|
|
131
|
+
// extension's idle sweep would eventually detach anyway.
|
|
132
|
+
void this.command('cdp_detach').catch(() => { });
|
|
133
|
+
this.socket.close();
|
|
134
|
+
this.failPending(new Error('extension bridge closed'));
|
|
135
|
+
}
|
|
136
|
+
// --- internals -----------------------------------------------------------
|
|
137
|
+
/**
|
|
138
|
+
* Commands this transport answers itself. `Target.attachToTarget` against
|
|
139
|
+
* the tab is the one that matters: monobrowse's connect path asks for a
|
|
140
|
+
* session, and over the bridge there is nothing to ask — the debuggee is
|
|
141
|
+
* already the session. Any *other* target id is a genuine child target and
|
|
142
|
+
* goes to Chrome.
|
|
143
|
+
*/
|
|
144
|
+
answerLocally(cdp) {
|
|
145
|
+
const targetId = cdp.params?.targetId;
|
|
146
|
+
if (cdp.method === 'Target.attachToTarget' && targetId === bridgeTargetId(this.tabId)) {
|
|
147
|
+
this.deliver({ id: cdp.id, result: { sessionId: bridgeSessionId(this.tabId) } });
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
if (cdp.method === 'Target.detachFromTarget' &&
|
|
151
|
+
isBridgeSessionId(cdp.params?.sessionId)) {
|
|
152
|
+
this.deliver({ id: cdp.id, result: {} });
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
command(type, params, timeoutMs = 0) {
|
|
158
|
+
const id = `cdp-${this.nextEnvelopeId++}`;
|
|
159
|
+
const envelope = { id, type, params };
|
|
160
|
+
if (this.tabId)
|
|
161
|
+
envelope.tabId = this.tabId;
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
let timer;
|
|
164
|
+
if (timeoutMs > 0) {
|
|
165
|
+
timer = setTimeout(() => {
|
|
166
|
+
this.pending.delete(id);
|
|
167
|
+
reject(new Error(`bridge ${type} timed out after ${timeoutMs}ms`));
|
|
168
|
+
}, timeoutMs);
|
|
169
|
+
timer.unref?.();
|
|
170
|
+
}
|
|
171
|
+
this.pending.set(id, (reply) => {
|
|
172
|
+
if (timer)
|
|
173
|
+
clearTimeout(timer);
|
|
174
|
+
resolve(reply);
|
|
175
|
+
});
|
|
176
|
+
this.socket.send(JSON.stringify(envelope)).catch((err) => {
|
|
177
|
+
if (timer)
|
|
178
|
+
clearTimeout(timer);
|
|
179
|
+
this.pending.delete(id);
|
|
180
|
+
reject(err);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
onBridgeMessage(data) {
|
|
185
|
+
let msg;
|
|
186
|
+
try {
|
|
187
|
+
msg = JSON.parse(data);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return; // malformed frames are ignored, as on a raw CDP socket
|
|
191
|
+
}
|
|
192
|
+
if (msg.type === 'cdp_event') {
|
|
193
|
+
this.relayEvent(msg);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (msg.id !== undefined) {
|
|
197
|
+
const settle = this.pending.get(msg.id);
|
|
198
|
+
if (settle) {
|
|
199
|
+
this.pending.delete(msg.id);
|
|
200
|
+
settle(msg);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
relayEvent(msg) {
|
|
205
|
+
const ev = msg.data;
|
|
206
|
+
if (!ev?.method)
|
|
207
|
+
return;
|
|
208
|
+
// One relay socket can carry several tabs; take only our own.
|
|
209
|
+
if (ev.tabId !== undefined && ev.tabId !== this.tabId)
|
|
210
|
+
return;
|
|
211
|
+
// The debugger went away — the user hit Cancel on the banner, DevTools
|
|
212
|
+
// opened on the tab, or the tab closed. Nothing else will arrive, and a
|
|
213
|
+
// caller waiting on a command should hear that now rather than time out.
|
|
214
|
+
if (ev.method === 'Inspector.detached') {
|
|
215
|
+
const reason = ev.params?.reason ?? 'unknown';
|
|
216
|
+
this.onGone(new Error(`extension bridge detached from tab ${this.tabId}: ${reason}`));
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
this.deliver({
|
|
220
|
+
method: ev.method,
|
|
221
|
+
params: ev.params ?? {},
|
|
222
|
+
// A real child session id wins; otherwise this is the tab's own
|
|
223
|
+
// session, which every instrument filters its events by.
|
|
224
|
+
sessionId: ev.sessionId ?? bridgeSessionId(this.tabId),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
deliver(frame) {
|
|
228
|
+
this.handlers?.message(JSON.stringify(frame));
|
|
229
|
+
}
|
|
230
|
+
onGone(err) {
|
|
231
|
+
this.failPending(err);
|
|
232
|
+
this.handlers?.close(err);
|
|
233
|
+
}
|
|
234
|
+
failPending(err) {
|
|
235
|
+
for (const settle of this.pending.values()) {
|
|
236
|
+
settle({ success: false, error: err.message });
|
|
237
|
+
}
|
|
238
|
+
this.pending.clear();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Connect a CdpClient to the user's real Chrome through the extension
|
|
243
|
+
* bridge, with the same domains enabled that a local session gets. This is
|
|
244
|
+
* the whole of the "point the instruments at the logged-in browser" story
|
|
245
|
+
* at the call site:
|
|
246
|
+
*
|
|
247
|
+
* const { client, sessionId } = await connectBridge({ token });
|
|
248
|
+
* const vitals = await collectVitals(client, sessionId);
|
|
249
|
+
*
|
|
250
|
+
* `enableDomains` is on by default for parity with connectToTarget. Turn it
|
|
251
|
+
* off for a caller that wants to choose its own domains (a bridge attach is
|
|
252
|
+
* visible to the user, so a lighter footprint is sometimes the point).
|
|
253
|
+
*/
|
|
254
|
+
export async function connectBridge(opts = {}) {
|
|
255
|
+
const transport = new BridgeTransport(opts);
|
|
256
|
+
const client = new CdpClient();
|
|
257
|
+
await client.connectTransport(transport);
|
|
258
|
+
const sessionId = transport.sessionId;
|
|
259
|
+
if (opts.enableDomains !== false) {
|
|
260
|
+
await enableSessionDomains(client, sessionId);
|
|
261
|
+
}
|
|
262
|
+
return { client, sessionId, tabId: transport.attachedTabId, transport };
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../src/browser/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,mFAAmF;AACnF,MAAM,CAAC,MAAM,mBAAmB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OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC;IAEO,MAAM,CAAC,GAAU;QACvB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAEO,WAAW,CAAC,GAAU;QAC5B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3C,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACjD,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF;AAUD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAI,GAAyD,EAAE;IAE/D,MAAM,SAAS,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;IAC/B,MAAM,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;IACtC,IAAI,IAAI,CAAC,aAAa,KAAK,KAAK,EAAE,CAAC;QACjC,MAAM,oBAAoB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC,aAAa,EAAE,SAAS,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
import type { CdpTransport } from './transport.js';
|
|
1
2
|
import type { CdpTarget } from './types.js';
|
|
2
3
|
export declare const DEFAULT_CDP_SEND_TIMEOUT_MS = 30000;
|
|
3
4
|
export declare class CdpClient {
|
|
4
|
-
private
|
|
5
|
+
private transport;
|
|
5
6
|
private pendingCommands;
|
|
6
7
|
private eventListeners;
|
|
7
8
|
private nextId;
|
|
8
9
|
private connected;
|
|
9
10
|
constructor();
|
|
10
11
|
private flushPending;
|
|
12
|
+
/** Connect to a Chrome DevTools WebSocket endpoint (the original path). */
|
|
11
13
|
connect(wsUrl: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Connect over any transport — a local DevTools socket, or the extension
|
|
16
|
+
* bridge to the user's own logged-in Chrome (see bridge.ts). Everything
|
|
17
|
+
* downstream of here (sessions, events, timeouts) is identical either way,
|
|
18
|
+
* which is the point: the instruments never learn which one they are on.
|
|
19
|
+
*/
|
|
20
|
+
connectTransport(transport: CdpTransport): Promise<void>;
|
|
21
|
+
private handleMessage;
|
|
12
22
|
send<T = Record<string, unknown>>(method: string, params?: Record<string, unknown>, sessionId?: string, timeoutMs?: number): Promise<T>;
|
|
13
23
|
on(event: string, fn: (params: Record<string, unknown>, sessionId?: string) => void): () => void;
|
|
14
24
|
once(event: string, sessionId?: string): Promise<Record<string, unknown>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdp.d.ts","sourceRoot":"","sources":["../../../src/browser/cdp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cdp.d.ts","sourceRoot":"","sources":["../../../src/browser/cdp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,KAAK,EAA2B,SAAS,EAAE,MAAM,YAAY,CAAC;AAUrE,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAMlD,qBAAa,SAAS;IACpB,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,eAAe,CAOnB;IACJ,OAAO,CAAC,cAAc,CAGlB;IACJ,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,SAAS,CAAS;IAE1B,cAOC;IAED,OAAO,CAAC,YAAY;IASpB,2EAA2E;IACrE,OA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Q,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,SAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAoEtF"}
|
package/dist/src/browser/cdp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WebSocketTransport } from './transport.js';
|
|
2
2
|
// send() had no timeout of its own — a command whose response never arrives
|
|
3
3
|
// (wedged/crashed renderer, dropped socket that never fires 'close') left a
|
|
4
4
|
// pendingCommands entry forever, hanging whatever awaited it (and, since
|
|
@@ -8,8 +8,11 @@ import { WebSocket } from 'ws';
|
|
|
8
8
|
// protection at all. This is the default for every send() unless a caller
|
|
9
9
|
// passes 0 (no timeout) or a different value.
|
|
10
10
|
export const DEFAULT_CDP_SEND_TIMEOUT_MS = 30_000;
|
|
11
|
+
// The message every path uses to say the connection went away. Shared so a
|
|
12
|
+
// caller matching on it does not have to care which transport was under it.
|
|
13
|
+
const CDP_CLOSED_MESSAGE = 'CDP connection closed';
|
|
11
14
|
export class CdpClient {
|
|
12
|
-
|
|
15
|
+
transport = null;
|
|
13
16
|
pendingCommands = new Map();
|
|
14
17
|
eventListeners = new Map();
|
|
15
18
|
nextId = 1;
|
|
@@ -31,61 +34,64 @@ export class CdpClient {
|
|
|
31
34
|
}
|
|
32
35
|
this.pendingCommands.clear();
|
|
33
36
|
}
|
|
37
|
+
/** Connect to a Chrome DevTools WebSocket endpoint (the original path). */
|
|
34
38
|
async connect(wsUrl) {
|
|
35
|
-
return new
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
return this.connectTransport(new WebSocketTransport(wsUrl));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Connect over any transport — a local DevTools socket, or the extension
|
|
43
|
+
* bridge to the user's own logged-in Chrome (see bridge.ts). Everything
|
|
44
|
+
* downstream of here (sessions, events, timeouts) is identical either way,
|
|
45
|
+
* which is the point: the instruments never learn which one they are on.
|
|
46
|
+
*/
|
|
47
|
+
connectTransport(transport) {
|
|
48
|
+
this.transport = transport;
|
|
49
|
+
return transport
|
|
50
|
+
.open({
|
|
51
|
+
message: (data) => this.handleMessage(data),
|
|
52
|
+
// Post-connect failure of either kind strands every in-flight
|
|
53
|
+
// command, so both flush: 'close' may not fire on all platforms.
|
|
54
|
+
close: (err) => this.flushPending(err ?? new Error(CDP_CLOSED_MESSAGE)),
|
|
55
|
+
error: (err) => this.flushPending(err),
|
|
56
|
+
})
|
|
57
|
+
.then(() => {
|
|
58
|
+
this.connected = true;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
handleMessage(data) {
|
|
62
|
+
try {
|
|
63
|
+
const msg = JSON.parse(data);
|
|
64
|
+
if (msg.id !== undefined && this.pendingCommands.has(msg.id)) {
|
|
65
|
+
const handler = this.pendingCommands.get(msg.id);
|
|
66
|
+
this.pendingCommands.delete(msg.id);
|
|
67
|
+
if (msg.error) {
|
|
68
|
+
handler.reject(new Error(`CDP error ${msg.error.code}: ${msg.error.message}`));
|
|
44
69
|
}
|
|
45
70
|
else {
|
|
46
|
-
|
|
47
|
-
this.flushPending(err instanceof Error ? err : new Error(String(err)));
|
|
71
|
+
handler.resolve(msg);
|
|
48
72
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (msg.id !== undefined && this.pendingCommands.has(msg.id)) {
|
|
57
|
-
const handler = this.pendingCommands.get(msg.id);
|
|
58
|
-
this.pendingCommands.delete(msg.id);
|
|
59
|
-
if (msg.error) {
|
|
60
|
-
handler.reject(new Error(`CDP error ${msg.error.code}: ${msg.error.message}`));
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
handler.resolve(msg);
|
|
73
|
+
}
|
|
74
|
+
else if (msg.method) {
|
|
75
|
+
const listeners = this.eventListeners.get(msg.method);
|
|
76
|
+
if (listeners) {
|
|
77
|
+
for (const fn of listeners) {
|
|
78
|
+
try {
|
|
79
|
+
fn(msg.params ?? {}, msg.sessionId);
|
|
64
80
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const listeners = this.eventListeners.get(msg.method);
|
|
68
|
-
if (listeners) {
|
|
69
|
-
for (const fn of listeners) {
|
|
70
|
-
try {
|
|
71
|
-
fn(msg.params ?? {}, msg.sessionId);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
/* isolate per-listener errors */
|
|
75
|
-
}
|
|
76
|
-
}
|
|
81
|
+
catch {
|
|
82
|
+
/* isolate per-listener errors */
|
|
77
83
|
}
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// ignore malformed messages
|
|
90
|
+
}
|
|
85
91
|
}
|
|
86
92
|
send(method, params, sessionId, timeoutMs = DEFAULT_CDP_SEND_TIMEOUT_MS) {
|
|
87
93
|
return new Promise((resolve, reject) => {
|
|
88
|
-
if (!this.
|
|
94
|
+
if (!this.transport || !this.connected) {
|
|
89
95
|
reject(new Error('CDP not connected'));
|
|
90
96
|
return;
|
|
91
97
|
}
|
|
@@ -119,13 +125,11 @@ export class CdpClient {
|
|
|
119
125
|
},
|
|
120
126
|
timer,
|
|
121
127
|
});
|
|
122
|
-
this.
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
reject(err);
|
|
128
|
-
}
|
|
128
|
+
this.transport.send(JSON.stringify(cmd)).catch((err) => {
|
|
129
|
+
if (timer)
|
|
130
|
+
clearTimeout(timer);
|
|
131
|
+
this.pendingCommands.delete(id);
|
|
132
|
+
reject(err);
|
|
129
133
|
});
|
|
130
134
|
});
|
|
131
135
|
}
|
|
@@ -158,9 +162,9 @@ export class CdpClient {
|
|
|
158
162
|
return [promise, () => off()];
|
|
159
163
|
}
|
|
160
164
|
close() {
|
|
161
|
-
this.flushPending(new Error(
|
|
162
|
-
this.
|
|
163
|
-
this.
|
|
165
|
+
this.flushPending(new Error(CDP_CLOSED_MESSAGE));
|
|
166
|
+
this.transport?.close();
|
|
167
|
+
this.transport = null;
|
|
164
168
|
this.eventListeners.clear();
|
|
165
169
|
}
|
|
166
170
|
isConnected() {
|