extension-develop 3.12.0 → 3.12.1
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 +1 -1
- package/dist/{890.cjs → 264.cjs} +182 -4773
- package/dist/324.cjs +21 -3
- package/dist/extension-js-devtools/chrome/background/service_worker.js +1 -1
- package/dist/extension-js-devtools/chromium/background/service_worker.js +1 -1
- package/dist/extension-js-devtools/edge/background/service_worker.js +1 -1
- package/dist/extension-js-devtools/firefox/background/scripts.js +1 -1
- package/dist/module.cjs +349 -5644
- package/dist/preview.cjs +1461 -0
- package/package.json +10 -12
- package/dist/215.cjs +0 -849
- package/dist/323.cjs +0 -1100
- package/webpack/webpack-lib/build-dependencies.json +0 -24
package/dist/215.cjs
DELETED
|
@@ -1,849 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.ids = [
|
|
3
|
-
"215"
|
|
4
|
-
];
|
|
5
|
-
exports.modules = {
|
|
6
|
-
"./webpack/plugin-browsers/run-chromium/chromium-source-inspection/cdp-client.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
7
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
8
|
-
n: ()=>CDPClient
|
|
9
|
-
});
|
|
10
|
-
var external_ws_ = __webpack_require__("ws");
|
|
11
|
-
var external_ws_default = /*#__PURE__*/ __webpack_require__.n(external_ws_);
|
|
12
|
-
var messages = __webpack_require__("./webpack/plugin-browsers/browsers-lib/messages.ts");
|
|
13
|
-
var discovery = __webpack_require__("./webpack/plugin-browsers/run-chromium/chromium-source-inspection/discovery.ts");
|
|
14
|
-
async function getExtensionInfo(cdp, extensionId) {
|
|
15
|
-
return await cdp.sendCommand('Extensions.getExtensionInfo', {
|
|
16
|
-
extensionId
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async function loadUnpackedExtension(cdp, absPath) {
|
|
20
|
-
const response = await cdp.sendCommand('Extensions.loadUnpacked', {
|
|
21
|
-
extensionPath: absPath,
|
|
22
|
-
options: {
|
|
23
|
-
failOnError: false
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return String(response?.extensionId || '');
|
|
27
|
-
}
|
|
28
|
-
async function unloadExtension(cdp, extensionId) {
|
|
29
|
-
try {
|
|
30
|
-
await cdp.sendCommand('Extensions.unload', {
|
|
31
|
-
extensionId
|
|
32
|
-
});
|
|
33
|
-
return true;
|
|
34
|
-
} catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function mergeShadowIntoDocument(mainHTML, shadowContent) {
|
|
39
|
-
try {
|
|
40
|
-
if (!mainHTML) return '';
|
|
41
|
-
const hasRoot = /<div id=(["'])extension-root\1/i.test(mainHTML);
|
|
42
|
-
if (hasRoot) {
|
|
43
|
-
const emptyRoot = /<div id=(["'])extension-root\1[^>]*><\/div>/i;
|
|
44
|
-
const replacedEmpty = mainHTML.replace(emptyRoot, `<div id="extension-root">${shadowContent}</div>`);
|
|
45
|
-
if (replacedEmpty !== mainHTML) return replacedEmpty;
|
|
46
|
-
return mainHTML.replace(/<div id=(["'])extension-root\1[^>]*>[\s\S]*?<\/div>/i, `<div id="extension-root">${shadowContent}</div>`);
|
|
47
|
-
}
|
|
48
|
-
const hostOpen = /(<[^>]*data-extension-root=(["'])true\2[^>]*>)/i;
|
|
49
|
-
if (hostOpen.test(mainHTML)) return mainHTML.replace(hostOpen, `$1<div id="extension-root">${shadowContent}</div>`);
|
|
50
|
-
return mainHTML;
|
|
51
|
-
} catch {
|
|
52
|
-
return mainHTML;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const CONTENT_ROOT_SELECTOR = '#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])';
|
|
56
|
-
const NON_DEVTOOLS_CONTENT_ROOT_SELECTOR = '#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])';
|
|
57
|
-
const EXTENSION_ROOT_META_EXPRESSION = `(() => {
|
|
58
|
-
const readGeneration = (node) => {
|
|
59
|
-
try {
|
|
60
|
-
const raw = node && node.getAttribute
|
|
61
|
-
? node.getAttribute('data-extjs-reinject-generation')
|
|
62
|
-
: '';
|
|
63
|
-
const parsed = Number(raw);
|
|
64
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
65
|
-
} catch (error) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const normalize = (node) => ({
|
|
70
|
-
tag: node && node.tagName ? String(node.tagName).toLowerCase() : 'unknown',
|
|
71
|
-
id: node && node.id ? String(node.id) : undefined,
|
|
72
|
-
key: node && node.getAttribute ? node.getAttribute('data-extjs-reinject-key') || undefined : undefined,
|
|
73
|
-
generation: readGeneration(node),
|
|
74
|
-
status: node && node.getAttribute ? node.getAttribute('data-extjs-reinject-status') || undefined : undefined,
|
|
75
|
-
build: node && node.getAttribute ? node.getAttribute('data-extjs-reinject-build') || undefined : undefined,
|
|
76
|
-
hasShadowRoot: !!(node && node.shadowRoot),
|
|
77
|
-
hasShadowContent: !!(node && node.shadowRoot && String(node.shadowRoot.innerHTML || '').trim())
|
|
78
|
-
});
|
|
79
|
-
const registry = (typeof globalThis === 'object' && globalThis)
|
|
80
|
-
? (globalThis.__EXTENSIONJS_DEV_REINJECT__ || {})
|
|
81
|
-
: {};
|
|
82
|
-
const registries = Object.entries(registry)
|
|
83
|
-
.slice(0, 10)
|
|
84
|
-
.map(([key, entry]) => {
|
|
85
|
-
const candidate = entry && typeof entry === 'object' ? entry : {};
|
|
86
|
-
const cleanup = candidate && typeof candidate.cleanup === 'function'
|
|
87
|
-
? candidate.cleanup
|
|
88
|
-
: (typeof entry === 'function' ? entry : undefined);
|
|
89
|
-
return {
|
|
90
|
-
key,
|
|
91
|
-
generation: typeof candidate.generation === 'number'
|
|
92
|
-
? candidate.generation
|
|
93
|
-
: (cleanup && typeof cleanup.__extjsGeneration === 'number'
|
|
94
|
-
? cleanup.__extjsGeneration
|
|
95
|
-
: undefined),
|
|
96
|
-
hasCleanup: typeof cleanup === 'function',
|
|
97
|
-
build: typeof candidate.build === 'string'
|
|
98
|
-
? candidate.build
|
|
99
|
-
: (cleanup && typeof cleanup.__extjsBuild === 'string'
|
|
100
|
-
? cleanup.__extjsBuild
|
|
101
|
-
: undefined)
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
const pageCandidate = {
|
|
105
|
-
key: document.documentElement.getAttribute('data-extjs-last-reinject-key') || undefined,
|
|
106
|
-
generation: (() => {
|
|
107
|
-
const parsed = Number(document.documentElement.getAttribute('data-extjs-last-reinject-generation') || '');
|
|
108
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
109
|
-
})(),
|
|
110
|
-
status: document.documentElement.getAttribute('data-extjs-last-reinject-status') || undefined,
|
|
111
|
-
build: document.documentElement.getAttribute('data-extjs-last-reinject-build') || undefined
|
|
112
|
-
};
|
|
113
|
-
const roots = Array.from(
|
|
114
|
-
document.querySelectorAll('#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])')
|
|
115
|
-
)
|
|
116
|
-
.slice(0, 10)
|
|
117
|
-
.map(normalize)
|
|
118
|
-
.filter((entry) =>
|
|
119
|
-
entry.hasShadowRoot ||
|
|
120
|
-
entry.hasShadowContent ||
|
|
121
|
-
typeof entry.key === 'string' ||
|
|
122
|
-
typeof entry.generation === 'number' ||
|
|
123
|
-
typeof entry.status === 'string' ||
|
|
124
|
-
typeof entry.build === 'string'
|
|
125
|
-
)
|
|
126
|
-
.map(({hasShadowRoot, hasShadowContent, ...entry}) => entry);
|
|
127
|
-
const markers = Array.from(
|
|
128
|
-
document.querySelectorAll('[data-extjs-reinject-marker="true"]')
|
|
129
|
-
)
|
|
130
|
-
.slice(0, 10)
|
|
131
|
-
.map(normalize);
|
|
132
|
-
const pageHasBackingEvidence =
|
|
133
|
-
roots.length > 0 ||
|
|
134
|
-
markers.length > 0 ||
|
|
135
|
-
registries.some((entry) =>
|
|
136
|
-
entry.key === pageCandidate.key ||
|
|
137
|
-
typeof entry.generation === 'number' ||
|
|
138
|
-
!!entry.hasCleanup ||
|
|
139
|
-
typeof entry.build === 'string'
|
|
140
|
-
);
|
|
141
|
-
const page = pageHasBackingEvidence ? pageCandidate : undefined;
|
|
142
|
-
const generations = roots
|
|
143
|
-
.concat(markers)
|
|
144
|
-
.map((entry) => entry.generation)
|
|
145
|
-
.concat(typeof page.generation === 'number' ? [page.generation] : [])
|
|
146
|
-
.concat(
|
|
147
|
-
registries
|
|
148
|
-
.map((entry) => entry.generation)
|
|
149
|
-
.filter((value) => typeof value === 'number')
|
|
150
|
-
)
|
|
151
|
-
.filter((value) => typeof value === 'number');
|
|
152
|
-
return {
|
|
153
|
-
rootCount: roots.length,
|
|
154
|
-
markerCount: markers.length,
|
|
155
|
-
latestGeneration: generations.length ? Math.max(...generations) : 0,
|
|
156
|
-
roots,
|
|
157
|
-
markers,
|
|
158
|
-
registries,
|
|
159
|
-
page
|
|
160
|
-
};
|
|
161
|
-
})()`;
|
|
162
|
-
const SHADOW_STYLE_SNAPSHOT_EXPRESSION = `(() => {
|
|
163
|
-
try {
|
|
164
|
-
const hosts = Array.from(document.querySelectorAll('#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])'));
|
|
165
|
-
if (!hosts.length) return null;
|
|
166
|
-
for (const host of hosts) {
|
|
167
|
-
const sr = host && host.shadowRoot;
|
|
168
|
-
if (!sr) continue;
|
|
169
|
-
const styles = Array.from(sr.querySelectorAll('style')).map((styleEl) => {
|
|
170
|
-
const html = String(styleEl.outerHTML || '');
|
|
171
|
-
const text = String(styleEl.textContent || '');
|
|
172
|
-
return {
|
|
173
|
-
html,
|
|
174
|
-
textLength: text.length,
|
|
175
|
-
textSnippet: text.trim().slice(0, 200)
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
return {
|
|
179
|
-
rootMode: 'shadow',
|
|
180
|
-
count: styles.length,
|
|
181
|
-
styles
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
return null;
|
|
185
|
-
} catch {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
})()`;
|
|
189
|
-
const HAS_VISIBLE_SHADOW_HOST_EXPRESSION = `(() => { try {
|
|
190
|
-
const hosts = Array.from(document.querySelectorAll('#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])'));
|
|
191
|
-
if (!hosts.length) return false;
|
|
192
|
-
for (const h of hosts) {
|
|
193
|
-
try {
|
|
194
|
-
const sr = h && h.shadowRoot;
|
|
195
|
-
if (sr && (String(sr.innerHTML||'').length > 0)) return true;
|
|
196
|
-
} catch { /* ignore */ }
|
|
197
|
-
}
|
|
198
|
-
return false;
|
|
199
|
-
} catch { return false } })()`;
|
|
200
|
-
async function collectExecutionContexts(cdp, sessionId) {
|
|
201
|
-
const rawCdp = cdp;
|
|
202
|
-
if ('function' != typeof rawCdp.sendCommand || 'function' != typeof rawCdp.onProtocolEvent) return [];
|
|
203
|
-
const contextsById = new Map();
|
|
204
|
-
const unsubscribe = rawCdp.onProtocolEvent((message)=>{
|
|
205
|
-
if (String(message.sessionId || '') !== sessionId) return;
|
|
206
|
-
if ('Runtime.executionContextCreated' !== String(message.method || '')) return;
|
|
207
|
-
const context = message.params?.context;
|
|
208
|
-
const contextId = context?.id;
|
|
209
|
-
if ('number' == typeof contextId) contextsById.set(contextId, context);
|
|
210
|
-
});
|
|
211
|
-
try {
|
|
212
|
-
await rawCdp.sendCommand('Runtime.enable', {}, sessionId, 3000);
|
|
213
|
-
await new Promise((resolve)=>setTimeout(resolve, 100));
|
|
214
|
-
} catch {
|
|
215
|
-
return [];
|
|
216
|
-
} finally{
|
|
217
|
-
unsubscribe();
|
|
218
|
-
}
|
|
219
|
-
return Array.from(contextsById.values());
|
|
220
|
-
}
|
|
221
|
-
async function getIsolatedContextId(cdp, sessionId) {
|
|
222
|
-
const contexts = await collectExecutionContexts(cdp, sessionId);
|
|
223
|
-
const preferredContext = contexts.find((context)=>{
|
|
224
|
-
const auxData = context?.auxData || {};
|
|
225
|
-
return 'isolated' === auxData.type && String(context?.origin || '').startsWith('chrome-extension://');
|
|
226
|
-
});
|
|
227
|
-
if ('number' == typeof preferredContext?.id) return preferredContext.id;
|
|
228
|
-
const fallbackContext = contexts.find((context)=>context?.auxData?.type === 'isolated');
|
|
229
|
-
return 'number' == typeof fallbackContext?.id ? fallbackContext.id : void 0;
|
|
230
|
-
}
|
|
231
|
-
async function evaluateWithContentContext(cdp, sessionId, expression, shouldAccept) {
|
|
232
|
-
let pageResult;
|
|
233
|
-
try {
|
|
234
|
-
pageResult = await cdp.evaluate(sessionId, expression);
|
|
235
|
-
if (shouldAccept(pageResult)) return pageResult;
|
|
236
|
-
} catch {}
|
|
237
|
-
try {
|
|
238
|
-
const isolatedContextId = await getIsolatedContextId(cdp, sessionId);
|
|
239
|
-
if ('number' == typeof isolatedContextId) {
|
|
240
|
-
const isolatedResult = await cdp.evaluateInContext(sessionId, expression, isolatedContextId);
|
|
241
|
-
if (shouldAccept(isolatedResult)) return isolatedResult;
|
|
242
|
-
if (void 0 !== pageResult) return pageResult;
|
|
243
|
-
return isolatedResult;
|
|
244
|
-
}
|
|
245
|
-
} catch {}
|
|
246
|
-
return pageResult;
|
|
247
|
-
}
|
|
248
|
-
function isExtensionRootMetaPayload(value) {
|
|
249
|
-
if (!value || 'object' != typeof value) return false;
|
|
250
|
-
const v = value;
|
|
251
|
-
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);
|
|
252
|
-
}
|
|
253
|
-
async function evaluateExtensionRootMeta(cdp, sessionId) {
|
|
254
|
-
try {
|
|
255
|
-
const payload = await evaluateWithContentContext(cdp, sessionId, EXTENSION_ROOT_META_EXPRESSION, isExtensionRootMetaPayload);
|
|
256
|
-
return payload;
|
|
257
|
-
} catch {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
async function evaluateShadowStyleSnapshot(cdp, sessionId) {
|
|
262
|
-
try {
|
|
263
|
-
const payload = await evaluateWithContentContext(cdp, sessionId, SHADOW_STYLE_SNAPSHOT_EXPRESSION, (value)=>null === value || 'object' == typeof value && null !== value);
|
|
264
|
-
if (null == payload) return;
|
|
265
|
-
return payload;
|
|
266
|
-
} catch {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
async function pollForVisibleShadowHostContent(cdp, sessionId, deadlineMs = 4000) {
|
|
271
|
-
const deadline = Date.now() + deadlineMs;
|
|
272
|
-
const started = Date.now();
|
|
273
|
-
while(Date.now() < deadline){
|
|
274
|
-
try {
|
|
275
|
-
const hasRoot = await hasVisibleShadowHostContent(cdp, sessionId);
|
|
276
|
-
if (hasRoot) return;
|
|
277
|
-
} catch {}
|
|
278
|
-
const elapsed = Date.now() - started;
|
|
279
|
-
const delay = elapsed < 1000 ? 150 : 350;
|
|
280
|
-
await new Promise((r)=>setTimeout(r, delay));
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
async function hasVisibleShadowHostContent(cdp, sessionId) {
|
|
284
|
-
try {
|
|
285
|
-
const v = await evaluateWithContentContext(cdp, sessionId, HAS_VISIBLE_SHADOW_HOST_EXPRESSION, (value)=>true === value || false === value);
|
|
286
|
-
return true === v;
|
|
287
|
-
} catch {
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async function getPageHTML(cdp, sessionId, includeShadow = 'open-only') {
|
|
292
|
-
try {
|
|
293
|
-
await cdp.evaluate(sessionId, 'document.title');
|
|
294
|
-
} catch {}
|
|
295
|
-
const mainHTMLRaw = await cdp.evaluate(sessionId, `(() => {
|
|
296
|
-
try {
|
|
297
|
-
const serialize = () => {
|
|
298
|
-
const doctype = document.doctype
|
|
299
|
-
const dt = doctype
|
|
300
|
-
? '<!DOCTYPE '
|
|
301
|
-
+ doctype.name
|
|
302
|
-
+ (doctype.publicId ? ' PUBLIC "' + doctype.publicId + '"' : '')
|
|
303
|
-
+ (doctype.systemId ? ' "' + doctype.systemId + '"' : '')
|
|
304
|
-
+ '>'
|
|
305
|
-
: ''
|
|
306
|
-
return dt + '\n' + document.documentElement.outerHTML
|
|
307
|
-
}
|
|
308
|
-
return serialize()
|
|
309
|
-
} catch (e) {
|
|
310
|
-
return ''
|
|
311
|
-
}
|
|
312
|
-
})()`);
|
|
313
|
-
const mainHTML = 'string' == typeof mainHTMLRaw ? mainHTMLRaw : String(mainHTMLRaw || '');
|
|
314
|
-
if ('off' === includeShadow) return mainHTML;
|
|
315
|
-
const hasVisibleContentRoot = await evaluateWithContentContext(cdp, sessionId, `(() => {
|
|
316
|
-
try {
|
|
317
|
-
return !!document.querySelector(${JSON.stringify(NON_DEVTOOLS_CONTENT_ROOT_SELECTOR)})
|
|
318
|
-
} catch {
|
|
319
|
-
return false
|
|
320
|
-
}
|
|
321
|
-
})()`, (value)=>'boolean' == typeof value);
|
|
322
|
-
if (!hasVisibleContentRoot) return mainHTML;
|
|
323
|
-
try {
|
|
324
|
-
const mergedHtmlRaw = await evaluateWithContentContext(cdp, sessionId, `(() => { try {
|
|
325
|
-
var cloned = document.documentElement.cloneNode(true);
|
|
326
|
-
var selector = ${JSON.stringify(NON_DEVTOOLS_CONTENT_ROOT_SELECTOR)};
|
|
327
|
-
var s = new XMLSerializer();
|
|
328
|
-
try {
|
|
329
|
-
var liveHosts = Array.from(document.querySelectorAll(selector));
|
|
330
|
-
if (!liveHosts.length) return '';
|
|
331
|
-
var clonedHosts = Array.from(cloned.querySelectorAll(selector));
|
|
332
|
-
if (clonedHosts.length < liveHosts.length) {
|
|
333
|
-
var cloneDoc = cloned.ownerDocument || document;
|
|
334
|
-
var cloneBody = cloned.querySelector('body') || cloned;
|
|
335
|
-
for (var missingIndex = clonedHosts.length; missingIndex < liveHosts.length; missingIndex++) {
|
|
336
|
-
var missingLiveHost = liveHosts[missingIndex];
|
|
337
|
-
if (!missingLiveHost || !missingLiveHost.tagName || !cloneBody || typeof cloneBody.appendChild !== 'function') continue;
|
|
338
|
-
var shell = cloneDoc.createElement(String(missingLiveHost.tagName || 'div').toLowerCase());
|
|
339
|
-
try {
|
|
340
|
-
Array.from(missingLiveHost.attributes || []).forEach(function(attr){
|
|
341
|
-
try { shell.setAttribute(attr.name, attr.value); } catch(_) {}
|
|
342
|
-
});
|
|
343
|
-
} catch(_) {}
|
|
344
|
-
try { cloneBody.appendChild(shell); } catch(_) {}
|
|
345
|
-
clonedHosts.push(shell);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
for (var index = 0; index < liveHosts.length; index++) {
|
|
349
|
-
var host = clonedHosts[index];
|
|
350
|
-
var liveHost = liveHosts[index];
|
|
351
|
-
if (!host || !liveHost || !liveHost.shadowRoot) continue;
|
|
352
|
-
var shadow = Array.from(liveHost.shadowRoot.childNodes).map(function(n){
|
|
353
|
-
try { return s.serializeToString(n) } catch(e){ return '' }
|
|
354
|
-
}).join('');
|
|
355
|
-
if (!shadow) continue;
|
|
356
|
-
try { host.innerHTML = shadow; } catch(e) {}
|
|
357
|
-
}
|
|
358
|
-
} catch(e) {}
|
|
359
|
-
var doctype = document.doctype;
|
|
360
|
-
var dt = doctype ? '<!DOCTYPE ' + doctype.name + (doctype.publicId ? ' PUBLIC \"' + doctype.publicId + '\"' : '') + (doctype.systemId ? ' \"' + doctype.systemId + '\"' : '') + '>' : '';
|
|
361
|
-
return String(dt + '\\n' + (cloned.outerHTML || document.documentElement.outerHTML));
|
|
362
|
-
} catch(e) { try { return String(document.documentElement.outerHTML); } catch(_) { return '' } } })()`, (value)=>'string' == typeof value && /<html[\s>]/i.test(value));
|
|
363
|
-
const mergedHtml = 'string' == typeof mergedHtmlRaw ? mergedHtmlRaw : String(mergedHtmlRaw || '');
|
|
364
|
-
if (mergedHtml && /<html[\s>]/i.test(mergedHtml)) return mergedHtml;
|
|
365
|
-
} catch {}
|
|
366
|
-
let shadowContent = '';
|
|
367
|
-
try {
|
|
368
|
-
shadowContent = await evaluateWithContentContext(cdp, sessionId, `(() => {
|
|
369
|
-
try {
|
|
370
|
-
const hosts = Array.from(document.querySelectorAll(${JSON.stringify(CONTENT_ROOT_SELECTOR)}));
|
|
371
|
-
if (!hosts.length) return '';
|
|
372
|
-
const preferMarkers = ['iskilar_box','content_script','content_title','js-probe'];
|
|
373
|
-
let firstNonEmpty = '';
|
|
374
|
-
for (const host of hosts) {
|
|
375
|
-
try {
|
|
376
|
-
const sr = host && host.shadowRoot;
|
|
377
|
-
if (!sr) continue;
|
|
378
|
-
const html = String(sr.innerHTML || '');
|
|
379
|
-
if (html && html.length) {
|
|
380
|
-
if (preferMarkers.some((m) => html.includes(m))) return html;
|
|
381
|
-
if (!firstNonEmpty) firstNonEmpty = html;
|
|
382
|
-
continue;
|
|
383
|
-
}
|
|
384
|
-
try {
|
|
385
|
-
const parts = Array.from(sr.children)
|
|
386
|
-
.map((n) => (n && n.outerHTML) ? String(n.outerHTML) : '')
|
|
387
|
-
.join('');
|
|
388
|
-
if (parts && parts.length) {
|
|
389
|
-
if (preferMarkers.some((m) => parts.includes(m))) return parts;
|
|
390
|
-
if (!firstNonEmpty) firstNonEmpty = parts;
|
|
391
|
-
}
|
|
392
|
-
} catch { /* ignore */ }
|
|
393
|
-
} catch { /* ignore */ }
|
|
394
|
-
}
|
|
395
|
-
return firstNonEmpty || '';
|
|
396
|
-
} catch { return '' }
|
|
397
|
-
})()`, (value)=>'string' == typeof value && value.trim().length > 0);
|
|
398
|
-
} catch {}
|
|
399
|
-
if (shadowContent) try {
|
|
400
|
-
const sc = 'string' == typeof shadowContent ? shadowContent : String(shadowContent || '');
|
|
401
|
-
return mergeShadowIntoDocument(mainHTML, sc);
|
|
402
|
-
} catch {}
|
|
403
|
-
return mainHTML;
|
|
404
|
-
}
|
|
405
|
-
async function waitForLoadEvent(cdp, sessionId) {
|
|
406
|
-
return new Promise((resolve)=>{
|
|
407
|
-
let resolved = false;
|
|
408
|
-
const listener = (data)=>{
|
|
409
|
-
try {
|
|
410
|
-
const message = JSON.parse(data);
|
|
411
|
-
if ('Page.loadEventFired' === message.method && message.sessionId === sessionId && !resolved) {
|
|
412
|
-
resolved = true;
|
|
413
|
-
resolve();
|
|
414
|
-
}
|
|
415
|
-
} catch {}
|
|
416
|
-
};
|
|
417
|
-
const clientWithHandle = cdp;
|
|
418
|
-
const original = clientWithHandle.handleMessage.bind(cdp);
|
|
419
|
-
clientWithHandle.handleMessage = (data)=>{
|
|
420
|
-
original(data);
|
|
421
|
-
listener(data);
|
|
422
|
-
};
|
|
423
|
-
setTimeout(()=>{
|
|
424
|
-
if (!resolved) {
|
|
425
|
-
resolved = true;
|
|
426
|
-
console.log(messages.Qiq());
|
|
427
|
-
resolve();
|
|
428
|
-
}
|
|
429
|
-
clientWithHandle.handleMessage = original;
|
|
430
|
-
}, 2000);
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
async function waitForContentScriptInjection(cdp, sessionId) {
|
|
434
|
-
const deadline = Date.now() + 30000;
|
|
435
|
-
const started = Date.now();
|
|
436
|
-
while(Date.now() < deadline){
|
|
437
|
-
try {
|
|
438
|
-
const injected = await evaluateWithContentContext(cdp, sessionId, `(() => { try {
|
|
439
|
-
const hosts = Array.from(document.querySelectorAll(${JSON.stringify(CONTENT_ROOT_SELECTOR)}));
|
|
440
|
-
if (!hosts.length) return false;
|
|
441
|
-
const markers = ['iskilar_box','content_script','content_title','js-probe'];
|
|
442
|
-
for (const h of hosts) {
|
|
443
|
-
try {
|
|
444
|
-
const sr = h && h.shadowRoot;
|
|
445
|
-
if (!sr) continue;
|
|
446
|
-
const html = String(sr.innerHTML||'');
|
|
447
|
-
if (html.length > 0) return true;
|
|
448
|
-
if (markers.some((m) => html.includes(m))) return true;
|
|
449
|
-
try {
|
|
450
|
-
const parts = Array.from(sr.children).map((n) => (n && n.outerHTML) ? String(n.outerHTML) : '').join('');
|
|
451
|
-
if (parts && parts.length) return true;
|
|
452
|
-
if (markers.some((m) => parts.includes(m))) return true;
|
|
453
|
-
} catch { /* ignore */ }
|
|
454
|
-
} catch { /* ignore */ }
|
|
455
|
-
}
|
|
456
|
-
return false;
|
|
457
|
-
} catch { return false } })()`, (value)=>Boolean(value));
|
|
458
|
-
if (Boolean(injected)) return true;
|
|
459
|
-
} catch {}
|
|
460
|
-
const elapsed = Date.now() - started;
|
|
461
|
-
const delay = elapsed < 2000 ? 150 : 500;
|
|
462
|
-
await new Promise((r)=>setTimeout(r, delay));
|
|
463
|
-
}
|
|
464
|
-
return false;
|
|
465
|
-
}
|
|
466
|
-
function establishBrowserConnection(url, isDev, onMessage, onRejectPending) {
|
|
467
|
-
return new Promise((resolve, reject)=>{
|
|
468
|
-
const ws = new (external_ws_default())(url);
|
|
469
|
-
ws.on('open', ()=>{
|
|
470
|
-
if (isDev) console.log(messages.F1E());
|
|
471
|
-
resolve(ws);
|
|
472
|
-
});
|
|
473
|
-
ws.on('message', (data)=>{
|
|
474
|
-
onMessage(data.toString());
|
|
475
|
-
});
|
|
476
|
-
ws.on('error', (error)=>{
|
|
477
|
-
if (isDev) console.error(messages.fRy(error.message));
|
|
478
|
-
onRejectPending(error.message);
|
|
479
|
-
reject(error);
|
|
480
|
-
});
|
|
481
|
-
ws.on('close', ()=>{
|
|
482
|
-
if (isDev) console.log(messages.hE8());
|
|
483
|
-
onRejectPending('CDP connection closed');
|
|
484
|
-
});
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
function _define_property(obj, key, value) {
|
|
488
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
489
|
-
value: value,
|
|
490
|
-
enumerable: true,
|
|
491
|
-
configurable: true,
|
|
492
|
-
writable: true
|
|
493
|
-
});
|
|
494
|
-
else obj[key] = value;
|
|
495
|
-
return obj;
|
|
496
|
-
}
|
|
497
|
-
class CDPClient {
|
|
498
|
-
isDev() {
|
|
499
|
-
return 'true' === process.env.EXTENSION_AUTHOR_MODE;
|
|
500
|
-
}
|
|
501
|
-
async connect() {
|
|
502
|
-
return new Promise(async (resolve, reject)=>{
|
|
503
|
-
try {
|
|
504
|
-
this.targetWebSocketUrl = await (0, discovery.N)(this.host, this.port, this.isDev());
|
|
505
|
-
this.ws = await establishBrowserConnection(this.targetWebSocketUrl, this.isDev(), (data)=>this.handleMessage(data), (reason)=>{
|
|
506
|
-
this.pendingRequests.forEach(({ reject, timeout }, id)=>{
|
|
507
|
-
try {
|
|
508
|
-
reject(new Error(reason));
|
|
509
|
-
} catch (error) {
|
|
510
|
-
if (this.isDev()) {
|
|
511
|
-
const err = error;
|
|
512
|
-
console.warn(messages.r0s(String(err.message || err)));
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
if (timeout) clearTimeout(timeout);
|
|
516
|
-
this.pendingRequests.delete(id);
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
if (this.isDev()) console.log(messages.M3V(this.host, this.port));
|
|
520
|
-
resolve();
|
|
521
|
-
} catch (error) {
|
|
522
|
-
const err = error;
|
|
523
|
-
reject(new Error(`Failed to connect to CDP: ${err.message || err}`));
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
disconnect() {
|
|
528
|
-
if (this.ws) {
|
|
529
|
-
try {
|
|
530
|
-
this.ws.close();
|
|
531
|
-
} catch {}
|
|
532
|
-
this.ws = null;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
isConnected() {
|
|
536
|
-
return !!this.ws && this.ws.readyState === external_ws_default().OPEN;
|
|
537
|
-
}
|
|
538
|
-
onProtocolEvent(handler) {
|
|
539
|
-
this.eventCallbacks.add(handler);
|
|
540
|
-
return ()=>{
|
|
541
|
-
this.eventCallbacks.delete(handler);
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
handleMessage(data) {
|
|
545
|
-
try {
|
|
546
|
-
const message = JSON.parse(data);
|
|
547
|
-
if (message.id) {
|
|
548
|
-
const pending = this.pendingRequests.get(message.id);
|
|
549
|
-
if (pending) {
|
|
550
|
-
if (pending.timeout) clearTimeout(pending.timeout);
|
|
551
|
-
this.pendingRequests.delete(message.id);
|
|
552
|
-
if (message.error) pending.reject(new Error(JSON.stringify(message.error)));
|
|
553
|
-
else pending.resolve(message.result);
|
|
554
|
-
}
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
if ('Target.attachedToTarget' === message.method) {
|
|
558
|
-
const params = message.params || {};
|
|
559
|
-
if (this.isDev()) console.log(messages.p8m(String(params.sessionId || ''), String(params.targetInfo?.type || '')));
|
|
560
|
-
}
|
|
561
|
-
for (const eventCallback of this.eventCallbacks)eventCallback(message);
|
|
562
|
-
} catch (error) {
|
|
563
|
-
if (this.isDev()) {
|
|
564
|
-
const err = error;
|
|
565
|
-
console.warn(messages.xxG(String(err.message || err)));
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
async sendCommand(method, params = {}, sessionId, timeoutMs = 12000) {
|
|
570
|
-
return new Promise((resolve, reject)=>{
|
|
571
|
-
if (!this.ws || this.ws.readyState !== external_ws_default().OPEN) return reject(new Error('WebSocket is not open'));
|
|
572
|
-
const id = ++this.messageId;
|
|
573
|
-
const message = {
|
|
574
|
-
id,
|
|
575
|
-
method,
|
|
576
|
-
params
|
|
577
|
-
};
|
|
578
|
-
if (sessionId) message.sessionId = sessionId;
|
|
579
|
-
try {
|
|
580
|
-
const timeout = setTimeout(()=>{
|
|
581
|
-
const pending = this.pendingRequests.get(id);
|
|
582
|
-
if (!pending) return;
|
|
583
|
-
this.pendingRequests.delete(id);
|
|
584
|
-
pending.reject(new Error(`CDP command timed out (${timeoutMs}ms): ${String(pending.method || method)}`));
|
|
585
|
-
}, timeoutMs);
|
|
586
|
-
this.pendingRequests.set(id, {
|
|
587
|
-
resolve,
|
|
588
|
-
reject,
|
|
589
|
-
timeout,
|
|
590
|
-
method
|
|
591
|
-
});
|
|
592
|
-
this.ws.send(JSON.stringify(message));
|
|
593
|
-
} catch (error) {
|
|
594
|
-
const pending = this.pendingRequests.get(id);
|
|
595
|
-
if (pending?.timeout) clearTimeout(pending.timeout);
|
|
596
|
-
this.pendingRequests.delete(id);
|
|
597
|
-
reject(error);
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
async getTargets() {
|
|
602
|
-
const response = await this.sendCommand('Target.getTargets');
|
|
603
|
-
return response?.targetInfos || [];
|
|
604
|
-
}
|
|
605
|
-
async getBrowserVersion() {
|
|
606
|
-
const response = await this.sendCommand('Browser.getVersion');
|
|
607
|
-
return response || {};
|
|
608
|
-
}
|
|
609
|
-
async attachToTarget(targetId) {
|
|
610
|
-
const response = await this.sendCommand('Target.attachToTarget', {
|
|
611
|
-
targetId,
|
|
612
|
-
flatten: true
|
|
613
|
-
});
|
|
614
|
-
return response.sessionId || '';
|
|
615
|
-
}
|
|
616
|
-
async enableAutoAttach() {
|
|
617
|
-
await this.sendCommand('Target.setAutoAttach', {
|
|
618
|
-
autoAttach: true,
|
|
619
|
-
waitForDebuggerOnStart: false,
|
|
620
|
-
flatten: true
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
async enableRuntimeAndLog(sessionId) {
|
|
624
|
-
await this.sendCommand('Log.enable', {}, sessionId);
|
|
625
|
-
if (sessionId) await this.sendCommand('Runtime.enable', {}, sessionId);
|
|
626
|
-
}
|
|
627
|
-
async navigate(sessionId, url) {
|
|
628
|
-
await this.sendCommand('Page.navigate', {
|
|
629
|
-
url
|
|
630
|
-
}, sessionId);
|
|
631
|
-
}
|
|
632
|
-
async createTarget(url) {
|
|
633
|
-
const res = await this.sendCommand('Target.createTarget', {
|
|
634
|
-
url
|
|
635
|
-
});
|
|
636
|
-
return String(res?.targetId || '');
|
|
637
|
-
}
|
|
638
|
-
async activateTarget(targetId) {
|
|
639
|
-
await this.sendCommand('Target.activateTarget', {
|
|
640
|
-
targetId
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
async waitForLoadEvent(sessionId) {
|
|
644
|
-
return waitForLoadEvent(this, sessionId);
|
|
645
|
-
}
|
|
646
|
-
async waitForContentScriptInjection(sessionId) {
|
|
647
|
-
return waitForContentScriptInjection(this, sessionId);
|
|
648
|
-
}
|
|
649
|
-
async getExtensionRootMeta(sessionId) {
|
|
650
|
-
return evaluateExtensionRootMeta(this, sessionId);
|
|
651
|
-
}
|
|
652
|
-
async getShadowStyleSnapshot(sessionId) {
|
|
653
|
-
return evaluateShadowStyleSnapshot(this, sessionId);
|
|
654
|
-
}
|
|
655
|
-
async pollForVisibleShadowHostContent(sessionId, deadlineMs) {
|
|
656
|
-
return pollForVisibleShadowHostContent(this, sessionId, deadlineMs);
|
|
657
|
-
}
|
|
658
|
-
async hasVisibleShadowHostContent(sessionId) {
|
|
659
|
-
return hasVisibleShadowHostContent(this, sessionId);
|
|
660
|
-
}
|
|
661
|
-
async evaluate(sessionId, expression, options) {
|
|
662
|
-
const response = await this.sendCommand('Runtime.evaluate', {
|
|
663
|
-
expression,
|
|
664
|
-
returnByValue: true,
|
|
665
|
-
awaitPromise: options?.awaitPromise === true
|
|
666
|
-
}, sessionId);
|
|
667
|
-
return response.result?.value;
|
|
668
|
-
}
|
|
669
|
-
async evaluateInContext(sessionId, expression, contextId, options) {
|
|
670
|
-
const response = await this.sendCommand('Runtime.evaluate', {
|
|
671
|
-
expression,
|
|
672
|
-
contextId,
|
|
673
|
-
returnByValue: true,
|
|
674
|
-
awaitPromise: options?.awaitPromise === true
|
|
675
|
-
}, sessionId);
|
|
676
|
-
return response.result?.value;
|
|
677
|
-
}
|
|
678
|
-
async getPageHTML(sessionId, includeShadow = 'open-only') {
|
|
679
|
-
return getPageHTML(this, sessionId, includeShadow);
|
|
680
|
-
}
|
|
681
|
-
async closeTarget(targetId) {
|
|
682
|
-
await this.sendCommand('Target.closeTarget', {
|
|
683
|
-
targetId
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
async forceReloadExtension(extensionId) {
|
|
687
|
-
const attempts = 8;
|
|
688
|
-
let lastError = null;
|
|
689
|
-
for(let i = 0; i < attempts; i++){
|
|
690
|
-
try {
|
|
691
|
-
const ok = await this.reloadExtensionViaTargetEval(extensionId);
|
|
692
|
-
if (ok) return true;
|
|
693
|
-
} catch (error) {
|
|
694
|
-
lastError = error;
|
|
695
|
-
}
|
|
696
|
-
const backoffMs = Math.min(1200, 150 * (i + 1));
|
|
697
|
-
await new Promise((r)=>setTimeout(r, backoffMs));
|
|
698
|
-
}
|
|
699
|
-
console.warn(messages.ccn(extensionId, lastError?.message || String(lastError || 'runtime.reload failed')));
|
|
700
|
-
return false;
|
|
701
|
-
}
|
|
702
|
-
async getExtensionInfo(extensionId) {
|
|
703
|
-
try {
|
|
704
|
-
return await getExtensionInfo(this, extensionId);
|
|
705
|
-
} catch (error) {
|
|
706
|
-
throw new Error(messages.Z5i(extensionId, error.message));
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
async reloadExtensionViaTargetEval(extensionId) {
|
|
710
|
-
try {
|
|
711
|
-
const targets = await this.getTargets();
|
|
712
|
-
const preferredOrder = [
|
|
713
|
-
'service_worker',
|
|
714
|
-
'background_page',
|
|
715
|
-
'worker',
|
|
716
|
-
'page'
|
|
717
|
-
];
|
|
718
|
-
for (const type of preferredOrder){
|
|
719
|
-
const matchingTargets = (targets || []).filter((t)=>{
|
|
720
|
-
const url = String(t?.url || '');
|
|
721
|
-
const tt = String(t?.type || '');
|
|
722
|
-
const inExtensionScope = url.startsWith(`chrome-extension://${extensionId}/`);
|
|
723
|
-
return tt === type && inExtensionScope;
|
|
724
|
-
});
|
|
725
|
-
for (const target of matchingTargets){
|
|
726
|
-
const targetId = target?.targetId;
|
|
727
|
-
if (targetId) try {
|
|
728
|
-
const sessionId = await this.attachToTarget(targetId);
|
|
729
|
-
await this.sendCommand('Runtime.enable', {}, sessionId);
|
|
730
|
-
await this.sendCommand('Runtime.evaluate', {
|
|
731
|
-
expression: '(function(){ try { if (!chrome || !chrome.runtime || !chrome.runtime.reload) return false; chrome.runtime.reload(); return true; } catch (error) { return false; } })()',
|
|
732
|
-
returnByValue: true
|
|
733
|
-
}, sessionId);
|
|
734
|
-
return true;
|
|
735
|
-
} catch {}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
return false;
|
|
739
|
-
} catch {
|
|
740
|
-
return false;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
async loadUnpackedExtension(path) {
|
|
744
|
-
try {
|
|
745
|
-
return await loadUnpackedExtension(this, path);
|
|
746
|
-
} catch (error) {
|
|
747
|
-
throw new Error(messages.xlM(path, error.message));
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
async unloadExtension(extensionId) {
|
|
751
|
-
try {
|
|
752
|
-
return await unloadExtension(this, extensionId);
|
|
753
|
-
} catch (error) {
|
|
754
|
-
console.error(messages.yEr(extensionId, error.message));
|
|
755
|
-
return false;
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
constructor(port = 9222, host = '127.0.0.1'){
|
|
759
|
-
_define_property(this, "port", void 0);
|
|
760
|
-
_define_property(this, "host", void 0);
|
|
761
|
-
_define_property(this, "ws", null);
|
|
762
|
-
_define_property(this, "targetWebSocketUrl", null);
|
|
763
|
-
_define_property(this, "eventCallbacks", new Set());
|
|
764
|
-
_define_property(this, "messageId", 0);
|
|
765
|
-
_define_property(this, "pendingRequests", new Map());
|
|
766
|
-
this.port = port;
|
|
767
|
-
this.host = host;
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
},
|
|
771
|
-
"./webpack/plugin-browsers/run-chromium/chromium-source-inspection/discovery.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
772
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
773
|
-
N: ()=>discoverWebSocketDebuggerUrl,
|
|
774
|
-
z: ()=>checkChromeRemoteDebugging
|
|
775
|
-
});
|
|
776
|
-
var http__rspack_import_0 = __webpack_require__("http");
|
|
777
|
-
var net__rspack_import_1 = __webpack_require__("net");
|
|
778
|
-
var _browsers_lib_messages__rspack_import_2 = __webpack_require__("./webpack/plugin-browsers/browsers-lib/messages.ts");
|
|
779
|
-
const CDP_HTTP_REQUEST_TIMEOUT_MS = 1200;
|
|
780
|
-
async function getJson(host, port, path) {
|
|
781
|
-
return new Promise((resolve, reject)=>{
|
|
782
|
-
const req = http__rspack_import_0.request({
|
|
783
|
-
hostname: host,
|
|
784
|
-
port,
|
|
785
|
-
path,
|
|
786
|
-
method: 'GET'
|
|
787
|
-
}, (res)=>{
|
|
788
|
-
let data = '';
|
|
789
|
-
res.on('data', (chunk)=>data += chunk);
|
|
790
|
-
res.on('end', ()=>{
|
|
791
|
-
try {
|
|
792
|
-
resolve(JSON.parse(data));
|
|
793
|
-
} catch (e) {
|
|
794
|
-
reject(new Error(`Failed to parse ${path}: ${e}`));
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
});
|
|
798
|
-
req.on('error', (err)=>reject(err));
|
|
799
|
-
req.setTimeout(CDP_HTTP_REQUEST_TIMEOUT_MS, ()=>{
|
|
800
|
-
req.destroy(new Error(`CDP endpoint timed out: ${path}`));
|
|
801
|
-
});
|
|
802
|
-
req.end();
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
async function discoverWebSocketDebuggerUrl(host, port, isDev) {
|
|
806
|
-
try {
|
|
807
|
-
const version = await getJson(host, port, '/json/version');
|
|
808
|
-
const wsUrl = 'string' == typeof version?.webSocketDebuggerUrl ? version.webSocketDebuggerUrl : void 0;
|
|
809
|
-
if (wsUrl) {
|
|
810
|
-
if (isDev) console.log(_browsers_lib_messages__rspack_import_2.Ter());
|
|
811
|
-
return wsUrl;
|
|
812
|
-
}
|
|
813
|
-
} catch (error) {
|
|
814
|
-
if (isDev) console.warn('[CDP] Failed to read /json/version:', String(error?.message || error));
|
|
815
|
-
}
|
|
816
|
-
const targets = await getJson(host, port, '/json');
|
|
817
|
-
if (isDev) console.log(_browsers_lib_messages__rspack_import_2.FFz((targets || []).length || 0));
|
|
818
|
-
const pageTarget = (targets || []).find((target)=>{
|
|
819
|
-
const type = String(target?.type || '');
|
|
820
|
-
const ws = 'string' == typeof target?.webSocketDebuggerUrl ? target.webSocketDebuggerUrl : '';
|
|
821
|
-
return 'page' === type && ws;
|
|
822
|
-
});
|
|
823
|
-
const pageWs = 'string' == typeof pageTarget?.webSocketDebuggerUrl ? pageTarget.webSocketDebuggerUrl : '';
|
|
824
|
-
if (pageWs) {
|
|
825
|
-
if (isDev) console.log(_browsers_lib_messages__rspack_import_2.Ter());
|
|
826
|
-
return pageWs;
|
|
827
|
-
}
|
|
828
|
-
throw new Error('No CDP WebSocket URL available');
|
|
829
|
-
}
|
|
830
|
-
async function checkChromeRemoteDebugging(port = 9222) {
|
|
831
|
-
return new Promise((resolve)=>{
|
|
832
|
-
const socket = new net__rspack_import_1.Socket();
|
|
833
|
-
socket.on('connect', ()=>{
|
|
834
|
-
socket.destroy();
|
|
835
|
-
resolve(true);
|
|
836
|
-
});
|
|
837
|
-
socket.on('error', ()=>{
|
|
838
|
-
resolve(false);
|
|
839
|
-
});
|
|
840
|
-
socket.on('timeout', ()=>{
|
|
841
|
-
socket.destroy();
|
|
842
|
-
resolve(false);
|
|
843
|
-
});
|
|
844
|
-
socket.setTimeout(2000);
|
|
845
|
-
socket.connect(port, 'localhost');
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
};
|