extension 4.0.1 → 4.0.2-canary.local-d776e4d9
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/{315.cjs → 876.cjs} +55 -703
- package/dist/browsers.cjs +298 -896
- package/dist/cli.cjs +341 -1183
- package/dist/extension/browsers/browsers-lib/browser-family.d.ts +3 -0
- package/dist/extension/browsers/browsers-lib/messages.d.ts +0 -116
- package/dist/extension/browsers/browsers-lib/runtime-options.d.ts +1 -1
- package/dist/extension/browsers/browsers-types.d.ts +0 -55
- package/dist/extension/browsers/index.d.ts +1 -14
- package/dist/extension/browsers/run-chromium/cdp/cdp-client.d.ts +50 -0
- package/dist/extension/browsers/run-chromium/{chromium-source-inspection → cdp}/cdp-extension-controller/index.d.ts +0 -3
- package/dist/extension/browsers/run-chromium/{chromium-source-inspection → cdp}/extensions.d.ts +0 -2
- package/dist/extension/browsers/run-chromium/chromium-context/index.d.ts +1 -1
- package/dist/extension/browsers/run-chromium/chromium-types.d.ts +1 -1
- package/dist/extension/browsers/run-firefox/firefox-context/index.d.ts +1 -1
- package/dist/extension/browsers/run-firefox/firefox-launch/setup-rdp-after-launch.d.ts +1 -1
- package/dist/extension/browsers/run-firefox/firefox-types.d.ts +2 -3
- package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/rdp-extension-controller/index.d.ts +1 -11
- package/dist/extension/browsers/run-firefox/rdp/remote-firefox/evaluate.d.ts +9 -0
- package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/firefox-utils.d.ts +0 -1
- package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/index.d.ts +0 -15
- package/dist/extension/browsers/run-firefox/rdp/remote-firefox/messaging-client.d.ts +18 -0
- package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/moz-id.d.ts +1 -0
- package/dist/extension/browsers/run-firefox/rdp/remote-firefox/rdp-api.d.ts +19 -0
- package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/rdp-types.d.ts +0 -27
- package/dist/extension/config-types.d.ts +0 -2
- package/dist/extension/helpers/messages.d.ts +0 -11
- package/dist/extension/helpers/normalize-options.d.ts +0 -20
- package/package.json +4 -4
- package/dist/632.cjs +0 -104
- package/dist/extension/browsers/browsers-lib/content-script-contracts.d.ts +0 -2
- package/dist/extension/browsers/browsers-lib/content-script-targets.d.ts +0 -44
- package/dist/extension/browsers/browsers-lib/normalize-options.d.ts +0 -12
- package/dist/extension/browsers/browsers-lib/source-output.d.ts +0 -86
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/cdp-client.d.ts +0 -78
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/deterministic-hmr-harness.d.ts +0 -21
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/extract.d.ts +0 -2
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/index.d.ts +0 -80
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/page.d.ts +0 -45
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/readiness.d.ts +0 -1
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/sessions.d.ts +0 -2
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/targets.d.ts +0 -7
- package/dist/extension/browsers/run-chromium/chromium-unified-logger/index.d.ts +0 -22
- package/dist/extension/browsers/run-chromium/chromium-unified-logger/unified-logging.d.ts +0 -2
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/index.d.ts +0 -56
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/evaluate.d.ts +0 -19
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/messaging-client.d.ts +0 -36
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/rdp-api.d.ts +0 -25
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/runtime-reinject.d.ts +0 -7
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/setup-firefox-inspection-actors.d.ts +0 -5
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/setup-firefox-inspection-navigation.d.ts +0 -2
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/source-inspect.d.ts +0 -9
- package/dist/extension/browsers/run-firefox/firefox-unified-logger/index.d.ts +0 -14
- /package/dist/extension/browsers/run-chromium/{chromium-source-inspection → cdp}/cdp-extension-controller/connect.d.ts +0 -0
- /package/dist/extension/browsers/run-chromium/{chromium-source-inspection → cdp}/cdp-extension-controller/derive-id.d.ts +0 -0
- /package/dist/extension/browsers/run-chromium/{chromium-source-inspection → cdp}/cdp-extension-controller/ensure.d.ts +0 -0
- /package/dist/extension/browsers/run-chromium/{chromium-source-inspection → cdp}/cdp-extension-controller/logging.d.ts +0 -0
- /package/dist/extension/browsers/run-chromium/{chromium-source-inspection → cdp}/cdp-extension-controller/ownership.d.ts +0 -0
- /package/dist/extension/browsers/run-chromium/{chromium-source-inspection → cdp}/discovery.d.ts +0 -0
- /package/dist/extension/browsers/run-chromium/{chromium-source-inspection → cdp}/ws.d.ts +0 -0
- /package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/addons-install.d.ts +0 -0
- /package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/addons.d.ts +0 -0
- /package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/logging.d.ts +0 -0
- /package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/message-utils.d.ts +0 -0
- /package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/rdp-wire.d.ts +0 -0
- /package/dist/extension/browsers/run-firefox/{firefox-source-inspection → rdp}/remote-firefox/transport.d.ts +0 -0
package/dist/{315.cjs → 876.cjs}
RENAMED
|
@@ -1,8 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
exports.ids = [
|
|
3
|
-
|
|
3
|
+
876
|
|
4
4
|
];
|
|
5
5
|
exports.modules = {
|
|
6
|
+
"./browsers/run-chromium/cdp/cdp-extension-controller/ensure.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
7
|
+
var fs__rspack_import_0 = __webpack_require__("fs");
|
|
8
|
+
var path__rspack_import_1 = __webpack_require__("path");
|
|
9
|
+
async function loadUnpackedIfNeeded(cdp, outPath) {
|
|
10
|
+
try {
|
|
11
|
+
const response = await cdp.sendCommand('Extensions.loadUnpacked', {
|
|
12
|
+
extensionPath: outPath,
|
|
13
|
+
options: {
|
|
14
|
+
failOnError: false
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const id = String(response?.extensionId || '');
|
|
18
|
+
return id || null;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function readManifestInfo(outPath) {
|
|
24
|
+
try {
|
|
25
|
+
const manifestPath = path__rspack_import_1.join(outPath, 'manifest.json');
|
|
26
|
+
const manifest = JSON.parse(fs__rspack_import_0.readFileSync(manifestPath, 'utf-8'));
|
|
27
|
+
return {
|
|
28
|
+
name: manifest?.name,
|
|
29
|
+
version: manifest?.version
|
|
30
|
+
};
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
M: ()=>readManifestInfo,
|
|
37
|
+
loadUnpackedIfNeeded: ()=>loadUnpackedIfNeeded
|
|
38
|
+
});
|
|
39
|
+
},
|
|
6
40
|
"./browsers/run-chromium/chromium-launch/setup-cdp-after-launch.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
7
41
|
__webpack_require__.d(__webpack_exports__, {
|
|
8
42
|
setupCdpAfterLaunch: ()=>setupCdpAfterLaunch
|
|
@@ -15,475 +49,29 @@ exports.modules = {
|
|
|
15
49
|
var external_ws_ = __webpack_require__("ws");
|
|
16
50
|
var external_ws_default = /*#__PURE__*/ __webpack_require__.n(external_ws_);
|
|
17
51
|
var constants = __webpack_require__("./browsers/browsers-lib/constants.ts");
|
|
18
|
-
var discovery = __webpack_require__("./browsers/run-chromium/
|
|
52
|
+
var discovery = __webpack_require__("./browsers/run-chromium/cdp/discovery.ts");
|
|
19
53
|
async function getExtensionInfo(cdp, extensionId) {
|
|
20
54
|
return await cdp.sendCommand('Extensions.getExtensionInfo', {
|
|
21
55
|
extensionId
|
|
22
56
|
});
|
|
23
57
|
}
|
|
24
|
-
async function loadUnpackedExtension(cdp, absPath) {
|
|
25
|
-
const response = await cdp.sendCommand('Extensions.loadUnpacked', {
|
|
26
|
-
extensionPath: absPath,
|
|
27
|
-
options: {
|
|
28
|
-
failOnError: false
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
return String(response?.extensionId || '');
|
|
32
|
-
}
|
|
33
|
-
async function unloadExtension(cdp, extensionId) {
|
|
34
|
-
try {
|
|
35
|
-
await cdp.sendCommand('Extensions.unload', {
|
|
36
|
-
extensionId
|
|
37
|
-
});
|
|
38
|
-
return true;
|
|
39
|
-
} catch {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function mergeShadowIntoDocument(mainHTML, shadowContent) {
|
|
44
|
-
try {
|
|
45
|
-
if (!mainHTML) return '';
|
|
46
|
-
const hasRoot = /<div id=(["'])extension-root\1/i.test(mainHTML);
|
|
47
|
-
if (hasRoot) {
|
|
48
|
-
const emptyRoot = /<div id=(["'])extension-root\1[^>]*><\/div>/i;
|
|
49
|
-
const replacedEmpty = mainHTML.replace(emptyRoot, `<div id="extension-root">${shadowContent}</div>`);
|
|
50
|
-
if (replacedEmpty !== mainHTML) return replacedEmpty;
|
|
51
|
-
return mainHTML.replace(/<div id=(["'])extension-root\1[^>]*>[\s\S]*?<\/div>/i, `<div id="extension-root">${shadowContent}</div>`);
|
|
52
|
-
}
|
|
53
|
-
const hostOpen = /(<[^>]*data-extension-root=(["'])true\2[^>]*>)/i;
|
|
54
|
-
if (hostOpen.test(mainHTML)) return mainHTML.replace(hostOpen, `$1<div id="extension-root">${shadowContent}</div>`);
|
|
55
|
-
return mainHTML;
|
|
56
|
-
} catch {
|
|
57
|
-
return mainHTML;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const CONTENT_ROOT_SELECTOR = '#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])';
|
|
61
|
-
const EXTENSION_ROOT_META_EXPRESSION = `(() => {
|
|
62
|
-
const readGeneration = (node) => {
|
|
63
|
-
try {
|
|
64
|
-
const raw = node && node.getAttribute
|
|
65
|
-
? node.getAttribute('data-extjs-reinject-generation')
|
|
66
|
-
: '';
|
|
67
|
-
const parsed = Number(raw);
|
|
68
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
69
|
-
} catch (error) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const normalize = (node) => ({
|
|
74
|
-
tag: node && node.tagName ? String(node.tagName).toLowerCase() : 'unknown',
|
|
75
|
-
id: node && node.id ? String(node.id) : undefined,
|
|
76
|
-
key: node && node.getAttribute ? node.getAttribute('data-extjs-reinject-key') || undefined : undefined,
|
|
77
|
-
generation: readGeneration(node),
|
|
78
|
-
status: node && node.getAttribute ? node.getAttribute('data-extjs-reinject-status') || undefined : undefined,
|
|
79
|
-
build: node && node.getAttribute ? node.getAttribute('data-extjs-reinject-build') || undefined : undefined,
|
|
80
|
-
hasShadowRoot: !!(node && node.shadowRoot),
|
|
81
|
-
hasShadowContent: !!(node && node.shadowRoot && String(node.shadowRoot.innerHTML || '').trim())
|
|
82
|
-
});
|
|
83
|
-
const registry = (typeof globalThis === 'object' && globalThis)
|
|
84
|
-
? (globalThis.__EXTENSIONJS_DEV_REINJECT__ || {})
|
|
85
|
-
: {};
|
|
86
|
-
const registries = Object.entries(registry)
|
|
87
|
-
.slice(0, 10)
|
|
88
|
-
.map(([key, entry]) => {
|
|
89
|
-
const candidate = entry && typeof entry === 'object' ? entry : {};
|
|
90
|
-
const cleanup = candidate && typeof candidate.cleanup === 'function'
|
|
91
|
-
? candidate.cleanup
|
|
92
|
-
: (typeof entry === 'function' ? entry : undefined);
|
|
93
|
-
return {
|
|
94
|
-
key,
|
|
95
|
-
generation: typeof candidate.generation === 'number'
|
|
96
|
-
? candidate.generation
|
|
97
|
-
: (cleanup && typeof cleanup.__extjsGeneration === 'number'
|
|
98
|
-
? cleanup.__extjsGeneration
|
|
99
|
-
: undefined),
|
|
100
|
-
hasCleanup: typeof cleanup === 'function',
|
|
101
|
-
build: typeof candidate.build === 'string'
|
|
102
|
-
? candidate.build
|
|
103
|
-
: (cleanup && typeof cleanup.__extjsBuild === 'string'
|
|
104
|
-
? cleanup.__extjsBuild
|
|
105
|
-
: undefined)
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
const pageCandidate = {
|
|
109
|
-
key: document.documentElement.getAttribute('data-extjs-last-reinject-key') || undefined,
|
|
110
|
-
generation: (() => {
|
|
111
|
-
const parsed = Number(document.documentElement.getAttribute('data-extjs-last-reinject-generation') || '');
|
|
112
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
113
|
-
})(),
|
|
114
|
-
status: document.documentElement.getAttribute('data-extjs-last-reinject-status') || undefined,
|
|
115
|
-
build: document.documentElement.getAttribute('data-extjs-last-reinject-build') || undefined
|
|
116
|
-
};
|
|
117
|
-
const roots = Array.from(
|
|
118
|
-
document.querySelectorAll('#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])')
|
|
119
|
-
)
|
|
120
|
-
.slice(0, 10)
|
|
121
|
-
.map(normalize)
|
|
122
|
-
.filter((entry) =>
|
|
123
|
-
entry.hasShadowRoot ||
|
|
124
|
-
entry.hasShadowContent ||
|
|
125
|
-
typeof entry.key === 'string' ||
|
|
126
|
-
typeof entry.generation === 'number' ||
|
|
127
|
-
typeof entry.status === 'string' ||
|
|
128
|
-
typeof entry.build === 'string'
|
|
129
|
-
)
|
|
130
|
-
.map(({hasShadowRoot, hasShadowContent, ...entry}) => entry);
|
|
131
|
-
const markers = Array.from(
|
|
132
|
-
document.querySelectorAll('[data-extjs-reinject-marker="true"]')
|
|
133
|
-
)
|
|
134
|
-
.slice(0, 10)
|
|
135
|
-
.map(normalize);
|
|
136
|
-
const pageHasBackingEvidence =
|
|
137
|
-
roots.length > 0 ||
|
|
138
|
-
markers.length > 0 ||
|
|
139
|
-
registries.some((entry) =>
|
|
140
|
-
entry.key === pageCandidate.key ||
|
|
141
|
-
typeof entry.generation === 'number' ||
|
|
142
|
-
!!entry.hasCleanup ||
|
|
143
|
-
typeof entry.build === 'string'
|
|
144
|
-
);
|
|
145
|
-
const page = pageHasBackingEvidence ? pageCandidate : undefined;
|
|
146
|
-
const generations = roots
|
|
147
|
-
.concat(markers)
|
|
148
|
-
.map((entry) => entry.generation)
|
|
149
|
-
.concat(page && typeof page.generation === 'number' ? [page.generation] : [])
|
|
150
|
-
.concat(
|
|
151
|
-
registries
|
|
152
|
-
.map((entry) => entry.generation)
|
|
153
|
-
.filter((value) => typeof value === 'number')
|
|
154
|
-
)
|
|
155
|
-
.filter((value) => typeof value === 'number');
|
|
156
|
-
return {
|
|
157
|
-
rootCount: roots.length,
|
|
158
|
-
markerCount: markers.length,
|
|
159
|
-
latestGeneration: generations.length ? Math.max(...generations) : 0,
|
|
160
|
-
roots,
|
|
161
|
-
markers,
|
|
162
|
-
registries,
|
|
163
|
-
page
|
|
164
|
-
};
|
|
165
|
-
})()`;
|
|
166
|
-
const SHADOW_STYLE_SNAPSHOT_EXPRESSION = `(() => {
|
|
167
|
-
try {
|
|
168
|
-
const hosts = Array.from(document.querySelectorAll('#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])'));
|
|
169
|
-
if (!hosts.length) return null;
|
|
170
|
-
for (const host of hosts) {
|
|
171
|
-
const sr = host && host.shadowRoot;
|
|
172
|
-
if (!sr) continue;
|
|
173
|
-
const styles = Array.from(sr.querySelectorAll('style')).map((styleEl) => {
|
|
174
|
-
const html = String(styleEl.outerHTML || '');
|
|
175
|
-
const text = String(styleEl.textContent || '');
|
|
176
|
-
return {
|
|
177
|
-
html,
|
|
178
|
-
textLength: text.length,
|
|
179
|
-
textSnippet: text.trim().slice(0, 200)
|
|
180
|
-
};
|
|
181
|
-
});
|
|
182
|
-
return {
|
|
183
|
-
rootMode: 'shadow',
|
|
184
|
-
count: styles.length,
|
|
185
|
-
styles
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
return null;
|
|
189
|
-
} catch {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
})()`;
|
|
193
|
-
const HAS_VISIBLE_SHADOW_HOST_EXPRESSION = `(() => { try {
|
|
194
|
-
const hosts = Array.from(document.querySelectorAll('#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])'));
|
|
195
|
-
if (!hosts.length) return false;
|
|
196
|
-
for (const h of hosts) {
|
|
197
|
-
try {
|
|
198
|
-
const sr = h && h.shadowRoot;
|
|
199
|
-
if (sr && (String(sr.innerHTML||'').length > 0)) return true;
|
|
200
|
-
} catch { /* ignore */ }
|
|
201
|
-
}
|
|
202
|
-
return false;
|
|
203
|
-
} catch { return false } })()`;
|
|
204
|
-
async function collectExecutionContexts(cdp, sessionId) {
|
|
205
|
-
const rawCdp = cdp;
|
|
206
|
-
if ('function' != typeof rawCdp.sendCommand || 'function' != typeof rawCdp.onProtocolEvent) return [];
|
|
207
|
-
const contextsById = new Map();
|
|
208
|
-
const unsubscribe = rawCdp.onProtocolEvent((message)=>{
|
|
209
|
-
if (String(message.sessionId || '') !== sessionId) return;
|
|
210
|
-
if ('Runtime.executionContextCreated' !== String(message.method || '')) return;
|
|
211
|
-
const context = message.params?.context;
|
|
212
|
-
const contextId = context?.id;
|
|
213
|
-
if ('number' == typeof contextId) contextsById.set(contextId, context);
|
|
214
|
-
});
|
|
215
|
-
try {
|
|
216
|
-
await rawCdp.sendCommand('Runtime.enable', {}, sessionId, 3000);
|
|
217
|
-
await new Promise((resolve)=>setTimeout(resolve, 100));
|
|
218
|
-
} catch {
|
|
219
|
-
return [];
|
|
220
|
-
} finally{
|
|
221
|
-
unsubscribe();
|
|
222
|
-
}
|
|
223
|
-
return Array.from(contextsById.values());
|
|
224
|
-
}
|
|
225
|
-
async function getIsolatedContextId(cdp, sessionId) {
|
|
226
|
-
const contexts = await collectExecutionContexts(cdp, sessionId);
|
|
227
|
-
const preferredContext = contexts.find((context)=>{
|
|
228
|
-
const auxData = context?.auxData || {};
|
|
229
|
-
return 'isolated' === auxData.type && String(context?.origin || '').startsWith('chrome-extension://');
|
|
230
|
-
});
|
|
231
|
-
if ('number' == typeof preferredContext?.id) return preferredContext.id;
|
|
232
|
-
const fallbackContext = contexts.find((context)=>context?.auxData?.type === 'isolated');
|
|
233
|
-
return 'number' == typeof fallbackContext?.id ? fallbackContext.id : void 0;
|
|
234
|
-
}
|
|
235
|
-
async function evaluateWithContentContext(cdp, sessionId, expression, shouldAccept) {
|
|
236
|
-
let pageResult;
|
|
237
|
-
try {
|
|
238
|
-
pageResult = await cdp.evaluate(sessionId, expression);
|
|
239
|
-
if (shouldAccept(pageResult)) return pageResult;
|
|
240
|
-
} catch {}
|
|
241
|
-
try {
|
|
242
|
-
const isolatedContextId = await getIsolatedContextId(cdp, sessionId);
|
|
243
|
-
if ('number' == typeof isolatedContextId) {
|
|
244
|
-
const isolatedResult = await cdp.evaluateInContext(sessionId, expression, isolatedContextId);
|
|
245
|
-
if (shouldAccept(isolatedResult)) return isolatedResult;
|
|
246
|
-
if (void 0 !== pageResult) return pageResult;
|
|
247
|
-
return isolatedResult;
|
|
248
|
-
}
|
|
249
|
-
} catch {}
|
|
250
|
-
return pageResult;
|
|
251
|
-
}
|
|
252
|
-
function isExtensionRootMetaPayload(value) {
|
|
253
|
-
if (!value || 'object' != typeof value) return false;
|
|
254
|
-
const v = value;
|
|
255
|
-
return 'number' == typeof v.rootCount && 'number' == typeof v.markerCount && 'number' == typeof v.latestGeneration && Array.isArray(v.roots) && Array.isArray(v.markers) && Array.isArray(v.registries);
|
|
256
|
-
}
|
|
257
|
-
async function evaluateExtensionRootMeta(cdp, sessionId) {
|
|
258
|
-
try {
|
|
259
|
-
const payload = await evaluateWithContentContext(cdp, sessionId, EXTENSION_ROOT_META_EXPRESSION, isExtensionRootMetaPayload);
|
|
260
|
-
return payload;
|
|
261
|
-
} catch {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
async function evaluateShadowStyleSnapshot(cdp, sessionId) {
|
|
266
|
-
try {
|
|
267
|
-
const payload = await evaluateWithContentContext(cdp, sessionId, SHADOW_STYLE_SNAPSHOT_EXPRESSION, (value)=>null === value || 'object' == typeof value && null !== value);
|
|
268
|
-
if (null == payload) return;
|
|
269
|
-
return payload;
|
|
270
|
-
} catch {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
async function pollForVisibleShadowHostContent(cdp, sessionId, deadlineMs = 4000) {
|
|
275
|
-
const deadline = Date.now() + deadlineMs;
|
|
276
|
-
const started = Date.now();
|
|
277
|
-
while(Date.now() < deadline){
|
|
278
|
-
try {
|
|
279
|
-
const hasRoot = await hasVisibleShadowHostContent(cdp, sessionId);
|
|
280
|
-
if (hasRoot) return;
|
|
281
|
-
} catch {}
|
|
282
|
-
const elapsed = Date.now() - started;
|
|
283
|
-
const delay = elapsed < 1000 ? 150 : 350;
|
|
284
|
-
await new Promise((r)=>setTimeout(r, delay));
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
async function hasVisibleShadowHostContent(cdp, sessionId) {
|
|
288
|
-
try {
|
|
289
|
-
const v = await evaluateWithContentContext(cdp, sessionId, HAS_VISIBLE_SHADOW_HOST_EXPRESSION, (value)=>true === value || false === value);
|
|
290
|
-
return true === v;
|
|
291
|
-
} catch {
|
|
292
|
-
return false;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
async function getPageHTML(cdp, sessionId, includeShadow = 'open-only') {
|
|
296
|
-
try {
|
|
297
|
-
await cdp.evaluate(sessionId, 'document.title');
|
|
298
|
-
} catch {}
|
|
299
|
-
const mainHTMLRaw = await cdp.evaluate(sessionId, `(() => {
|
|
300
|
-
try {
|
|
301
|
-
const serialize = () => {
|
|
302
|
-
const doctype = document.doctype
|
|
303
|
-
const dt = doctype
|
|
304
|
-
? '<!DOCTYPE '
|
|
305
|
-
+ doctype.name
|
|
306
|
-
+ (doctype.publicId ? ' PUBLIC "' + doctype.publicId + '"' : '')
|
|
307
|
-
+ (doctype.systemId ? ' "' + doctype.systemId + '"' : '')
|
|
308
|
-
+ '>'
|
|
309
|
-
: ''
|
|
310
|
-
return dt + '\n' + document.documentElement.outerHTML
|
|
311
|
-
}
|
|
312
|
-
return serialize()
|
|
313
|
-
} catch (e) {
|
|
314
|
-
return ''
|
|
315
|
-
}
|
|
316
|
-
})()`);
|
|
317
|
-
const mainHTML = 'string' == typeof mainHTMLRaw ? mainHTMLRaw : String(mainHTMLRaw || '');
|
|
318
|
-
if ('off' === includeShadow) return mainHTML;
|
|
319
|
-
const hasVisibleContentRoot = await evaluateWithContentContext(cdp, sessionId, `(() => {
|
|
320
|
-
try {
|
|
321
|
-
return !!document.querySelector(${JSON.stringify(CONTENT_ROOT_SELECTOR)})
|
|
322
|
-
} catch {
|
|
323
|
-
return false
|
|
324
|
-
}
|
|
325
|
-
})()`, (value)=>'boolean' == typeof value);
|
|
326
|
-
if (!hasVisibleContentRoot) return mainHTML;
|
|
327
|
-
try {
|
|
328
|
-
const mergedHtmlRaw = await evaluateWithContentContext(cdp, sessionId, `(() => { try {
|
|
329
|
-
var cloned = document.documentElement.cloneNode(true);
|
|
330
|
-
var selector = ${JSON.stringify(CONTENT_ROOT_SELECTOR)};
|
|
331
|
-
var s = new XMLSerializer();
|
|
332
|
-
try {
|
|
333
|
-
var liveHosts = Array.from(document.querySelectorAll(selector));
|
|
334
|
-
if (!liveHosts.length) return '';
|
|
335
|
-
var clonedHosts = Array.from(cloned.querySelectorAll(selector));
|
|
336
|
-
if (clonedHosts.length < liveHosts.length) {
|
|
337
|
-
var cloneDoc = cloned.ownerDocument || document;
|
|
338
|
-
var cloneBody = cloned.querySelector('body') || cloned;
|
|
339
|
-
for (var missingIndex = clonedHosts.length; missingIndex < liveHosts.length; missingIndex++) {
|
|
340
|
-
var missingLiveHost = liveHosts[missingIndex];
|
|
341
|
-
if (!missingLiveHost || !missingLiveHost.tagName || !cloneBody || typeof cloneBody.appendChild !== 'function') continue;
|
|
342
|
-
var shell = cloneDoc.createElement(String(missingLiveHost.tagName || 'div').toLowerCase());
|
|
343
|
-
try {
|
|
344
|
-
Array.from(missingLiveHost.attributes || []).forEach(function(attr){
|
|
345
|
-
try { shell.setAttribute(attr.name, attr.value); } catch(_) {}
|
|
346
|
-
});
|
|
347
|
-
} catch(_) {}
|
|
348
|
-
try { cloneBody.appendChild(shell); } catch(_) {}
|
|
349
|
-
clonedHosts.push(shell);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
for (var index = 0; index < liveHosts.length; index++) {
|
|
353
|
-
var host = clonedHosts[index];
|
|
354
|
-
var liveHost = liveHosts[index];
|
|
355
|
-
if (!host || !liveHost || !liveHost.shadowRoot) continue;
|
|
356
|
-
var shadow = Array.from(liveHost.shadowRoot.childNodes).map(function(n){
|
|
357
|
-
try { return s.serializeToString(n) } catch(e){ return '' }
|
|
358
|
-
}).join('');
|
|
359
|
-
if (!shadow) continue;
|
|
360
|
-
try { host.innerHTML = shadow; } catch(e) {}
|
|
361
|
-
}
|
|
362
|
-
} catch(e) {}
|
|
363
|
-
var doctype = document.doctype;
|
|
364
|
-
var dt = doctype ? '<!DOCTYPE ' + doctype.name + (doctype.publicId ? ' PUBLIC \"' + doctype.publicId + '\"' : '') + (doctype.systemId ? ' \"' + doctype.systemId + '\"' : '') + '>' : '';
|
|
365
|
-
return String(dt + '\\n' + (cloned.outerHTML || document.documentElement.outerHTML));
|
|
366
|
-
} catch(e) { try { return String(document.documentElement.outerHTML); } catch(_) { return '' } } })()`, (value)=>'string' == typeof value && /<html[\s>]/i.test(value));
|
|
367
|
-
const mergedHtml = 'string' == typeof mergedHtmlRaw ? mergedHtmlRaw : String(mergedHtmlRaw || '');
|
|
368
|
-
if (mergedHtml && /<html[\s>]/i.test(mergedHtml)) return mergedHtml;
|
|
369
|
-
} catch {}
|
|
370
|
-
let shadowContent = '';
|
|
371
|
-
try {
|
|
372
|
-
shadowContent = await evaluateWithContentContext(cdp, sessionId, `(() => {
|
|
373
|
-
try {
|
|
374
|
-
const hosts = Array.from(document.querySelectorAll(${JSON.stringify(CONTENT_ROOT_SELECTOR)}));
|
|
375
|
-
if (!hosts.length) return '';
|
|
376
|
-
const preferMarkers = ['iskilar_box','content_script','content_title','js-probe'];
|
|
377
|
-
let firstNonEmpty = '';
|
|
378
|
-
for (const host of hosts) {
|
|
379
|
-
try {
|
|
380
|
-
const sr = host && host.shadowRoot;
|
|
381
|
-
if (!sr) continue;
|
|
382
|
-
const html = String(sr.innerHTML || '');
|
|
383
|
-
if (html && html.length) {
|
|
384
|
-
if (preferMarkers.some((m) => html.includes(m))) return html;
|
|
385
|
-
if (!firstNonEmpty) firstNonEmpty = html;
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
|
-
try {
|
|
389
|
-
const parts = Array.from(sr.children)
|
|
390
|
-
.map((n) => (n && n.outerHTML) ? String(n.outerHTML) : '')
|
|
391
|
-
.join('');
|
|
392
|
-
if (parts && parts.length) {
|
|
393
|
-
if (preferMarkers.some((m) => parts.includes(m))) return parts;
|
|
394
|
-
if (!firstNonEmpty) firstNonEmpty = parts;
|
|
395
|
-
}
|
|
396
|
-
} catch { /* ignore */ }
|
|
397
|
-
} catch { /* ignore */ }
|
|
398
|
-
}
|
|
399
|
-
return firstNonEmpty || '';
|
|
400
|
-
} catch { return '' }
|
|
401
|
-
})()`, (value)=>'string' == typeof value && value.trim().length > 0);
|
|
402
|
-
} catch {}
|
|
403
|
-
if (shadowContent) try {
|
|
404
|
-
const sc = 'string' == typeof shadowContent ? shadowContent : String(shadowContent || '');
|
|
405
|
-
return mergeShadowIntoDocument(mainHTML, sc);
|
|
406
|
-
} catch {}
|
|
407
|
-
return mainHTML;
|
|
408
|
-
}
|
|
409
|
-
async function waitForLoadEvent(cdp, sessionId) {
|
|
410
|
-
return new Promise((resolve)=>{
|
|
411
|
-
let resolved = false;
|
|
412
|
-
const listener = (data)=>{
|
|
413
|
-
try {
|
|
414
|
-
const message = JSON.parse(data);
|
|
415
|
-
if ('Page.loadEventFired' === message.method && message.sessionId === sessionId && !resolved) {
|
|
416
|
-
resolved = true;
|
|
417
|
-
resolve();
|
|
418
|
-
}
|
|
419
|
-
} catch {}
|
|
420
|
-
};
|
|
421
|
-
const clientWithHandle = cdp;
|
|
422
|
-
const original = clientWithHandle.handleMessage.bind(cdp);
|
|
423
|
-
clientWithHandle.handleMessage = (data)=>{
|
|
424
|
-
original(data);
|
|
425
|
-
listener(data);
|
|
426
|
-
};
|
|
427
|
-
setTimeout(()=>{
|
|
428
|
-
if (!resolved) {
|
|
429
|
-
resolved = true;
|
|
430
|
-
console.log(messages.Qiq());
|
|
431
|
-
resolve();
|
|
432
|
-
}
|
|
433
|
-
clientWithHandle.handleMessage = original;
|
|
434
|
-
}, 2000);
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
async function waitForContentScriptInjection(cdp, sessionId) {
|
|
438
|
-
const deadline = Date.now() + 30000;
|
|
439
|
-
const started = Date.now();
|
|
440
|
-
while(Date.now() < deadline){
|
|
441
|
-
try {
|
|
442
|
-
const injected = await evaluateWithContentContext(cdp, sessionId, `(() => { try {
|
|
443
|
-
const hosts = Array.from(document.querySelectorAll(${JSON.stringify(CONTENT_ROOT_SELECTOR)}));
|
|
444
|
-
if (!hosts.length) return false;
|
|
445
|
-
const markers = ['iskilar_box','content_script','content_title','js-probe'];
|
|
446
|
-
for (const h of hosts) {
|
|
447
|
-
try {
|
|
448
|
-
const sr = h && h.shadowRoot;
|
|
449
|
-
if (!sr) continue;
|
|
450
|
-
const html = String(sr.innerHTML||'');
|
|
451
|
-
if (html.length > 0) return true;
|
|
452
|
-
if (markers.some((m) => html.includes(m))) return true;
|
|
453
|
-
try {
|
|
454
|
-
const parts = Array.from(sr.children).map((n) => (n && n.outerHTML) ? String(n.outerHTML) : '').join('');
|
|
455
|
-
if (parts && parts.length) return true;
|
|
456
|
-
if (markers.some((m) => parts.includes(m))) return true;
|
|
457
|
-
} catch { /* ignore */ }
|
|
458
|
-
} catch { /* ignore */ }
|
|
459
|
-
}
|
|
460
|
-
return false;
|
|
461
|
-
} catch { return false } })()`, (value)=>Boolean(value));
|
|
462
|
-
if (Boolean(injected)) return true;
|
|
463
|
-
} catch {}
|
|
464
|
-
const elapsed = Date.now() - started;
|
|
465
|
-
const delay = elapsed < 2000 ? 150 : 500;
|
|
466
|
-
await new Promise((r)=>setTimeout(r, delay));
|
|
467
|
-
}
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
470
58
|
function establishBrowserConnection(url, isDev, onMessage, onRejectPending) {
|
|
471
59
|
return new Promise((resolve, reject)=>{
|
|
472
60
|
const ws = new (external_ws_default())(url);
|
|
473
61
|
ws.on('open', ()=>{
|
|
474
|
-
if (isDev) console.log(messages.
|
|
62
|
+
if (isDev) console.log(messages.F1());
|
|
475
63
|
resolve(ws);
|
|
476
64
|
});
|
|
477
65
|
ws.on('message', (data)=>{
|
|
478
66
|
onMessage(data.toString());
|
|
479
67
|
});
|
|
480
68
|
ws.on('error', (error)=>{
|
|
481
|
-
if (isDev) console.error(messages.
|
|
69
|
+
if (isDev) console.error(messages.fR(error.message));
|
|
482
70
|
onRejectPending(error.message);
|
|
483
71
|
reject(error);
|
|
484
72
|
});
|
|
485
73
|
ws.on('close', ()=>{
|
|
486
|
-
if (isDev) console.log(messages.
|
|
74
|
+
if (isDev) console.log(messages.hE());
|
|
487
75
|
onRejectPending('CDP connection closed');
|
|
488
76
|
reject(new Error('CDP WebSocket closed before the connection opened'));
|
|
489
77
|
});
|
|
@@ -528,7 +116,7 @@ exports.modules = {
|
|
|
528
116
|
} catch (error) {
|
|
529
117
|
if (this.isDev()) {
|
|
530
118
|
const err = error;
|
|
531
|
-
console.warn(messages.
|
|
119
|
+
console.warn(messages.r0(String(err.message || err)));
|
|
532
120
|
}
|
|
533
121
|
}
|
|
534
122
|
if (timeout) clearTimeout(timeout);
|
|
@@ -538,7 +126,7 @@ exports.modules = {
|
|
|
538
126
|
});
|
|
539
127
|
this.transport = 'websocket';
|
|
540
128
|
this.startHeartbeat();
|
|
541
|
-
if (this.isDev()) console.log(messages.
|
|
129
|
+
if (this.isDev()) console.log(messages.M3(this.host, this.port));
|
|
542
130
|
resolve();
|
|
543
131
|
} catch (error) {
|
|
544
132
|
const err = error;
|
|
@@ -573,7 +161,7 @@ exports.modules = {
|
|
|
573
161
|
this.pipeIn = null;
|
|
574
162
|
});
|
|
575
163
|
this.startHeartbeat();
|
|
576
|
-
if (this.isDev()) console.log(messages.
|
|
164
|
+
if (this.isDev()) console.log(messages.M3(this.host, this.port));
|
|
577
165
|
}
|
|
578
166
|
rejectAllPending(reason) {
|
|
579
167
|
this.pendingRequests.forEach(({ reject, timeout }, id)=>{
|
|
@@ -645,13 +233,13 @@ exports.modules = {
|
|
|
645
233
|
}
|
|
646
234
|
if ('Target.attachedToTarget' === message.method) {
|
|
647
235
|
const params = message.params || {};
|
|
648
|
-
if (this.isDev()) console.log(messages.
|
|
236
|
+
if (this.isDev()) console.log(messages.p8(String(params.sessionId || ''), String(params.targetInfo?.type || '')));
|
|
649
237
|
}
|
|
650
238
|
for (const eventCallback of this.eventCallbacks)eventCallback(message);
|
|
651
239
|
} catch (error) {
|
|
652
240
|
if (this.isDev()) {
|
|
653
241
|
const err = error;
|
|
654
|
-
console.warn(messages.
|
|
242
|
+
console.warn(messages.xx(String(err.message || err)));
|
|
655
243
|
}
|
|
656
244
|
}
|
|
657
245
|
}
|
|
@@ -715,40 +303,6 @@ exports.modules = {
|
|
|
715
303
|
await this.sendCommand('Log.enable', {}, sessionId);
|
|
716
304
|
if (sessionId) await this.sendCommand('Runtime.enable', {}, sessionId);
|
|
717
305
|
}
|
|
718
|
-
async navigate(sessionId, url) {
|
|
719
|
-
await this.sendCommand('Page.navigate', {
|
|
720
|
-
url
|
|
721
|
-
}, sessionId);
|
|
722
|
-
}
|
|
723
|
-
async createTarget(url) {
|
|
724
|
-
const res = await this.sendCommand('Target.createTarget', {
|
|
725
|
-
url
|
|
726
|
-
});
|
|
727
|
-
return String(res?.targetId || '');
|
|
728
|
-
}
|
|
729
|
-
async activateTarget(targetId) {
|
|
730
|
-
await this.sendCommand('Target.activateTarget', {
|
|
731
|
-
targetId
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
async waitForLoadEvent(sessionId) {
|
|
735
|
-
return waitForLoadEvent(this, sessionId);
|
|
736
|
-
}
|
|
737
|
-
async waitForContentScriptInjection(sessionId) {
|
|
738
|
-
return waitForContentScriptInjection(this, sessionId);
|
|
739
|
-
}
|
|
740
|
-
async getExtensionRootMeta(sessionId) {
|
|
741
|
-
return evaluateExtensionRootMeta(this, sessionId);
|
|
742
|
-
}
|
|
743
|
-
async getShadowStyleSnapshot(sessionId) {
|
|
744
|
-
return evaluateShadowStyleSnapshot(this, sessionId);
|
|
745
|
-
}
|
|
746
|
-
async pollForVisibleShadowHostContent(sessionId, deadlineMs) {
|
|
747
|
-
return pollForVisibleShadowHostContent(this, sessionId, deadlineMs);
|
|
748
|
-
}
|
|
749
|
-
async hasVisibleShadowHostContent(sessionId) {
|
|
750
|
-
return hasVisibleShadowHostContent(this, sessionId);
|
|
751
|
-
}
|
|
752
306
|
async evaluate(sessionId, expression, options) {
|
|
753
307
|
const response = await this.sendCommand('Runtime.evaluate', {
|
|
754
308
|
expression,
|
|
@@ -757,150 +311,11 @@ exports.modules = {
|
|
|
757
311
|
}, sessionId);
|
|
758
312
|
return response.result?.value;
|
|
759
313
|
}
|
|
760
|
-
async evaluateInContext(sessionId, expression, contextId, options) {
|
|
761
|
-
const response = await this.sendCommand('Runtime.evaluate', {
|
|
762
|
-
expression,
|
|
763
|
-
contextId,
|
|
764
|
-
returnByValue: true,
|
|
765
|
-
awaitPromise: options?.awaitPromise === true
|
|
766
|
-
}, sessionId);
|
|
767
|
-
return response.result?.value;
|
|
768
|
-
}
|
|
769
|
-
async getPageHTML(sessionId, includeShadow = 'open-only') {
|
|
770
|
-
return getPageHTML(this, sessionId, includeShadow);
|
|
771
|
-
}
|
|
772
|
-
async getClosedShadowRoots(sessionId, maxBytes = 65536) {
|
|
773
|
-
await this.sendCommand('DOM.enable', {}, sessionId);
|
|
774
|
-
const doc = await this.sendCommand('DOM.getDocument', {
|
|
775
|
-
depth: -1,
|
|
776
|
-
pierce: true
|
|
777
|
-
}, sessionId);
|
|
778
|
-
const found = [];
|
|
779
|
-
const walk = (node, hostName)=>{
|
|
780
|
-
if (!node || 'object' != typeof node) return;
|
|
781
|
-
const name = node.localName || node.nodeName || hostName;
|
|
782
|
-
if (Array.isArray(node.shadowRoots)) for (const sr of node.shadowRoots){
|
|
783
|
-
if (sr && 'closed' === sr.shadowRootType && 'number' == typeof sr.nodeId) found.push({
|
|
784
|
-
nodeId: sr.nodeId,
|
|
785
|
-
host: String(name)
|
|
786
|
-
});
|
|
787
|
-
walk(sr, name);
|
|
788
|
-
}
|
|
789
|
-
if (Array.isArray(node.children)) for (const c of node.children)walk(c, name);
|
|
790
|
-
if (node.contentDocument) walk(node.contentDocument, name);
|
|
791
|
-
};
|
|
792
|
-
walk(doc.root, 'html');
|
|
793
|
-
const out = [];
|
|
794
|
-
for (const f of found)try {
|
|
795
|
-
const oh = await this.sendCommand('DOM.getOuterHTML', {
|
|
796
|
-
nodeId: f.nodeId
|
|
797
|
-
}, sessionId);
|
|
798
|
-
let html = String(oh?.outerHTML ?? '');
|
|
799
|
-
let truncated = false;
|
|
800
|
-
if (maxBytes > 0 && html.length > maxBytes) {
|
|
801
|
-
html = html.slice(0, maxBytes);
|
|
802
|
-
truncated = true;
|
|
803
|
-
}
|
|
804
|
-
out.push({
|
|
805
|
-
host: f.host,
|
|
806
|
-
type: 'closed',
|
|
807
|
-
html,
|
|
808
|
-
...truncated ? {
|
|
809
|
-
truncated
|
|
810
|
-
} : {}
|
|
811
|
-
});
|
|
812
|
-
} catch {
|
|
813
|
-
out.push({
|
|
814
|
-
host: f.host,
|
|
815
|
-
type: 'closed',
|
|
816
|
-
html: ''
|
|
817
|
-
});
|
|
818
|
-
}
|
|
819
|
-
return out;
|
|
820
|
-
}
|
|
821
|
-
async closeTarget(targetId) {
|
|
822
|
-
await this.sendCommand('Target.closeTarget', {
|
|
823
|
-
targetId
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
async forceReloadExtension(extensionId) {
|
|
827
|
-
const attempts = 8;
|
|
828
|
-
let lastError = null;
|
|
829
|
-
for(let i = 0; i < attempts; i++){
|
|
830
|
-
try {
|
|
831
|
-
const ok = await this.reloadExtensionViaTargetEval(extensionId);
|
|
832
|
-
if (ok) return true;
|
|
833
|
-
} catch (error) {
|
|
834
|
-
lastError = error;
|
|
835
|
-
}
|
|
836
|
-
const backoffMs = Math.min(1200, 150 * (i + 1));
|
|
837
|
-
await new Promise((r)=>setTimeout(r, backoffMs));
|
|
838
|
-
}
|
|
839
|
-
console.warn(messages.ccn(extensionId, lastError?.message || String(lastError || 'runtime.reload failed')));
|
|
840
|
-
return false;
|
|
841
|
-
}
|
|
842
314
|
async getExtensionInfo(extensionId) {
|
|
843
315
|
try {
|
|
844
316
|
return await getExtensionInfo(this, extensionId);
|
|
845
317
|
} catch (error) {
|
|
846
|
-
throw new Error(messages.
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
async reloadExtensionViaTargetEval(extensionId) {
|
|
850
|
-
try {
|
|
851
|
-
const targets = await this.getTargets();
|
|
852
|
-
const preferredOrder = [
|
|
853
|
-
'service_worker',
|
|
854
|
-
'background_page',
|
|
855
|
-
'worker',
|
|
856
|
-
'page'
|
|
857
|
-
];
|
|
858
|
-
for (const type of preferredOrder){
|
|
859
|
-
const matchingTargets = (targets || []).filter((t)=>{
|
|
860
|
-
const url = String(t?.url || '');
|
|
861
|
-
const tt = String(t?.type || '');
|
|
862
|
-
const inExtensionScope = url.startsWith(`chrome-extension://${extensionId}/`);
|
|
863
|
-
return tt === type && inExtensionScope;
|
|
864
|
-
});
|
|
865
|
-
for (const target of matchingTargets){
|
|
866
|
-
const targetId = target?.targetId;
|
|
867
|
-
if (!targetId) continue;
|
|
868
|
-
let sessionId;
|
|
869
|
-
try {
|
|
870
|
-
sessionId = await this.attachToTarget(targetId);
|
|
871
|
-
} catch {
|
|
872
|
-
continue;
|
|
873
|
-
}
|
|
874
|
-
try {
|
|
875
|
-
await this.sendCommand('Runtime.enable', {}, sessionId);
|
|
876
|
-
} catch {
|
|
877
|
-
return true;
|
|
878
|
-
}
|
|
879
|
-
this.sendCommand('Runtime.evaluate', {
|
|
880
|
-
expression: '(function(){ try { if (!chrome || !chrome.runtime || !chrome.runtime.reload) return false; chrome.runtime.reload(); return true; } catch (error) { return false; } })()',
|
|
881
|
-
returnByValue: true
|
|
882
|
-
}, sessionId).catch(()=>{});
|
|
883
|
-
return true;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
return false;
|
|
887
|
-
} catch {
|
|
888
|
-
return false;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
async loadUnpackedExtension(path) {
|
|
892
|
-
try {
|
|
893
|
-
return await loadUnpackedExtension(this, path);
|
|
894
|
-
} catch (error) {
|
|
895
|
-
throw new Error(messages.xlM(path, error.message));
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
async unloadExtension(extensionId) {
|
|
899
|
-
try {
|
|
900
|
-
return await unloadExtension(this, extensionId);
|
|
901
|
-
} catch (error) {
|
|
902
|
-
console.error(messages.yEr(extensionId, error.message));
|
|
903
|
-
return false;
|
|
318
|
+
throw new Error(messages.Z5(extensionId, error.message));
|
|
904
319
|
}
|
|
905
320
|
}
|
|
906
321
|
constructor(port = 9222, host = '127.0.0.1'){
|
|
@@ -1136,7 +551,7 @@ exports.modules = {
|
|
|
1136
551
|
}
|
|
1137
552
|
return deriveFromProfile() || deferredFirstEvalId || deferredUrlDerivedId;
|
|
1138
553
|
}
|
|
1139
|
-
var ensure = __webpack_require__("./browsers/run-chromium/
|
|
554
|
+
var ensure = __webpack_require__("./browsers/run-chromium/cdp/cdp-extension-controller/ensure.ts");
|
|
1140
555
|
function registerAutoEnableLogging(cdp, getExtensionId) {
|
|
1141
556
|
cdp.onProtocolEvent((message)=>{
|
|
1142
557
|
try {
|
|
@@ -1156,11 +571,11 @@ exports.modules = {
|
|
|
1156
571
|
} else if ('Runtime.consoleAPICalled' === message.method || 'Log.entryAdded' === message.method) {
|
|
1157
572
|
if ('1' === String(process.env.EXTENSION_VERBOSE || '').trim()) {
|
|
1158
573
|
const ts = new Date().toISOString();
|
|
1159
|
-
console.log(messages.
|
|
574
|
+
console.log(messages.bv(ts, message.params));
|
|
1160
575
|
}
|
|
1161
576
|
}
|
|
1162
577
|
} catch (error) {
|
|
1163
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(messages.
|
|
578
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(messages.KK(String(error?.message || error)));
|
|
1164
579
|
}
|
|
1165
580
|
});
|
|
1166
581
|
}
|
|
@@ -1232,7 +647,7 @@ exports.modules = {
|
|
|
1232
647
|
const exists = external_fs_.existsSync(this.outPath);
|
|
1233
648
|
if (!exists) throw new Error(`Output path not found: ${this.outPath}`);
|
|
1234
649
|
if (!this.extensionId) try {
|
|
1235
|
-
const { loadUnpackedIfNeeded } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "./browsers/run-chromium/
|
|
650
|
+
const { loadUnpackedIfNeeded } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "./browsers/run-chromium/cdp/cdp-extension-controller/ensure.ts"));
|
|
1236
651
|
const cdpId = await loadUnpackedIfNeeded(this.cdp, this.outPath);
|
|
1237
652
|
if (cdpId) this.extensionId = cdpId;
|
|
1238
653
|
} catch {}
|
|
@@ -1312,32 +727,6 @@ exports.modules = {
|
|
|
1312
727
|
classifyOwnership(extensionId) {
|
|
1313
728
|
return classifyExtensionOwnership(this.profilePath, this.outPath, extensionId);
|
|
1314
729
|
}
|
|
1315
|
-
getDeveloperModeStatus() {
|
|
1316
|
-
if (!this.profilePath) return 'unknown';
|
|
1317
|
-
const prefCandidates = [];
|
|
1318
|
-
const seen = new Set();
|
|
1319
|
-
const addPrefCandidate = (dir)=>{
|
|
1320
|
-
const prefPath = external_path_.join(dir, 'Preferences');
|
|
1321
|
-
if (!external_fs_.existsSync(prefPath)) return;
|
|
1322
|
-
const dedupeKey = external_path_.resolve(prefPath);
|
|
1323
|
-
if (seen.has(dedupeKey)) return;
|
|
1324
|
-
seen.add(dedupeKey);
|
|
1325
|
-
prefCandidates.push(prefPath);
|
|
1326
|
-
};
|
|
1327
|
-
try {
|
|
1328
|
-
addPrefCandidate(this.profilePath);
|
|
1329
|
-
addPrefCandidate(external_path_.join(this.profilePath, 'Default'));
|
|
1330
|
-
for (const entry of external_fs_.readdirSync(this.profilePath))if (/^Profile\s+\d+$/i.test(entry)) addPrefCandidate(external_path_.join(this.profilePath, entry));
|
|
1331
|
-
} catch {}
|
|
1332
|
-
for (const prefPath of prefCandidates)try {
|
|
1333
|
-
const prefs = JSON.parse(external_fs_.readFileSync(prefPath, 'utf-8'));
|
|
1334
|
-
const uiFlag = prefs?.extensions?.ui?.developer_mode;
|
|
1335
|
-
if ('boolean' == typeof uiFlag) return uiFlag ? 'enabled' : 'disabled';
|
|
1336
|
-
const legacyFlag = prefs?.extensions?.developer_mode;
|
|
1337
|
-
if ('boolean' == typeof legacyFlag) return legacyFlag ? 'enabled' : 'disabled';
|
|
1338
|
-
} catch {}
|
|
1339
|
-
return 'unknown';
|
|
1340
|
-
}
|
|
1341
730
|
async connectFreshClient() {
|
|
1342
731
|
if (this.pipeIn && this.pipeOut && !this.pipeIn.destroyed) this.cdp = await connectToChromeCdpViaPipe(this.pipeIn, this.pipeOut, this.cdpPort);
|
|
1343
732
|
else this.cdp = await connectToChromeCdp(this.cdpPort);
|
|
@@ -1352,7 +741,7 @@ exports.modules = {
|
|
|
1352
741
|
filter: EXTENSION_AUTO_ATTACH_FILTER
|
|
1353
742
|
});
|
|
1354
743
|
} catch (error) {
|
|
1355
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(messages.
|
|
744
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(messages.wX(String(error?.message || error)));
|
|
1356
745
|
}
|
|
1357
746
|
registerAutoEnableLogging(this.cdp, ()=>this.extensionId);
|
|
1358
747
|
}
|
|
@@ -1362,9 +751,6 @@ exports.modules = {
|
|
|
1362
751
|
cb(message);
|
|
1363
752
|
});
|
|
1364
753
|
}
|
|
1365
|
-
clearProtocolEventHandler() {
|
|
1366
|
-
if (!this.cdp) return;
|
|
1367
|
-
}
|
|
1368
754
|
async enableUnifiedLogging() {
|
|
1369
755
|
if (!this.cdp) return;
|
|
1370
756
|
try {
|
|
@@ -1408,7 +794,7 @@ exports.modules = {
|
|
|
1408
794
|
} else if ('Runtime.consoleAPICalled' === message.method || 'Log.entryAdded' === message.method) {
|
|
1409
795
|
if ('1' === String(process.env.EXTENSION_VERBOSE || '').trim()) {
|
|
1410
796
|
const ts = new Date().toISOString();
|
|
1411
|
-
console.log(messages.
|
|
797
|
+
console.log(messages.bv(ts, message.params));
|
|
1412
798
|
}
|
|
1413
799
|
}
|
|
1414
800
|
} catch {}
|
|
@@ -1482,8 +868,8 @@ exports.modules = {
|
|
|
1482
868
|
const userDataDirFlag = chromiumArgs.find((flag)=>flag.startsWith('--user-data-dir='));
|
|
1483
869
|
const userDataDir = userDataDirFlag ? userDataDirFlag.replace('--user-data-dir=', '').replace(/^"|"$/g, '') : '';
|
|
1484
870
|
if ('true' === process.env.EXTENSION_AUTHOR_MODE) {
|
|
1485
|
-
if (userDataDir) console.log(messages.
|
|
1486
|
-
console.log(messages.
|
|
871
|
+
if (userDataDir) console.log(messages.aI(userDataDir));
|
|
872
|
+
console.log(messages.CY(chromeRemoteDebugPort, chromeRemoteDebugPort));
|
|
1487
873
|
}
|
|
1488
874
|
const cdpExtensionController = new CDPExtensionController({
|
|
1489
875
|
outPath: extensionOutputPath,
|
|
@@ -1495,7 +881,7 @@ exports.modules = {
|
|
|
1495
881
|
pipeOut: pipeStreams?.output
|
|
1496
882
|
});
|
|
1497
883
|
await cdpExtensionController.connect();
|
|
1498
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(messages.
|
|
884
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(messages.M3('127.0.0.1', chromeRemoteDebugPort));
|
|
1499
885
|
try {
|
|
1500
886
|
if (extensionOutputPath && Number.isFinite(chromeRemoteDebugPort)) {
|
|
1501
887
|
const readyPath = external_path_.join(external_path_.dirname(extensionOutputPath), 'extension-js', external_path_.basename(extensionOutputPath), 'ready.json');
|
|
@@ -1584,7 +970,7 @@ exports.modules = {
|
|
|
1584
970
|
});
|
|
1585
971
|
}
|
|
1586
972
|
} catch (bannerErr) {
|
|
1587
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(messages.$
|
|
973
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(messages.$w(String(bannerErr)));
|
|
1588
974
|
try {
|
|
1589
975
|
const mode = compilation?.options?.mode || 'development';
|
|
1590
976
|
if ('production' === mode) await (0, banner.MK)({
|
|
@@ -1596,39 +982,5 @@ exports.modules = {
|
|
|
1596
982
|
}
|
|
1597
983
|
plugin.cdpController = cdpExtensionController;
|
|
1598
984
|
}
|
|
1599
|
-
},
|
|
1600
|
-
"./browsers/run-chromium/chromium-source-inspection/cdp-extension-controller/ensure.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
1601
|
-
var fs__rspack_import_0 = __webpack_require__("fs");
|
|
1602
|
-
var path__rspack_import_1 = __webpack_require__("path");
|
|
1603
|
-
async function loadUnpackedIfNeeded(cdp, outPath) {
|
|
1604
|
-
try {
|
|
1605
|
-
const response = await cdp.sendCommand('Extensions.loadUnpacked', {
|
|
1606
|
-
extensionPath: outPath,
|
|
1607
|
-
options: {
|
|
1608
|
-
failOnError: false
|
|
1609
|
-
}
|
|
1610
|
-
});
|
|
1611
|
-
const id = String(response?.extensionId || '');
|
|
1612
|
-
return id || null;
|
|
1613
|
-
} catch {
|
|
1614
|
-
return null;
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
function readManifestInfo(outPath) {
|
|
1618
|
-
try {
|
|
1619
|
-
const manifestPath = path__rspack_import_1.join(outPath, 'manifest.json');
|
|
1620
|
-
const manifest = JSON.parse(fs__rspack_import_0.readFileSync(manifestPath, 'utf-8'));
|
|
1621
|
-
return {
|
|
1622
|
-
name: manifest?.name,
|
|
1623
|
-
version: manifest?.version
|
|
1624
|
-
};
|
|
1625
|
-
} catch {
|
|
1626
|
-
return null;
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
1630
|
-
M: ()=>readManifestInfo,
|
|
1631
|
-
loadUnpackedIfNeeded: ()=>loadUnpackedIfNeeded
|
|
1632
|
-
});
|
|
1633
985
|
}
|
|
1634
986
|
};
|