extension-develop 3.10.2 → 3.10.4-canary.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/dist/215.cjs +350 -69
- package/dist/323.cjs +456 -26
- package/dist/324.cjs +15 -9
- package/dist/{270.cjs → 677.cjs} +3121 -494
- package/dist/ensure-hmr-for-scripts.cjs +50 -0
- package/dist/ensure-hmr-for-scripts.js +145 -0
- package/dist/feature-scripts-content-script-wrapper.cjs +237 -0
- package/dist/feature-scripts-content-script-wrapper.js +237 -0
- package/dist/main-world-bridge.js +127 -0
- package/dist/minimum-chromium-file.js +10 -0
- package/dist/minimum-firefox-file.js +10 -0
- package/dist/minimum-script-file.js +31 -0
- package/dist/module.cjs +2072 -1755
- package/dist/package.json +3 -0
- package/dist/resolve-paths-loader.js +1350 -0
- package/package.json +5 -5
- package/dist/add-hmr-accept-code.cjs +0 -91
- package/dist/content-script-wrapper.cjs +0 -319
- package/dist/extension-js-devtools/chrome/assets/developer-mode-off.f9a94937.jpeg +0 -0
- package/dist/extension-js-devtools/chrome/assets/developer-mode-on.ede80e5b.jpeg +0 -0
- package/dist/extension-js-devtools/chrome/assets/local-network-permission.4fae40a7.png +0 -0
- package/dist/extension-js-devtools/chrome/assets/logo.7dc70d61.png +0 -0
- package/dist/extension-js-devtools/chrome/background/service_worker.js +0 -26
- package/dist/extension-js-devtools/chrome/chrome_url_overrides/newtab.html +0 -23
- package/dist/extension-js-devtools/chrome/content_scripts/content-0.js +0 -5
- package/dist/extension-js-devtools/chrome/content_scripts/styles.24e59c3d.css +0 -2
- package/dist/extension-js-devtools/chrome/devtools/index.html +0 -12
- package/dist/extension-js-devtools/chrome/devtools/index.js +0 -1
- package/dist/extension-js-devtools/chrome/icons/logo.png +0 -0
- package/dist/extension-js-devtools/chrome/manifest.json +0 -57
- package/dist/extension-js-devtools/chrome/pages/centralized-logger.css +0 -2
- package/dist/extension-js-devtools/chrome/pages/centralized-logger.html +0 -12
- package/dist/extension-js-devtools/chrome/pages/centralized-logger.js +0 -15
- package/dist/extension-js-devtools/chrome/pages/welcome.css +0 -2
- package/dist/extension-js-devtools/chrome/pages/welcome.html +0 -11
- package/dist/extension-js-devtools/chrome/pages/welcome.js +0 -25
- package/dist/extension-js-devtools/chrome/scripts/logger-client.js +0 -1
- package/dist/extension-js-devtools/chromium/assets/developer-mode-off.f9a94937.jpeg +0 -0
- package/dist/extension-js-devtools/chromium/assets/developer-mode-on.ede80e5b.jpeg +0 -0
- package/dist/extension-js-devtools/chromium/assets/local-network-permission.4fae40a7.png +0 -0
- package/dist/extension-js-devtools/chromium/assets/logo.7dc70d61.png +0 -0
- package/dist/extension-js-devtools/chromium/background/service_worker.js +0 -26
- package/dist/extension-js-devtools/chromium/chrome_url_overrides/newtab.html +0 -23
- package/dist/extension-js-devtools/chromium/content_scripts/content-0.js +0 -5
- package/dist/extension-js-devtools/chromium/content_scripts/styles.24e59c3d.css +0 -2
- package/dist/extension-js-devtools/chromium/devtools/index.html +0 -12
- package/dist/extension-js-devtools/chromium/devtools/index.js +0 -1
- package/dist/extension-js-devtools/chromium/icons/logo.png +0 -0
- package/dist/extension-js-devtools/chromium/manifest.json +0 -57
- package/dist/extension-js-devtools/chromium/pages/centralized-logger.css +0 -2
- package/dist/extension-js-devtools/chromium/pages/centralized-logger.html +0 -12
- package/dist/extension-js-devtools/chromium/pages/centralized-logger.js +0 -15
- package/dist/extension-js-devtools/chromium/pages/welcome.css +0 -2
- package/dist/extension-js-devtools/chromium/pages/welcome.html +0 -11
- package/dist/extension-js-devtools/chromium/pages/welcome.js +0 -25
- package/dist/extension-js-devtools/chromium/scripts/logger-client.js +0 -1
- package/dist/extension-js-devtools/edge/assets/developer-mode-off.f9a94937.jpeg +0 -0
- package/dist/extension-js-devtools/edge/assets/developer-mode-on.ede80e5b.jpeg +0 -0
- package/dist/extension-js-devtools/edge/assets/local-network-permission.4fae40a7.png +0 -0
- package/dist/extension-js-devtools/edge/assets/logo.7dc70d61.png +0 -0
- package/dist/extension-js-devtools/edge/background/service_worker.js +0 -26
- package/dist/extension-js-devtools/edge/chrome_url_overrides/newtab.html +0 -23
- package/dist/extension-js-devtools/edge/content_scripts/content-0.js +0 -5
- package/dist/extension-js-devtools/edge/content_scripts/styles.24e59c3d.css +0 -2
- package/dist/extension-js-devtools/edge/devtools/index.html +0 -12
- package/dist/extension-js-devtools/edge/devtools/index.js +0 -1
- package/dist/extension-js-devtools/edge/icons/logo.png +0 -0
- package/dist/extension-js-devtools/edge/manifest.json +0 -57
- package/dist/extension-js-devtools/edge/pages/centralized-logger.css +0 -2
- package/dist/extension-js-devtools/edge/pages/centralized-logger.html +0 -12
- package/dist/extension-js-devtools/edge/pages/centralized-logger.js +0 -15
- package/dist/extension-js-devtools/edge/pages/welcome.css +0 -2
- package/dist/extension-js-devtools/edge/pages/welcome.html +0 -11
- package/dist/extension-js-devtools/edge/pages/welcome.js +0 -25
- package/dist/extension-js-devtools/edge/scripts/logger-client.js +0 -1
- package/dist/extension-js-devtools/firefox/assets/developer-mode-off.f9a94937.jpeg +0 -0
- package/dist/extension-js-devtools/firefox/assets/developer-mode-on.ede80e5b.jpeg +0 -0
- package/dist/extension-js-devtools/firefox/assets/local-network-permission.4fae40a7.png +0 -0
- package/dist/extension-js-devtools/firefox/assets/logo.7dc70d61.png +0 -0
- package/dist/extension-js-devtools/firefox/background/scripts.js +0 -26
- package/dist/extension-js-devtools/firefox/content_scripts/content-0.js +0 -5
- package/dist/extension-js-devtools/firefox/content_scripts/styles.24e59c3d.css +0 -2
- package/dist/extension-js-devtools/firefox/devtools/index.html +0 -12
- package/dist/extension-js-devtools/firefox/devtools/index.js +0 -1
- package/dist/extension-js-devtools/firefox/icons/logo.png +0 -0
- package/dist/extension-js-devtools/firefox/manifest.json +0 -42
- package/dist/extension-js-devtools/firefox/pages/centralized-logger.css +0 -2
- package/dist/extension-js-devtools/firefox/pages/centralized-logger.html +0 -12
- package/dist/extension-js-devtools/firefox/pages/centralized-logger.js +0 -15
- package/dist/extension-js-devtools/firefox/pages/welcome.css +0 -2
- package/dist/extension-js-devtools/firefox/pages/welcome.html +0 -11
- package/dist/extension-js-devtools/firefox/pages/welcome.js +0 -25
- package/dist/extension-js-devtools/firefox/scripts/logger-client.js +0 -1
- package/dist/extension-js-theme/chrome/manifest.json +0 -66
- package/dist/extension-js-theme/chromium/manifest.json +0 -66
- package/dist/extension-js-theme/edge/manifest.json +0 -66
- package/dist/extension-js-theme/firefox/manifest.json +0 -66
- package/dist/warn-no-default-export.cjs +0 -356
- package/webpack/webpack-lib/optional-dependencies.json +0 -20
package/dist/215.cjs
CHANGED
|
@@ -10,6 +10,7 @@ exports.modules = {
|
|
|
10
10
|
var external_ws_ = __webpack_require__("ws");
|
|
11
11
|
var external_ws_default = /*#__PURE__*/ __webpack_require__.n(external_ws_);
|
|
12
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");
|
|
13
14
|
async function getExtensionInfo(cdp, extensionId) {
|
|
14
15
|
return await cdp.sendCommand('Extensions.getExtensionInfo', {
|
|
15
16
|
extensionId
|
|
@@ -34,28 +35,6 @@ exports.modules = {
|
|
|
34
35
|
return false;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
var discovery = __webpack_require__("./webpack/plugin-browsers/run-chromium/chromium-source-inspection/discovery.ts");
|
|
38
|
-
function establishBrowserConnection(url, isDev, onMessage, onRejectPending) {
|
|
39
|
-
return new Promise((resolve, reject)=>{
|
|
40
|
-
const ws = new (external_ws_default())(url);
|
|
41
|
-
ws.on('open', ()=>{
|
|
42
|
-
if (isDev) console.log(messages.F1E());
|
|
43
|
-
resolve(ws);
|
|
44
|
-
});
|
|
45
|
-
ws.on('message', (data)=>{
|
|
46
|
-
onMessage(data.toString());
|
|
47
|
-
});
|
|
48
|
-
ws.on('error', (error)=>{
|
|
49
|
-
if (isDev) console.error(messages.fRy(error.message));
|
|
50
|
-
onRejectPending(error.message);
|
|
51
|
-
reject(error);
|
|
52
|
-
});
|
|
53
|
-
ws.on('close', ()=>{
|
|
54
|
-
if (isDev) console.log(messages.hE8());
|
|
55
|
-
onRejectPending('CDP connection closed');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
38
|
function mergeShadowIntoDocument(mainHTML, shadowContent) {
|
|
60
39
|
try {
|
|
61
40
|
if (!mainHTML) return '';
|
|
@@ -68,12 +47,247 @@ exports.modules = {
|
|
|
68
47
|
}
|
|
69
48
|
const hostOpen = /(<[^>]*data-extension-root=(["'])true\2[^>]*>)/i;
|
|
70
49
|
if (hostOpen.test(mainHTML)) return mainHTML.replace(hostOpen, `$1<div id="extension-root">${shadowContent}</div>`);
|
|
71
|
-
|
|
72
|
-
return `${mainHTML}\n<div id="extension-root">${shadowContent}</div>`;
|
|
50
|
+
return mainHTML;
|
|
73
51
|
} catch {
|
|
74
52
|
return mainHTML;
|
|
75
53
|
}
|
|
76
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
|
+
}
|
|
77
291
|
async function getPageHTML(cdp, sessionId, includeShadow = 'open-only') {
|
|
78
292
|
try {
|
|
79
293
|
await cdp.evaluate(sessionId, 'document.title');
|
|
@@ -98,40 +312,62 @@ exports.modules = {
|
|
|
98
312
|
})()`);
|
|
99
313
|
const mainHTML = 'string' == typeof mainHTMLRaw ? mainHTMLRaw : String(mainHTMLRaw || '');
|
|
100
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;
|
|
101
323
|
try {
|
|
102
|
-
const mergedHtmlRaw = await cdp
|
|
324
|
+
const mergedHtmlRaw = await evaluateWithContentContext(cdp, sessionId, `(() => { try {
|
|
103
325
|
var cloned = document.documentElement.cloneNode(true);
|
|
104
|
-
var
|
|
105
|
-
if (!host) {
|
|
106
|
-
var body = cloned.querySelector('body') || cloned;
|
|
107
|
-
var newRoot = document.createElement('div');
|
|
108
|
-
newRoot.id='extension-root';
|
|
109
|
-
body.appendChild(newRoot);
|
|
110
|
-
host = newRoot;
|
|
111
|
-
}
|
|
326
|
+
var selector = ${JSON.stringify(NON_DEVTOOLS_CONTENT_ROOT_SELECTOR)};
|
|
112
327
|
var s = new XMLSerializer();
|
|
113
|
-
var shadow = '';
|
|
114
328
|
try {
|
|
115
|
-
var
|
|
116
|
-
if (
|
|
117
|
-
|
|
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){
|
|
118
353
|
try { return s.serializeToString(n) } catch(e){ return '' }
|
|
119
|
-
}).join('');
|
|
354
|
+
}).join('');
|
|
355
|
+
if (!shadow) continue;
|
|
356
|
+
try { host.innerHTML = shadow; } catch(e) {}
|
|
120
357
|
}
|
|
121
358
|
} catch(e) {}
|
|
122
|
-
try { host.innerHTML = shadow; } catch(e) {}
|
|
123
359
|
var doctype = document.doctype;
|
|
124
360
|
var dt = doctype ? '<!DOCTYPE ' + doctype.name + (doctype.publicId ? ' PUBLIC \"' + doctype.publicId + '\"' : '') + (doctype.systemId ? ' \"' + doctype.systemId + '\"' : '') + '>' : '';
|
|
125
361
|
return String(dt + '\\n' + (cloned.outerHTML || document.documentElement.outerHTML));
|
|
126
|
-
} catch(e) { try { return String(document.documentElement.outerHTML); } catch(_) { return '' } } })()
|
|
362
|
+
} catch(e) { try { return String(document.documentElement.outerHTML); } catch(_) { return '' } } })()`, (value)=>'string' == typeof value && /<html[\s>]/i.test(value));
|
|
127
363
|
const mergedHtml = 'string' == typeof mergedHtmlRaw ? mergedHtmlRaw : String(mergedHtmlRaw || '');
|
|
128
364
|
if (mergedHtml && /<html[\s>]/i.test(mergedHtml)) return mergedHtml;
|
|
129
365
|
} catch {}
|
|
130
366
|
let shadowContent = '';
|
|
131
367
|
try {
|
|
132
|
-
shadowContent = await cdp
|
|
368
|
+
shadowContent = await evaluateWithContentContext(cdp, sessionId, `(() => {
|
|
133
369
|
try {
|
|
134
|
-
const hosts = Array.from(document.querySelectorAll(
|
|
370
|
+
const hosts = Array.from(document.querySelectorAll(${JSON.stringify(CONTENT_ROOT_SELECTOR)}));
|
|
135
371
|
if (!hosts.length) return '';
|
|
136
372
|
const preferMarkers = ['iskilar_box','content_script','content_title','js-probe'];
|
|
137
373
|
let firstNonEmpty = '';
|
|
@@ -158,7 +394,7 @@ exports.modules = {
|
|
|
158
394
|
}
|
|
159
395
|
return firstNonEmpty || '';
|
|
160
396
|
} catch { return '' }
|
|
161
|
-
})()
|
|
397
|
+
})()`, (value)=>'string' == typeof value && value.trim().length > 0);
|
|
162
398
|
} catch {}
|
|
163
399
|
if (shadowContent) try {
|
|
164
400
|
const sc = 'string' == typeof shadowContent ? shadowContent : String(shadowContent || '');
|
|
@@ -199,8 +435,8 @@ exports.modules = {
|
|
|
199
435
|
const started = Date.now();
|
|
200
436
|
while(Date.now() < deadline){
|
|
201
437
|
try {
|
|
202
|
-
const injected = await cdp
|
|
203
|
-
const hosts = Array.from(document.querySelectorAll(
|
|
438
|
+
const injected = await evaluateWithContentContext(cdp, sessionId, `(() => { try {
|
|
439
|
+
const hosts = Array.from(document.querySelectorAll(${JSON.stringify(CONTENT_ROOT_SELECTOR)}));
|
|
204
440
|
if (!hosts.length) return false;
|
|
205
441
|
const markers = ['iskilar_box','content_script','content_title','js-probe'];
|
|
206
442
|
for (const h of hosts) {
|
|
@@ -218,13 +454,35 @@ exports.modules = {
|
|
|
218
454
|
} catch { /* ignore */ }
|
|
219
455
|
}
|
|
220
456
|
return false;
|
|
221
|
-
} catch { return false } })()
|
|
222
|
-
if (Boolean(injected)) return;
|
|
457
|
+
} catch { return false } })()`, (value)=>Boolean(value));
|
|
458
|
+
if (Boolean(injected)) return true;
|
|
223
459
|
} catch {}
|
|
224
460
|
const elapsed = Date.now() - started;
|
|
225
461
|
const delay = elapsed < 2000 ? 150 : 500;
|
|
226
462
|
await new Promise((r)=>setTimeout(r, delay));
|
|
227
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
|
+
});
|
|
228
486
|
}
|
|
229
487
|
function _define_property(obj, key, value) {
|
|
230
488
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -274,8 +532,14 @@ exports.modules = {
|
|
|
274
532
|
this.ws = null;
|
|
275
533
|
}
|
|
276
534
|
}
|
|
535
|
+
isConnected() {
|
|
536
|
+
return !!this.ws && this.ws.readyState === external_ws_default().OPEN;
|
|
537
|
+
}
|
|
277
538
|
onProtocolEvent(handler) {
|
|
278
|
-
this.
|
|
539
|
+
this.eventCallbacks.add(handler);
|
|
540
|
+
return ()=>{
|
|
541
|
+
this.eventCallbacks.delete(handler);
|
|
542
|
+
};
|
|
279
543
|
}
|
|
280
544
|
handleMessage(data) {
|
|
281
545
|
try {
|
|
@@ -294,7 +558,7 @@ exports.modules = {
|
|
|
294
558
|
const params = message.params || {};
|
|
295
559
|
if (this.isDev()) console.log(messages.p8m(String(params.sessionId || ''), String(params.targetInfo?.type || '')));
|
|
296
560
|
}
|
|
297
|
-
|
|
561
|
+
for (const eventCallback of this.eventCallbacks)eventCallback(message);
|
|
298
562
|
} catch (error) {
|
|
299
563
|
if (this.isDev()) {
|
|
300
564
|
const err = error;
|
|
@@ -382,10 +646,32 @@ exports.modules = {
|
|
|
382
646
|
async waitForContentScriptInjection(sessionId) {
|
|
383
647
|
return waitForContentScriptInjection(this, sessionId);
|
|
384
648
|
}
|
|
385
|
-
async
|
|
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) {
|
|
386
662
|
const response = await this.sendCommand('Runtime.evaluate', {
|
|
387
663
|
expression,
|
|
388
|
-
returnByValue: true
|
|
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
|
|
389
675
|
}, sessionId);
|
|
390
676
|
return response.result?.value;
|
|
391
677
|
}
|
|
@@ -398,25 +684,20 @@ exports.modules = {
|
|
|
398
684
|
});
|
|
399
685
|
}
|
|
400
686
|
async forceReloadExtension(extensionId) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
for(let i = 0; i < attempts; i++){
|
|
410
|
-
try {
|
|
411
|
-
const ok = await this.reloadExtensionViaTargetEval(extensionId);
|
|
412
|
-
if (ok) return true;
|
|
413
|
-
} catch {}
|
|
414
|
-
const backoffMs = Math.min(1200, 150 * (i + 1));
|
|
415
|
-
await new Promise((r)=>setTimeout(r, backoffMs));
|
|
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;
|
|
416
695
|
}
|
|
417
|
-
|
|
418
|
-
|
|
696
|
+
const backoffMs = Math.min(1200, 150 * (i + 1));
|
|
697
|
+
await new Promise((r)=>setTimeout(r, backoffMs));
|
|
419
698
|
}
|
|
699
|
+
console.warn(messages.ccn(extensionId, lastError?.message || String(lastError || 'runtime.reload failed')));
|
|
700
|
+
return false;
|
|
420
701
|
}
|
|
421
702
|
async getExtensionInfo(extensionId) {
|
|
422
703
|
try {
|
|
@@ -479,7 +760,7 @@ exports.modules = {
|
|
|
479
760
|
_define_property(this, "host", void 0);
|
|
480
761
|
_define_property(this, "ws", null);
|
|
481
762
|
_define_property(this, "targetWebSocketUrl", null);
|
|
482
|
-
_define_property(this, "
|
|
763
|
+
_define_property(this, "eventCallbacks", new Set());
|
|
483
764
|
_define_property(this, "messageId", 0);
|
|
484
765
|
_define_property(this, "pendingRequests", new Map());
|
|
485
766
|
this.port = port;
|