@vforsh/argus-watcher 0.1.6 → 0.1.8
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/.tsbuildinfo +1 -1
- package/dist/cdp/text-filter.js.map +1 -1
- package/dist/http/routes/domSelectorRoute.d.ts +16 -0
- package/dist/http/routes/domSelectorRoute.d.ts.map +1 -0
- package/dist/http/routes/domSelectorRoute.js +31 -0
- package/dist/http/routes/domSelectorRoute.js.map +1 -0
- package/dist/http/routes/postDomClick.d.ts.map +1 -1
- package/dist/http/routes/postDomClick.js +2 -7
- package/dist/http/routes/postDomClick.js.map +1 -1
- package/dist/http/routes/postDomFocus.d.ts.map +1 -1
- package/dist/http/routes/postDomFocus.js +6 -17
- package/dist/http/routes/postDomFocus.js.map +1 -1
- package/dist/http/routes/postDomHover.d.ts.map +1 -1
- package/dist/http/routes/postDomHover.js +6 -17
- package/dist/http/routes/postDomHover.js.map +1 -1
- package/dist/http/routes/postDomInfo.d.ts.map +1 -1
- package/dist/http/routes/postDomInfo.js +6 -18
- package/dist/http/routes/postDomInfo.js.map +1 -1
- package/dist/http/routes/postDomRemove.d.ts.map +1 -1
- package/dist/http/routes/postDomRemove.js +6 -17
- package/dist/http/routes/postDomRemove.js.map +1 -1
- package/dist/http/routes/postDomTree.d.ts.map +1 -1
- package/dist/http/routes/postDomTree.js +6 -18
- package/dist/http/routes/postDomTree.js.map +1 -1
- package/dist/http/routes/postReload.d.ts.map +1 -1
- package/dist/http/routes/postReload.js +2 -1
- package/dist/http/routes/postReload.js.map +1 -1
- package/dist/http/server.d.ts +2 -0
- package/dist/http/server.d.ts.map +1 -1
- package/dist/http/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -395
- package/dist/index.js.map +1 -1
- package/dist/sources/extension-delegating-session.d.ts +21 -0
- package/dist/sources/extension-delegating-session.d.ts.map +1 -0
- package/dist/sources/extension-delegating-session.js +62 -0
- package/dist/sources/extension-delegating-session.js.map +1 -0
- package/dist/sources/extension-frame-state.d.ts +28 -1
- package/dist/sources/extension-frame-state.d.ts.map +1 -1
- package/dist/sources/extension-frame-state.js +54 -2
- package/dist/sources/extension-frame-state.js.map +1 -1
- package/dist/sources/extension-session-events.d.ts +21 -0
- package/dist/sources/extension-session-events.d.ts.map +1 -0
- package/dist/sources/extension-session-events.js +103 -0
- package/dist/sources/extension-session-events.js.map +1 -0
- package/dist/sources/extension-source.d.ts +0 -4
- package/dist/sources/extension-source.d.ts.map +1 -1
- package/dist/sources/extension-source.js +74 -190
- package/dist/sources/extension-source.js.map +1 -1
- package/dist/startWatcherRuntime.d.ts +6 -0
- package/dist/startWatcherRuntime.d.ts.map +1 -0
- package/dist/startWatcherRuntime.js +414 -0
- package/dist/startWatcherRuntime.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export const createEmptyFrameState = () => ({
|
|
2
2
|
topFrameId: null,
|
|
3
3
|
requestedFrameId: null,
|
|
4
|
+
requestedFrameHint: null,
|
|
5
|
+
requestedFrameDetached: false,
|
|
4
6
|
activeFrameId: null,
|
|
5
7
|
activeAttachedAt: null,
|
|
6
8
|
frames: new Map(),
|
|
@@ -103,15 +105,65 @@ export const parseExecutionContext = (params) => {
|
|
|
103
105
|
isDefault: record.context.auxData?.isDefault === true,
|
|
104
106
|
};
|
|
105
107
|
};
|
|
108
|
+
export const createRequestedFrameHint = (frame) => {
|
|
109
|
+
if (!frame) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
url: frame.url || null,
|
|
114
|
+
title: frame.title?.trim() || null,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
106
117
|
/**
|
|
107
118
|
* Selection is about the user's intended target, not whether every frame-scoped command is ready.
|
|
108
119
|
* Once the watcher knows the frame exists we can switch the active target; commands that require
|
|
109
120
|
* an execution context still guard that separately at execution time.
|
|
110
121
|
*/
|
|
111
|
-
export const resolveRequestedFrameId = (state, requestedFrameId) => {
|
|
122
|
+
export const resolveRequestedFrameId = (state, requestedFrameId, requestedFrameHint) => {
|
|
112
123
|
if (!requestedFrameId) {
|
|
113
124
|
return null;
|
|
114
125
|
}
|
|
115
|
-
|
|
126
|
+
if (state.frames.has(requestedFrameId)) {
|
|
127
|
+
return requestedFrameId;
|
|
128
|
+
}
|
|
129
|
+
if (!requestedFrameHint) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const urlMatch = requestedFrameHint.url == null ? null : findSingleMatchingFrameId(state, (frame) => frame.url === requestedFrameHint.url);
|
|
133
|
+
if (urlMatch) {
|
|
134
|
+
return urlMatch;
|
|
135
|
+
}
|
|
136
|
+
if (requestedFrameHint.url != null || !requestedFrameHint.title) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return findSingleMatchingFrameId(state, (frame) => frame.title?.trim() === requestedFrameHint.title);
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Pending iframe selections have two valid states:
|
|
143
|
+
* - `pending`: the iframe has never become active in this attachment yet, so keep waiting silently.
|
|
144
|
+
* - `page`: the iframe was active and then disappeared, so report the page while we wait for a safe rematch.
|
|
145
|
+
*/
|
|
146
|
+
export const resolveRequestedTarget = (state) => {
|
|
147
|
+
if (state.requestedFrameId == null) {
|
|
148
|
+
return { kind: 'page' };
|
|
149
|
+
}
|
|
150
|
+
const nextFrameId = resolveRequestedFrameId(state, state.requestedFrameId, state.requestedFrameHint);
|
|
151
|
+
if (nextFrameId) {
|
|
152
|
+
return { kind: 'frame', frameId: nextFrameId };
|
|
153
|
+
}
|
|
154
|
+
return state.requestedFrameDetached ? { kind: 'page' } : { kind: 'pending' };
|
|
155
|
+
};
|
|
156
|
+
const findSingleMatchingFrameId = (state, predicate) => {
|
|
157
|
+
let matchId = null;
|
|
158
|
+
for (const frame of state.frames.values()) {
|
|
159
|
+
if (!predicate(frame)) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (matchId) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
matchId = frame.frameId;
|
|
166
|
+
}
|
|
167
|
+
return matchId;
|
|
116
168
|
};
|
|
117
169
|
//# sourceMappingURL=extension-frame-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-frame-state.js","sourceRoot":"","sources":["../../src/sources/extension-frame-state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extension-frame-state.js","sourceRoot":"","sources":["../../src/sources/extension-frame-state.ts"],"names":[],"mappings":"AAoDA,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAwB,EAAE,CAAC,CAAC;IAChE,UAAU,EAAE,IAAI;IAChB,gBAAgB,EAAE,IAAI;IACtB,kBAAkB,EAAE,IAAI;IACxB,sBAAsB,EAAE,KAAK;IAC7B,aAAa,EAAE,IAAI;IACnB,gBAAgB,EAAE,IAAI;IACtB,MAAM,EAAE,IAAI,GAAG,EAAE;IACjB,iBAAiB,EAAE,IAAI,GAAG,EAAE;IAC5B,iBAAiB,EAAE,IAAI,GAAG,EAAE;CAC5B,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAU,EAAE;IACjD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,+BAA+B,CAAC,CACvD;IAAC,KAAmC,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAC/D,OAAO,KAAK,CAAA;AACb,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,OAAO,KAAK,EAAE,CAAA;AAE3E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAE,OAAe,EAAU,EAAE,CAAC,SAAS,KAAK,IAAI,OAAO,EAAE,CAAA;AAE1G,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,QAAgB,EAA6C,EAAE;IACrG,IAAI,QAAQ,CAA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,CAAA;AAC7E,CAAC,CAAA;AAED,MAAM,yBAAyB,GAAG,CAAC,KAA0B,EAAE,SAA6C,EAAiB,EAAE;IAC9H,IAAI,OAAO,GAAkB,IAAI,CAAA;IACjC,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QAC3C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,SAAQ;QACT,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAA;QACZ,CAAC;QACD,OAAO,GAAG,KAAK,CAAC,OAAO,CAAA;IACxB,CAAC;IACD,OAAO,OAAO,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ExtensionSession } from '../native-messaging/session-manager.js';
|
|
2
|
+
import type { CdpSourceEvents } from './types.js';
|
|
3
|
+
import { type ExtensionFrameState } from './extension-frame-state.js';
|
|
4
|
+
type RegisterExtensionSessionEventsOptions = {
|
|
5
|
+
session: ExtensionSession;
|
|
6
|
+
events: CdpSourceEvents;
|
|
7
|
+
ignoreMatcher?: ((url: string) => boolean) | null;
|
|
8
|
+
stripUrlPrefixes?: string[];
|
|
9
|
+
getOrCreateFrameState: (tabId: number) => ExtensionFrameState;
|
|
10
|
+
reconcileTargetSelection: (session: ExtensionSession) => boolean;
|
|
11
|
+
removeFrame: (tabId: number, frameId: string) => void;
|
|
12
|
+
refreshFrameTitle: (session: ExtensionSession, frameId: string, contextId?: number) => Promise<void>;
|
|
13
|
+
emitTargetChanged: (session: ExtensionSession) => void;
|
|
14
|
+
setCurrentSession: (session: ExtensionSession) => void;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Subscribe to extension-backed CDP events and funnel them back through the shared frame-state helpers.
|
|
18
|
+
*/
|
|
19
|
+
export declare const registerExtensionSessionEventHandlers: ({ session, events, ignoreMatcher, stripUrlPrefixes, getOrCreateFrameState, reconcileTargetSelection, removeFrame, refreshFrameTitle, emitTargetChanged, setCurrentSession, }: RegisterExtensionSessionEventsOptions) => void;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=extension-session-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-session-events.d.ts","sourceRoot":"","sources":["../../src/sources/extension-session-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAqC,KAAK,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAGxG,KAAK,qCAAqC,GAAG;IAC5C,OAAO,EAAE,gBAAgB,CAAA;IACzB,MAAM,EAAE,eAAe,CAAA;IACvB,aAAa,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,IAAI,CAAA;IACjD,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC3B,qBAAqB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,mBAAmB,CAAA;IAC7D,wBAAwB,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAA;IAChE,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IACrD,iBAAiB,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpG,iBAAiB,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAA;IACtD,iBAAiB,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAA;CACtD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,qCAAqC,GAAI,8KAWnD,qCAAqC,KAAG,IA2G1C,CAAA"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { parseExecutionContext, parseFrame } from './extension-frame-state.js';
|
|
2
|
+
import { toConsoleEvent, toExceptionEvent } from './extension-log-events.js';
|
|
3
|
+
/**
|
|
4
|
+
* Subscribe to extension-backed CDP events and funnel them back through the shared frame-state helpers.
|
|
5
|
+
*/
|
|
6
|
+
export const registerExtensionSessionEventHandlers = ({ session, events, ignoreMatcher, stripUrlPrefixes, getOrCreateFrameState, reconcileTargetSelection, removeFrame, refreshFrameTitle, emitTargetChanged, setCurrentSession, }) => {
|
|
7
|
+
session.handle.onEvent('Runtime.executionContextCreated', (params, meta) => {
|
|
8
|
+
const context = parseExecutionContext(params);
|
|
9
|
+
if (!context?.isDefault || !context.frameId) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const state = getOrCreateFrameState(session.tabId);
|
|
13
|
+
state.executionContexts.set(context.frameId, context.id);
|
|
14
|
+
const frame = state.frames.get(context.frameId);
|
|
15
|
+
if (frame) {
|
|
16
|
+
frame.sessionId = meta.sessionId ?? null;
|
|
17
|
+
}
|
|
18
|
+
void refreshFrameTitle(session, context.frameId, context.id);
|
|
19
|
+
reconcileTargetSelection(session);
|
|
20
|
+
});
|
|
21
|
+
session.handle.onEvent('Runtime.executionContextsCleared', () => {
|
|
22
|
+
const state = getOrCreateFrameState(session.tabId);
|
|
23
|
+
state.executionContexts.clear();
|
|
24
|
+
state.pendingTitleLoads.clear();
|
|
25
|
+
});
|
|
26
|
+
session.handle.onEvent('Runtime.executionContextDestroyed', (params) => {
|
|
27
|
+
const record = params;
|
|
28
|
+
if (record.executionContextId == null) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const state = getOrCreateFrameState(session.tabId);
|
|
32
|
+
for (const [frameId, contextId] of state.executionContexts.entries()) {
|
|
33
|
+
if (contextId === record.executionContextId) {
|
|
34
|
+
state.executionContexts.delete(frameId);
|
|
35
|
+
state.pendingTitleLoads.delete(frameId);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
session.handle.onEvent('Page.frameNavigated', (params, meta) => {
|
|
40
|
+
const frame = parseFrame(params);
|
|
41
|
+
if (!frame) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const state = getOrCreateFrameState(session.tabId);
|
|
45
|
+
state.frames.set(frame.frameId, frame);
|
|
46
|
+
frame.sessionId = meta.sessionId ?? null;
|
|
47
|
+
if (!frame.parentFrameId) {
|
|
48
|
+
if (!meta.sessionId) {
|
|
49
|
+
state.topFrameId = frame.frameId;
|
|
50
|
+
session.url = frame.url;
|
|
51
|
+
}
|
|
52
|
+
else if (state.topFrameId == null) {
|
|
53
|
+
state.topFrameId = frame.parentFrameId;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (state.executionContexts.has(frame.frameId)) {
|
|
57
|
+
void refreshFrameTitle(session, frame.frameId);
|
|
58
|
+
}
|
|
59
|
+
setCurrentSession(session);
|
|
60
|
+
if (!frame.parentFrameId && !meta.sessionId) {
|
|
61
|
+
events.onPageNavigation?.({ url: frame.url, title: session.title ?? null });
|
|
62
|
+
}
|
|
63
|
+
if (reconcileTargetSelection(session)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if ((!frame.parentFrameId && state.activeFrameId == null) || state.activeFrameId === frame.frameId) {
|
|
67
|
+
emitTargetChanged(session);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
session.handle.onEvent('Page.frameAttached', (params, meta) => {
|
|
71
|
+
const record = params;
|
|
72
|
+
if (!record.frameId) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const state = getOrCreateFrameState(session.tabId);
|
|
76
|
+
state.frames.set(record.frameId, {
|
|
77
|
+
frameId: record.frameId,
|
|
78
|
+
parentFrameId: record.parentFrameId ?? state.topFrameId ?? null,
|
|
79
|
+
url: '',
|
|
80
|
+
title: null,
|
|
81
|
+
sessionId: meta.sessionId ?? null,
|
|
82
|
+
});
|
|
83
|
+
reconcileTargetSelection(session);
|
|
84
|
+
});
|
|
85
|
+
session.handle.onEvent('Page.frameDetached', (params) => {
|
|
86
|
+
const record = params;
|
|
87
|
+
if (!record.frameId) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
removeFrame(session.tabId, record.frameId);
|
|
91
|
+
reconcileTargetSelection(session);
|
|
92
|
+
});
|
|
93
|
+
session.handle.onEvent('Page.domContentEventFired', () => {
|
|
94
|
+
events.onPageLoad?.();
|
|
95
|
+
});
|
|
96
|
+
session.handle.onEvent('Runtime.consoleAPICalled', (params) => {
|
|
97
|
+
events.onLog(toConsoleEvent(params, session, { ignoreMatcher, stripUrlPrefixes }));
|
|
98
|
+
});
|
|
99
|
+
session.handle.onEvent('Runtime.exceptionThrown', (params) => {
|
|
100
|
+
events.onLog(toExceptionEvent(params, session, { ignoreMatcher, stripUrlPrefixes }));
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=extension-session-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-session-events.js","sourceRoot":"","sources":["../../src/sources/extension-session-events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAA4B,MAAM,4BAA4B,CAAA;AACxG,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAe5E;;GAEG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAAC,EACrD,OAAO,EACP,MAAM,EACN,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GACsB,EAAQ,EAAE;IACjD,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,iCAAiC,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QAC1E,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAA;QAC7C,IA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M,MAAM,GAAG,MAA8B,CAAA;QAC7C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACrB,OAAM;QACP,CAAC;QACD,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;QAC1C,wBAAwB,CAAC,OAAO,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,UAAU,EAAE,EAAE,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,0BAA0B,EAAE,CAAC,MAAM,EAAE,EAAE;QAC7D,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAA;IACnF,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,yBAAyB,EAAE,CAAC,MAAM,EAAE,EAAE;QAC5D,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAA;IACrF,CAAC,CAAC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extension source for CDP access via Chrome extension Native Messaging.
|
|
3
|
-
* Wraps SessionManager and provides a unified source interface.
|
|
4
|
-
*/
|
|
5
1
|
import type { CdpSourceHandle, CdpSourceBaseOptions } from './types.js';
|
|
6
2
|
export type ExtensionSourceOptions = CdpSourceBaseOptions;
|
|
7
3
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-source.d.ts","sourceRoot":"","sources":["../../src/sources/extension-source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extension-source.d.ts","sourceRoot":"","sources":["../../src/sources/extension-source.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAmB,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAmBxF,MAAM,MAAM,sBAAsB,GAAG,oBAAoB,CAAA;AAEzD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAS,sBAAsB,KAAG,eAycvE,CAAA"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extension source for CDP access via Chrome extension Native Messaging.
|
|
3
|
-
* Wraps SessionManager and provides a unified source interface.
|
|
4
|
-
*/
|
|
5
1
|
import { createNativeMessaging } from '../native-messaging/messaging.js';
|
|
6
2
|
import { SessionManager } from '../native-messaging/session-manager.js';
|
|
7
|
-
import { buildFrameTargets, buildPageTarget, collectFrameTree, createEmptyFrameState, createNotAttachedError, frameToTarget, formatPageTargetId,
|
|
8
|
-
import {
|
|
3
|
+
import { buildFrameTargets, buildPageTarget, collectFrameTree, createRequestedFrameHint, createEmptyFrameState, createNotAttachedError, frameToTarget, formatPageTargetId, parseExtensionTargetId, resolveRequestedTarget, } from './extension-frame-state.js';
|
|
4
|
+
import { createDelegatingSession } from './extension-delegating-session.js';
|
|
5
|
+
import { registerExtensionSessionEventHandlers } from './extension-session-events.js';
|
|
9
6
|
/**
|
|
10
7
|
* Create an extension source that connects to Chrome via Native Messaging.
|
|
11
8
|
* Returns a handle that can be used to control the source and access CDP session.
|
|
@@ -47,20 +44,21 @@ export const createExtensionSource = (options) => {
|
|
|
47
44
|
emitStatus(null, reason);
|
|
48
45
|
events.onDetach?.(reason);
|
|
49
46
|
},
|
|
50
|
-
onTabsUpdated: () => {
|
|
51
|
-
// Tabs list updated - no action needed
|
|
52
|
-
},
|
|
47
|
+
onTabsUpdated: () => { },
|
|
53
48
|
onTargetSelected: (tabId, frameId) => {
|
|
54
49
|
const session = currentSession;
|
|
55
50
|
if (!session || session.tabId !== tabId) {
|
|
56
|
-
getOrCreateFrameState(tabId)
|
|
51
|
+
const state = getOrCreateFrameState(tabId);
|
|
52
|
+
setRequestedTargetSelection(state, frameId);
|
|
57
53
|
return;
|
|
58
54
|
}
|
|
59
55
|
requestTargetSelection(session, frameId);
|
|
60
56
|
},
|
|
61
57
|
});
|
|
62
58
|
// Proxy session follows the currently selected page/frame target inside the attached tab.
|
|
63
|
-
const proxySession = createDelegatingSession({
|
|
59
|
+
const { session: proxySession, controller: proxyController } = createDelegatingSession({
|
|
60
|
+
getCurrentSession: () => currentSession,
|
|
61
|
+
requireCurrentSession: getCurrentExtensionSession,
|
|
64
62
|
getTargetContext: () => getCurrentTargetContext() ?? { kind: 'page' },
|
|
65
63
|
mapParams: (method, params) => {
|
|
66
64
|
const targetContext = getCurrentTargetContext();
|
|
@@ -76,11 +74,14 @@ export const createExtensionSource = (options) => {
|
|
|
76
74
|
};
|
|
77
75
|
},
|
|
78
76
|
});
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
const pageSession = createDelegatingSession({
|
|
77
|
+
delegatingSessions.add(proxyController);
|
|
78
|
+
// Page session stays pinned to the top-level tab for page-scoped features like the indicator and inject-on-attach.
|
|
79
|
+
const { session: pageSession, controller: pageController } = createDelegatingSession({
|
|
80
|
+
getCurrentSession: () => currentSession,
|
|
81
|
+
requireCurrentSession: getCurrentExtensionSession,
|
|
82
82
|
getTargetContext: () => ({ kind: 'page' }),
|
|
83
83
|
});
|
|
84
|
+
delegatingSessions.add(pageController);
|
|
84
85
|
messaging.start();
|
|
85
86
|
sendHostInfo();
|
|
86
87
|
messaging.onDisconnect(() => {
|
|
@@ -115,7 +116,8 @@ export const createExtensionSource = (options) => {
|
|
|
115
116
|
const target = parseExtensionTargetId(targetId);
|
|
116
117
|
const session = currentSession;
|
|
117
118
|
if (!session || session.tabId !== target.tabId) {
|
|
118
|
-
getOrCreateFrameState(target.tabId)
|
|
119
|
+
const state = getOrCreateFrameState(target.tabId);
|
|
120
|
+
setRequestedTargetSelection(state, target.frameId);
|
|
119
121
|
sessionManager.attachTab(target.tabId);
|
|
120
122
|
return;
|
|
121
123
|
}
|
|
@@ -157,10 +159,24 @@ export const createExtensionSource = (options) => {
|
|
|
157
159
|
for (const controller of delegatingSessions) {
|
|
158
160
|
controller.dispose();
|
|
159
161
|
}
|
|
162
|
+
delegatingSessions.clear();
|
|
160
163
|
}
|
|
161
164
|
async function bootstrapAttachedSession(session) {
|
|
162
165
|
try {
|
|
163
|
-
|
|
166
|
+
registerExtensionSessionEventHandlers({
|
|
167
|
+
session,
|
|
168
|
+
events,
|
|
169
|
+
ignoreMatcher,
|
|
170
|
+
stripUrlPrefixes,
|
|
171
|
+
getOrCreateFrameState,
|
|
172
|
+
reconcileTargetSelection,
|
|
173
|
+
removeFrame,
|
|
174
|
+
refreshFrameTitle,
|
|
175
|
+
emitTargetChanged,
|
|
176
|
+
setCurrentSession: (nextSession) => {
|
|
177
|
+
currentSession = nextSession;
|
|
178
|
+
},
|
|
179
|
+
});
|
|
164
180
|
await enableBootstrapDomains(session);
|
|
165
181
|
await refreshFrameTree(session);
|
|
166
182
|
if (currentSession?.tabId !== session.tabId) {
|
|
@@ -188,103 +204,6 @@ export const createExtensionSource = (options) => {
|
|
|
188
204
|
await session.handle.sendAndWait('Runtime.enable');
|
|
189
205
|
await session.handle.sendAndWait('Page.enable');
|
|
190
206
|
}
|
|
191
|
-
function registerSessionEventHandlers(session) {
|
|
192
|
-
session.handle.onEvent('Runtime.executionContextCreated', (params, meta) => {
|
|
193
|
-
const context = parseExecutionContext(params);
|
|
194
|
-
if (!context?.isDefault || !context.frameId) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
const state = getOrCreateFrameState(session.tabId);
|
|
198
|
-
state.executionContexts.set(context.frameId, context.id);
|
|
199
|
-
const frame = state.frames.get(context.frameId);
|
|
200
|
-
if (frame) {
|
|
201
|
-
frame.sessionId = meta.sessionId ?? null;
|
|
202
|
-
}
|
|
203
|
-
void refreshFrameTitle(session, context.frameId, context.id);
|
|
204
|
-
reconcileTargetSelection(session);
|
|
205
|
-
});
|
|
206
|
-
session.handle.onEvent('Runtime.executionContextsCleared', () => {
|
|
207
|
-
const state = getOrCreateFrameState(session.tabId);
|
|
208
|
-
state.executionContexts.clear();
|
|
209
|
-
state.pendingTitleLoads.clear();
|
|
210
|
-
});
|
|
211
|
-
session.handle.onEvent('Runtime.executionContextDestroyed', (params) => {
|
|
212
|
-
const record = params;
|
|
213
|
-
if (record.executionContextId == null) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const state = getOrCreateFrameState(session.tabId);
|
|
217
|
-
for (const [frameId, contextId] of state.executionContexts.entries()) {
|
|
218
|
-
if (contextId === record.executionContextId) {
|
|
219
|
-
state.executionContexts.delete(frameId);
|
|
220
|
-
state.pendingTitleLoads.delete(frameId);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
session.handle.onEvent('Page.frameNavigated', (params, meta) => {
|
|
225
|
-
const frame = parseFrame(params);
|
|
226
|
-
if (!frame) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
const state = getOrCreateFrameState(session.tabId);
|
|
230
|
-
state.frames.set(frame.frameId, frame);
|
|
231
|
-
frame.sessionId = meta.sessionId ?? null;
|
|
232
|
-
if (!frame.parentFrameId) {
|
|
233
|
-
if (!meta.sessionId) {
|
|
234
|
-
state.topFrameId = frame.frameId;
|
|
235
|
-
session.url = frame.url;
|
|
236
|
-
}
|
|
237
|
-
else if (state.topFrameId == null) {
|
|
238
|
-
state.topFrameId = frame.parentFrameId;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else if (state.executionContexts.has(frame.frameId)) {
|
|
242
|
-
void refreshFrameTitle(session, frame.frameId);
|
|
243
|
-
}
|
|
244
|
-
currentSession = session;
|
|
245
|
-
if (!frame.parentFrameId && !meta.sessionId) {
|
|
246
|
-
events.onPageNavigation?.({ url: frame.url, title: session.title ?? null });
|
|
247
|
-
}
|
|
248
|
-
if (reconcileTargetSelection(session)) {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
if ((!frame.parentFrameId && state.activeFrameId == null) || state.activeFrameId === frame.frameId) {
|
|
252
|
-
emitTargetChanged(session);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
session.handle.onEvent('Page.frameAttached', (params, meta) => {
|
|
256
|
-
const record = params;
|
|
257
|
-
if (!record.frameId) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
const state = getOrCreateFrameState(session.tabId);
|
|
261
|
-
state.frames.set(record.frameId, {
|
|
262
|
-
frameId: record.frameId,
|
|
263
|
-
parentFrameId: record.parentFrameId ?? state.topFrameId ?? null,
|
|
264
|
-
url: '',
|
|
265
|
-
title: null,
|
|
266
|
-
sessionId: meta.sessionId ?? null,
|
|
267
|
-
});
|
|
268
|
-
reconcileTargetSelection(session);
|
|
269
|
-
});
|
|
270
|
-
session.handle.onEvent('Page.frameDetached', (params) => {
|
|
271
|
-
const record = params;
|
|
272
|
-
if (!record.frameId) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
removeFrame(session.tabId, record.frameId);
|
|
276
|
-
reconcileTargetSelection(session);
|
|
277
|
-
});
|
|
278
|
-
session.handle.onEvent('Page.domContentEventFired', () => {
|
|
279
|
-
events.onPageLoad?.();
|
|
280
|
-
});
|
|
281
|
-
session.handle.onEvent('Runtime.consoleAPICalled', (params) => {
|
|
282
|
-
events.onLog(toConsoleEvent(params, session, { ignoreMatcher, stripUrlPrefixes }));
|
|
283
|
-
});
|
|
284
|
-
session.handle.onEvent('Runtime.exceptionThrown', (params) => {
|
|
285
|
-
events.onLog(toExceptionEvent(params, session, { ignoreMatcher, stripUrlPrefixes }));
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
207
|
function getCurrentTargetContext() {
|
|
289
208
|
const session = currentSession;
|
|
290
209
|
if (!session) {
|
|
@@ -373,9 +292,15 @@ export const createExtensionSource = (options) => {
|
|
|
373
292
|
}
|
|
374
293
|
function requestTargetSelection(session, frameId) {
|
|
375
294
|
const state = getOrCreateFrameState(session.tabId);
|
|
376
|
-
state
|
|
295
|
+
setRequestedTargetSelection(state, frameId);
|
|
377
296
|
reconcileTargetSelection(session);
|
|
378
297
|
}
|
|
298
|
+
function setRequestedTargetSelection(state, frameId) {
|
|
299
|
+
const frame = frameId ? state.frames.get(frameId) : null;
|
|
300
|
+
state.requestedFrameId = frameId;
|
|
301
|
+
state.requestedFrameHint = createRequestedFrameHint(frame);
|
|
302
|
+
state.requestedFrameDetached = false;
|
|
303
|
+
}
|
|
379
304
|
/**
|
|
380
305
|
* Popup selection can arrive before the iframe's session is fully bootstrapped.
|
|
381
306
|
* Keep the request pending until the frame is discovered instead of routing commands
|
|
@@ -383,25 +308,36 @@ export const createExtensionSource = (options) => {
|
|
|
383
308
|
*/
|
|
384
309
|
function reconcileTargetSelection(session) {
|
|
385
310
|
const state = getOrCreateFrameState(session.tabId);
|
|
386
|
-
const
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
state.activeAttachedAt = Date.now();
|
|
391
|
-
emitTargetChanged(session);
|
|
392
|
-
return true;
|
|
393
|
-
}
|
|
394
|
-
return false;
|
|
395
|
-
}
|
|
396
|
-
state.activeFrameId = null;
|
|
397
|
-
state.activeAttachedAt = Date.now();
|
|
398
|
-
emitTargetChanged(session);
|
|
399
|
-
return true;
|
|
311
|
+
const resolution = resolveRequestedTarget(state);
|
|
312
|
+
if (resolution.kind === 'page') {
|
|
313
|
+
state.requestedFrameDetached = false;
|
|
314
|
+
return activatePageTarget(session, state);
|
|
400
315
|
}
|
|
401
|
-
if (
|
|
316
|
+
if (resolution.kind === 'pending') {
|
|
402
317
|
return false;
|
|
403
318
|
}
|
|
404
|
-
state.
|
|
319
|
+
state.requestedFrameDetached = false;
|
|
320
|
+
if (state.activeFrameId === resolution.frameId) {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
return activateFrameTarget(session, state, resolution.frameId);
|
|
324
|
+
}
|
|
325
|
+
function activatePageTarget(session, state) {
|
|
326
|
+
if (state.activeFrameId == null) {
|
|
327
|
+
if (state.activeAttachedAt == null) {
|
|
328
|
+
state.activeAttachedAt = Date.now();
|
|
329
|
+
emitTargetChanged(session);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
state.activeFrameId = null;
|
|
335
|
+
state.activeAttachedAt = Date.now();
|
|
336
|
+
emitTargetChanged(session);
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
function activateFrameTarget(session, state, frameId) {
|
|
340
|
+
state.activeFrameId = frameId;
|
|
405
341
|
state.activeAttachedAt = Date.now();
|
|
406
342
|
emitTargetChanged(session);
|
|
407
343
|
return true;
|
|
@@ -418,8 +354,14 @@ export const createExtensionSource = (options) => {
|
|
|
418
354
|
for (const childId of childIds) {
|
|
419
355
|
removeFrame(tabId, childId);
|
|
420
356
|
}
|
|
421
|
-
|
|
422
|
-
|
|
357
|
+
/**
|
|
358
|
+
* Keep the user's requested iframe selection across reload/navigation detaches.
|
|
359
|
+
* Frame ids are ephemeral, so the stored frame hint lets selection survive a fresh id after reload.
|
|
360
|
+
*/
|
|
361
|
+
if (state.activeFrameId === frameId) {
|
|
362
|
+
state.requestedFrameDetached = state.requestedFrameId === frameId;
|
|
363
|
+
state.activeFrameId = null;
|
|
364
|
+
state.activeAttachedAt = null;
|
|
423
365
|
}
|
|
424
366
|
state.frames.delete(frameId);
|
|
425
367
|
state.executionContexts.delete(frameId);
|
|
@@ -467,55 +409,6 @@ export const createExtensionSource = (options) => {
|
|
|
467
409
|
state.pendingTitleLoads.delete(frameId);
|
|
468
410
|
}
|
|
469
411
|
}
|
|
470
|
-
function createDelegatingSession(config) {
|
|
471
|
-
const subscriptions = new Set();
|
|
472
|
-
const rebindSubscriptions = () => {
|
|
473
|
-
// Delegating sessions are created before a tab may be attached, so event listeners
|
|
474
|
-
// must follow the active extension session instead of binding once and going stale.
|
|
475
|
-
for (const subscription of subscriptions) {
|
|
476
|
-
subscription.unbind();
|
|
477
|
-
if (!currentSession) {
|
|
478
|
-
continue;
|
|
479
|
-
}
|
|
480
|
-
subscription.off = currentSession.handle.onEvent(subscription.method, subscription.handler);
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
const disposeSubscriptions = () => {
|
|
484
|
-
for (const subscription of subscriptions) {
|
|
485
|
-
subscription.unbind();
|
|
486
|
-
}
|
|
487
|
-
subscriptions.clear();
|
|
488
|
-
};
|
|
489
|
-
const controller = {
|
|
490
|
-
rebind: rebindSubscriptions,
|
|
491
|
-
dispose: () => {
|
|
492
|
-
disposeSubscriptions();
|
|
493
|
-
delegatingSessions.delete(controller);
|
|
494
|
-
},
|
|
495
|
-
};
|
|
496
|
-
delegatingSessions.add(controller);
|
|
497
|
-
controller.rebind();
|
|
498
|
-
return {
|
|
499
|
-
isAttached: () => currentSession?.handle.isAttached() ?? false,
|
|
500
|
-
sendAndWait: async (method, params, options) => {
|
|
501
|
-
const session = getCurrentExtensionSession();
|
|
502
|
-
const targetContext = config.getTargetContext();
|
|
503
|
-
const nextParams = config.mapParams ? config.mapParams(method, params) : params;
|
|
504
|
-
const nextOptions = targetContext.kind === 'frame' && targetContext.sessionId ? { ...(options ?? {}), sessionId: targetContext.sessionId } : options;
|
|
505
|
-
return session.handle.sendAndWait(method, nextParams, nextOptions);
|
|
506
|
-
},
|
|
507
|
-
onEvent: (method, handler) => {
|
|
508
|
-
const subscription = createDelegatingEventSubscription(method, handler);
|
|
509
|
-
subscriptions.add(subscription);
|
|
510
|
-
controller.rebind();
|
|
511
|
-
return () => {
|
|
512
|
-
subscription.unbind();
|
|
513
|
-
subscriptions.delete(subscription);
|
|
514
|
-
};
|
|
515
|
-
},
|
|
516
|
-
getTargetContext: config.getTargetContext,
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
412
|
};
|
|
520
413
|
/**
|
|
521
414
|
* Convert TabInfo to CdpSourceTarget.
|
|
@@ -528,13 +421,4 @@ const tabToTarget = (tab) => ({
|
|
|
528
421
|
faviconUrl: tab.faviconUrl,
|
|
529
422
|
attached: tab.attached,
|
|
530
423
|
});
|
|
531
|
-
const createDelegatingEventSubscription = (method, handler) => ({
|
|
532
|
-
method,
|
|
533
|
-
handler,
|
|
534
|
-
off: null,
|
|
535
|
-
unbind() {
|
|
536
|
-
this.off?.();
|
|
537
|
-
this.off = null;
|
|
538
|
-
},
|
|
539
|
-
});
|
|
540
424
|
//# sourceMappingURL=extension-source.js.map
|