@olimsaidov/icdp 0.2.0 → 0.3.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 +4 -117
- package/dist/frame/index.mjs +24320 -6
- package/dist/host/index.d.mts +1 -1
- package/dist/host/index.mjs +3 -1
- package/dist/protocol-CZthc7CO.d.mts +121 -0
- package/dist/protocol.d.mts +1 -120
- package/dist/relay/core.d.mts +1 -1
- package/package.json +7 -1
- package/src/host/index.ts +8 -1
- package/dist/frame/ax-tree.mjs +0 -2186
package/dist/host/index.d.mts
CHANGED
package/dist/host/index.mjs
CHANGED
|
@@ -34,7 +34,9 @@ var IcdpHost = class {
|
|
|
34
34
|
pending: /* @__PURE__ */ new Map(),
|
|
35
35
|
enables: /* @__PURE__ */ new Map(),
|
|
36
36
|
localSessions: /* @__PURE__ */ new Map(),
|
|
37
|
-
onLoad: () =>
|
|
37
|
+
onLoad: () => {
|
|
38
|
+
if (!pairing.port) this.probe(pairing);
|
|
39
|
+
}
|
|
38
40
|
};
|
|
39
41
|
this.pairings.set(options.targetId, pairing);
|
|
40
42
|
iframe.addEventListener("load", pairing.onLoad);
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import Protocol from "devtools-protocol";
|
|
2
|
+
|
|
3
|
+
//#region src/protocol.d.ts
|
|
4
|
+
declare const PROTOCOL_VERSION = 1;
|
|
5
|
+
type CdpId = Protocol.integer | string;
|
|
6
|
+
/** A raw CDP message: command, response, or event. */
|
|
7
|
+
type CdpMessage = {
|
|
8
|
+
id?: CdpId;
|
|
9
|
+
method?: string;
|
|
10
|
+
params?: Record<string, unknown>;
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
result?: unknown;
|
|
13
|
+
error?: CdpError;
|
|
14
|
+
};
|
|
15
|
+
type CdpError = {
|
|
16
|
+
code: number;
|
|
17
|
+
message: string;
|
|
18
|
+
};
|
|
19
|
+
declare const CDP_SERVER_ERROR = -32000;
|
|
20
|
+
declare const CDP_METHOD_NOT_FOUND = -32601;
|
|
21
|
+
/** Metadata a Frame Agent reports about its document. */
|
|
22
|
+
type FrameInfo = {
|
|
23
|
+
title: string;
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
26
|
+
/** Target metadata as the Host reports it to the Relay. */
|
|
27
|
+
type TargetSummary = FrameInfo & {
|
|
28
|
+
targetId: string;
|
|
29
|
+
};
|
|
30
|
+
/** Sent by the Frame Agent to window.parent when it boots (and on probe). */
|
|
31
|
+
type HelloMessage = {
|
|
32
|
+
icdp: "hello";
|
|
33
|
+
v: number;
|
|
34
|
+
} & FrameInfo;
|
|
35
|
+
/** Sent by the Host to an iframe it doesn't yet have a channel for. */
|
|
36
|
+
type ProbeMessage = {
|
|
37
|
+
icdp: "probe";
|
|
38
|
+
v: number;
|
|
39
|
+
};
|
|
40
|
+
/** Sent by the Host in reply to hello, transferring a MessagePort. */
|
|
41
|
+
type WelcomeMessage = {
|
|
42
|
+
icdp: "welcome";
|
|
43
|
+
v: number;
|
|
44
|
+
};
|
|
45
|
+
type HandshakeMessage = HelloMessage | ProbeMessage | WelcomeMessage;
|
|
46
|
+
declare function isHandshakeMessage(data: unknown): data is HandshakeMessage;
|
|
47
|
+
/** Host -> Relay: announces itself and its current targets. New-wins: the Relay drops any previous Host. */
|
|
48
|
+
type BridgeReady = {
|
|
49
|
+
kind: "ready";
|
|
50
|
+
v: number;
|
|
51
|
+
targets: TargetSummary[];
|
|
52
|
+
/** Browser-level methods (e.g. "Target.createTarget") the Host handles itself.
|
|
53
|
+
* The Relay forwards these as a BridgeBrowserRequest instead of using its
|
|
54
|
+
* built-in default; omitted/empty means the Relay keeps its defaults. */
|
|
55
|
+
handles?: string[];
|
|
56
|
+
};
|
|
57
|
+
/** Host -> Relay: a Pairing appeared. */
|
|
58
|
+
type BridgeTargetCreated = {
|
|
59
|
+
kind: "targetCreated";
|
|
60
|
+
target: TargetSummary;
|
|
61
|
+
};
|
|
62
|
+
/** Host -> Relay: a Pairing was destroyed by the Host. */
|
|
63
|
+
type BridgeTargetDestroyed = {
|
|
64
|
+
kind: "targetDestroyed";
|
|
65
|
+
targetId: string;
|
|
66
|
+
};
|
|
67
|
+
/** Host -> Relay: a Target's document changed (reload / navigation under a stable targetId). */
|
|
68
|
+
type BridgeTargetInfoChanged = {
|
|
69
|
+
kind: "targetInfoChanged";
|
|
70
|
+
target: TargetSummary;
|
|
71
|
+
};
|
|
72
|
+
/** Relay -> Host: a Client command routed to one session. */
|
|
73
|
+
type BridgeCommand = {
|
|
74
|
+
kind: "command";
|
|
75
|
+
sessionId: string;
|
|
76
|
+
targetId: string;
|
|
77
|
+
id: number;
|
|
78
|
+
method: string;
|
|
79
|
+
params: Record<string, unknown>;
|
|
80
|
+
};
|
|
81
|
+
/** Host -> Relay: the response to a BridgeCommand. */
|
|
82
|
+
type BridgeResponse = {
|
|
83
|
+
kind: "response";
|
|
84
|
+
sessionId: string;
|
|
85
|
+
id: number;
|
|
86
|
+
result?: unknown;
|
|
87
|
+
error?: CdpError;
|
|
88
|
+
};
|
|
89
|
+
/** Host -> Relay: a CDP event from a Target; the Relay fans it out to every session attached to it. */
|
|
90
|
+
type BridgeEvent = {
|
|
91
|
+
kind: "event";
|
|
92
|
+
targetId: string;
|
|
93
|
+
method: string;
|
|
94
|
+
params: Record<string, unknown>;
|
|
95
|
+
};
|
|
96
|
+
/** Relay -> Host: a session detached (Client disconnected or detached explicitly). */
|
|
97
|
+
type BridgeDetached = {
|
|
98
|
+
kind: "detached";
|
|
99
|
+
sessionId: string;
|
|
100
|
+
targetId: string;
|
|
101
|
+
};
|
|
102
|
+
/** Relay -> Host: a browser-level method the Host advertised it handles
|
|
103
|
+
* (e.g. Target.createTarget / Target.closeTarget). Not session-scoped. */
|
|
104
|
+
type BridgeBrowserRequest = {
|
|
105
|
+
kind: "browserRequest";
|
|
106
|
+
id: number;
|
|
107
|
+
method: string;
|
|
108
|
+
params: Record<string, unknown>;
|
|
109
|
+
};
|
|
110
|
+
/** Host -> Relay: the response to a BridgeBrowserRequest. */
|
|
111
|
+
type BridgeBrowserResult = {
|
|
112
|
+
kind: "browserResult";
|
|
113
|
+
id: number;
|
|
114
|
+
result?: unknown;
|
|
115
|
+
error?: CdpError;
|
|
116
|
+
};
|
|
117
|
+
type HostToRelayMessage = BridgeReady | BridgeTargetCreated | BridgeTargetDestroyed | BridgeTargetInfoChanged | BridgeResponse | BridgeEvent | BridgeBrowserResult;
|
|
118
|
+
type RelayToHostMessage = BridgeCommand | BridgeDetached | BridgeBrowserRequest;
|
|
119
|
+
declare function parseJson<T>(raw: string | Buffer | ArrayBuffer | Uint8Array): T | null;
|
|
120
|
+
//#endregion
|
|
121
|
+
export { TargetSummary as C, parseJson as E, RelayToHostMessage as S, isHandshakeMessage as T, HandshakeMessage as _, BridgeEvent as a, PROTOCOL_VERSION as b, BridgeTargetCreated as c, CDP_METHOD_NOT_FOUND as d, CDP_SERVER_ERROR as f, FrameInfo as g, CdpMessage as h, BridgeDetached as i, BridgeTargetDestroyed as l, CdpId as m, BridgeBrowserResult as n, BridgeReady as o, CdpError as p, BridgeCommand as r, BridgeResponse as s, BridgeBrowserRequest as t, BridgeTargetInfoChanged as u, HelloMessage as v, WelcomeMessage as w, ProbeMessage as x, HostToRelayMessage as y };
|
package/dist/protocol.d.mts
CHANGED
|
@@ -1,121 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/protocol.d.ts
|
|
4
|
-
declare const PROTOCOL_VERSION = 1;
|
|
5
|
-
type CdpId = Protocol.integer | string;
|
|
6
|
-
/** A raw CDP message: command, response, or event. */
|
|
7
|
-
type CdpMessage = {
|
|
8
|
-
id?: CdpId;
|
|
9
|
-
method?: string;
|
|
10
|
-
params?: Record<string, unknown>;
|
|
11
|
-
sessionId?: string;
|
|
12
|
-
result?: unknown;
|
|
13
|
-
error?: CdpError;
|
|
14
|
-
};
|
|
15
|
-
type CdpError = {
|
|
16
|
-
code: number;
|
|
17
|
-
message: string;
|
|
18
|
-
};
|
|
19
|
-
declare const CDP_SERVER_ERROR = -32000;
|
|
20
|
-
declare const CDP_METHOD_NOT_FOUND = -32601;
|
|
21
|
-
/** Metadata a Frame Agent reports about its document. */
|
|
22
|
-
type FrameInfo = {
|
|
23
|
-
title: string;
|
|
24
|
-
url: string;
|
|
25
|
-
};
|
|
26
|
-
/** Target metadata as the Host reports it to the Relay. */
|
|
27
|
-
type TargetSummary = FrameInfo & {
|
|
28
|
-
targetId: string;
|
|
29
|
-
};
|
|
30
|
-
/** Sent by the Frame Agent to window.parent when it boots (and on probe). */
|
|
31
|
-
type HelloMessage = {
|
|
32
|
-
icdp: "hello";
|
|
33
|
-
v: number;
|
|
34
|
-
} & FrameInfo;
|
|
35
|
-
/** Sent by the Host to an iframe it doesn't yet have a channel for. */
|
|
36
|
-
type ProbeMessage = {
|
|
37
|
-
icdp: "probe";
|
|
38
|
-
v: number;
|
|
39
|
-
};
|
|
40
|
-
/** Sent by the Host in reply to hello, transferring a MessagePort. */
|
|
41
|
-
type WelcomeMessage = {
|
|
42
|
-
icdp: "welcome";
|
|
43
|
-
v: number;
|
|
44
|
-
};
|
|
45
|
-
type HandshakeMessage = HelloMessage | ProbeMessage | WelcomeMessage;
|
|
46
|
-
declare function isHandshakeMessage(data: unknown): data is HandshakeMessage;
|
|
47
|
-
/** Host -> Relay: announces itself and its current targets. New-wins: the Relay drops any previous Host. */
|
|
48
|
-
type BridgeReady = {
|
|
49
|
-
kind: "ready";
|
|
50
|
-
v: number;
|
|
51
|
-
targets: TargetSummary[];
|
|
52
|
-
/** Browser-level methods (e.g. "Target.createTarget") the Host handles itself.
|
|
53
|
-
* The Relay forwards these as a BridgeBrowserRequest instead of using its
|
|
54
|
-
* built-in default; omitted/empty means the Relay keeps its defaults. */
|
|
55
|
-
handles?: string[];
|
|
56
|
-
};
|
|
57
|
-
/** Host -> Relay: a Pairing appeared. */
|
|
58
|
-
type BridgeTargetCreated = {
|
|
59
|
-
kind: "targetCreated";
|
|
60
|
-
target: TargetSummary;
|
|
61
|
-
};
|
|
62
|
-
/** Host -> Relay: a Pairing was destroyed by the Host. */
|
|
63
|
-
type BridgeTargetDestroyed = {
|
|
64
|
-
kind: "targetDestroyed";
|
|
65
|
-
targetId: string;
|
|
66
|
-
};
|
|
67
|
-
/** Host -> Relay: a Target's document changed (reload / navigation under a stable targetId). */
|
|
68
|
-
type BridgeTargetInfoChanged = {
|
|
69
|
-
kind: "targetInfoChanged";
|
|
70
|
-
target: TargetSummary;
|
|
71
|
-
};
|
|
72
|
-
/** Relay -> Host: a Client command routed to one session. */
|
|
73
|
-
type BridgeCommand = {
|
|
74
|
-
kind: "command";
|
|
75
|
-
sessionId: string;
|
|
76
|
-
targetId: string;
|
|
77
|
-
id: number;
|
|
78
|
-
method: string;
|
|
79
|
-
params: Record<string, unknown>;
|
|
80
|
-
};
|
|
81
|
-
/** Host -> Relay: the response to a BridgeCommand. */
|
|
82
|
-
type BridgeResponse = {
|
|
83
|
-
kind: "response";
|
|
84
|
-
sessionId: string;
|
|
85
|
-
id: number;
|
|
86
|
-
result?: unknown;
|
|
87
|
-
error?: CdpError;
|
|
88
|
-
};
|
|
89
|
-
/** Host -> Relay: a CDP event from a Target; the Relay fans it out to every session attached to it. */
|
|
90
|
-
type BridgeEvent = {
|
|
91
|
-
kind: "event";
|
|
92
|
-
targetId: string;
|
|
93
|
-
method: string;
|
|
94
|
-
params: Record<string, unknown>;
|
|
95
|
-
};
|
|
96
|
-
/** Relay -> Host: a session detached (Client disconnected or detached explicitly). */
|
|
97
|
-
type BridgeDetached = {
|
|
98
|
-
kind: "detached";
|
|
99
|
-
sessionId: string;
|
|
100
|
-
targetId: string;
|
|
101
|
-
};
|
|
102
|
-
/** Relay -> Host: a browser-level method the Host advertised it handles
|
|
103
|
-
* (e.g. Target.createTarget / Target.closeTarget). Not session-scoped. */
|
|
104
|
-
type BridgeBrowserRequest = {
|
|
105
|
-
kind: "browserRequest";
|
|
106
|
-
id: number;
|
|
107
|
-
method: string;
|
|
108
|
-
params: Record<string, unknown>;
|
|
109
|
-
};
|
|
110
|
-
/** Host -> Relay: the response to a BridgeBrowserRequest. */
|
|
111
|
-
type BridgeBrowserResult = {
|
|
112
|
-
kind: "browserResult";
|
|
113
|
-
id: number;
|
|
114
|
-
result?: unknown;
|
|
115
|
-
error?: CdpError;
|
|
116
|
-
};
|
|
117
|
-
type HostToRelayMessage = BridgeReady | BridgeTargetCreated | BridgeTargetDestroyed | BridgeTargetInfoChanged | BridgeResponse | BridgeEvent | BridgeBrowserResult;
|
|
118
|
-
type RelayToHostMessage = BridgeCommand | BridgeDetached | BridgeBrowserRequest;
|
|
119
|
-
declare function parseJson<T>(raw: string | Buffer | ArrayBuffer | Uint8Array): T | null;
|
|
120
|
-
//#endregion
|
|
1
|
+
import { C as TargetSummary, E as parseJson, S as RelayToHostMessage, T as isHandshakeMessage, _ as HandshakeMessage, a as BridgeEvent, b as PROTOCOL_VERSION, c as BridgeTargetCreated, d as CDP_METHOD_NOT_FOUND, f as CDP_SERVER_ERROR, g as FrameInfo, h as CdpMessage, i as BridgeDetached, l as BridgeTargetDestroyed, m as CdpId, n as BridgeBrowserResult, o as BridgeReady, p as CdpError, r as BridgeCommand, s as BridgeResponse, t as BridgeBrowserRequest, u as BridgeTargetInfoChanged, v as HelloMessage, w as WelcomeMessage, x as ProbeMessage, y as HostToRelayMessage } from "./protocol-CZthc7CO.mjs";
|
|
121
2
|
export { BridgeBrowserRequest, BridgeBrowserResult, BridgeCommand, BridgeDetached, BridgeEvent, BridgeReady, BridgeResponse, BridgeTargetCreated, BridgeTargetDestroyed, BridgeTargetInfoChanged, CDP_METHOD_NOT_FOUND, CDP_SERVER_ERROR, CdpError, CdpId, CdpMessage, FrameInfo, HandshakeMessage, HelloMessage, HostToRelayMessage, PROTOCOL_VERSION, ProbeMessage, RelayToHostMessage, TargetSummary, WelcomeMessage, isHandshakeMessage, parseJson };
|
package/dist/relay/core.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olimsaidov/icdp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Chrome DevTools Protocol over an iframe boundary: drive and inspect embedded (including cross-origin) apps with CDP tools, without a real browser debugging session.",
|
|
5
5
|
"homepage": "https://github.com/olimsaidov/icdp#readme",
|
|
6
6
|
"bugs": "https://github.com/olimsaidov/icdp/issues",
|
|
@@ -45,6 +45,9 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsdown",
|
|
47
47
|
"check": "tsc --noEmit && oxlint && oxfmt --check .",
|
|
48
|
+
"docs:build": "vitepress build docs",
|
|
49
|
+
"docs:dev": "vitepress dev docs",
|
|
50
|
+
"docs:preview": "vitepress preview docs",
|
|
48
51
|
"fmt": "oxfmt .",
|
|
49
52
|
"gen:conformance": "node scripts/gen-conformance.ts",
|
|
50
53
|
"playground": "node playground/server.ts",
|
|
@@ -64,11 +67,14 @@
|
|
|
64
67
|
"@types/node": "^24",
|
|
65
68
|
"@types/ws": "^8",
|
|
66
69
|
"jsdom": "^29.1.1",
|
|
70
|
+
"mermaid": "^11.15.0",
|
|
67
71
|
"oxfmt": "^0.54.0",
|
|
68
72
|
"oxlint": "^1.69.0",
|
|
69
73
|
"rolldown": "^1.1.1",
|
|
70
74
|
"tsdown": "^0.22.2",
|
|
71
75
|
"typescript": "^5",
|
|
76
|
+
"vitepress": "^1.6.4",
|
|
77
|
+
"vitepress-plugin-mermaid": "^2.0.17",
|
|
72
78
|
"vitest": "^4.1.8"
|
|
73
79
|
},
|
|
74
80
|
"engines": {
|
package/src/host/index.ts
CHANGED
|
@@ -138,7 +138,14 @@ export class IcdpHost {
|
|
|
138
138
|
pending: new Map(),
|
|
139
139
|
enables: new Map(),
|
|
140
140
|
localSessions: new Map(),
|
|
141
|
-
|
|
141
|
+
// Re-probe on load only when we have no channel yet. A connected pairing
|
|
142
|
+
// must not be re-probed: the agent would answer with a fresh hello, which
|
|
143
|
+
// handleWindowMessage treats as a reload and uses to fail in-flight
|
|
144
|
+
// commands. The initial load of a freshly-paired iframe already connected
|
|
145
|
+
// via the agent's boot hello, and a genuine reload re-announces on its own.
|
|
146
|
+
onLoad: () => {
|
|
147
|
+
if (!pairing.port) this.probe(pairing);
|
|
148
|
+
},
|
|
142
149
|
};
|
|
143
150
|
this.pairings.set(options.targetId, pairing);
|
|
144
151
|
iframe.addEventListener("load", pairing.onLoad);
|