extension 3.18.4 → 3.18.5-canary.local-b4fd0431
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/{322.cjs → 315.cjs} +127 -790
- package/dist/632.cjs +104 -0
- package/dist/browsers.cjs +1106 -1840
- package/dist/cli.cjs +1205 -1829
- package/dist/extension/browsers/browsers-lib/instance-registry.d.ts +38 -0
- package/dist/extension/browsers/browsers-lib/messages.d.ts +11 -0
- package/dist/extension/browsers/browsers-lib/output-binaries-resolver.d.ts +1 -1
- package/dist/extension/browsers/browsers-lib/process-teardown.d.ts +6 -0
- package/dist/extension/browsers/browsers-lib/resolve-profile.d.ts +62 -0
- package/dist/extension/browsers/browsers-lib/runtime-options.d.ts +3 -3
- package/dist/extension/browsers/browsers-lib/wsl-support.d.ts +1 -3
- package/dist/extension/browsers/browsers-types.d.ts +1 -1
- package/dist/extension/browsers/index.d.ts +7 -6
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/cdp-client.d.ts +3 -2
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/cdp-extension-controller/index.d.ts +3 -75
- package/dist/extension/browsers/run-chromium/chromium-source-inspection/cdp-extension-controller/ownership.d.ts +2 -0
- package/dist/extension/browsers/run-chromium/chromium-types.d.ts +136 -1
- package/dist/extension/browsers/run-firefox/firefox-launch/binary-detector.d.ts +8 -1
- package/dist/extension/browsers/run-firefox/firefox-launch/index.d.ts +1 -2
- package/dist/extension/browsers/run-firefox/firefox-launch/process-handlers.d.ts +1 -2
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/index.d.ts +4 -0
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/rdp-extension-controller/index.d.ts +1 -7
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/index.d.ts +2 -18
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/messaging-client.d.ts +9 -15
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/rdp-api.d.ts +2 -6
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/rdp-types.d.ts +99 -0
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/runtime-reinject.d.ts +0 -27
- package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/source-inspect.d.ts +6 -6
- package/dist/extension/browsers/run-firefox/firefox-types.d.ts +1 -1
- package/dist/extension/browsers/run-safari/safari-launch/safari-config.d.ts +10 -0
- package/dist/extension/config-types.d.ts +131 -0
- package/dist/extension/index.d.ts +1 -1
- package/package.json +20 -13
package/dist/{322.cjs → 315.cjs}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
exports.ids = [
|
|
3
|
-
|
|
3
|
+
315
|
|
4
4
|
];
|
|
5
5
|
exports.modules = {
|
|
6
6
|
"./browsers/run-chromium/chromium-launch/setup-cdp-after-launch.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
@@ -12,8 +12,6 @@ exports.modules = {
|
|
|
12
12
|
var messages = __webpack_require__("./browsers/browsers-lib/messages.ts");
|
|
13
13
|
var shared_utils = __webpack_require__("./browsers/browsers-lib/shared-utils.ts");
|
|
14
14
|
var banner = __webpack_require__("./browsers/browsers-lib/banner.ts");
|
|
15
|
-
var content_script_targets = __webpack_require__("./browsers/browsers-lib/content-script-targets.ts");
|
|
16
|
-
var content_script_contracts = __webpack_require__("./browsers/browsers-lib/content-script-contracts.ts");
|
|
17
15
|
var external_ws_ = __webpack_require__("ws");
|
|
18
16
|
var external_ws_default = /*#__PURE__*/ __webpack_require__.n(external_ws_);
|
|
19
17
|
var constants = __webpack_require__("./browsers/browsers-lib/constants.ts");
|
|
@@ -922,6 +920,71 @@ exports.modules = {
|
|
|
922
920
|
this.host = host;
|
|
923
921
|
}
|
|
924
922
|
}
|
|
923
|
+
function isRecoverableBootstrapError(error) {
|
|
924
|
+
const msg = String(error?.message || error || '').toLowerCase();
|
|
925
|
+
return msg.includes('econnreset') || msg.includes('websocket is not open') || msg.includes('cdp transport is not open') || msg.includes('cdp connection closed') || msg.includes('cdp pipe closed') || msg.includes('socket hang up') || msg.includes('timed out') || msg.includes('no cdp websocket url');
|
|
926
|
+
}
|
|
927
|
+
async function connectToChromeCdpViaPipe(pipeIn, pipeOut, cdpPort = 0, cdpHost = '127.0.0.1') {
|
|
928
|
+
const cdp = new CDPClient(cdpPort, cdpHost);
|
|
929
|
+
try {
|
|
930
|
+
await cdp.connectViaPipe(pipeIn, pipeOut);
|
|
931
|
+
await cdp.sendCommand('Target.setDiscoverTargets', {
|
|
932
|
+
discover: true
|
|
933
|
+
});
|
|
934
|
+
await cdp.sendCommand('Target.setAutoAttach', {
|
|
935
|
+
autoAttach: true,
|
|
936
|
+
waitForDebuggerOnStart: false,
|
|
937
|
+
flatten: true,
|
|
938
|
+
filter: EXTENSION_AUTO_ATTACH_FILTER
|
|
939
|
+
});
|
|
940
|
+
return cdp;
|
|
941
|
+
} catch (error) {
|
|
942
|
+
cdp.disconnect();
|
|
943
|
+
throw error;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
async function connectToChromeCdp(cdpPort, cdpHost = '127.0.0.1') {
|
|
947
|
+
let retries = 0;
|
|
948
|
+
const maxRetries = 60;
|
|
949
|
+
const backoffMs = 250;
|
|
950
|
+
while(retries < maxRetries){
|
|
951
|
+
const ready = await (0, discovery.z)(cdpPort, cdpHost);
|
|
952
|
+
if (ready) break;
|
|
953
|
+
retries++;
|
|
954
|
+
await new Promise((r)=>setTimeout(r, backoffMs));
|
|
955
|
+
}
|
|
956
|
+
const maxBootstrapAttempts = 4;
|
|
957
|
+
let lastError = null;
|
|
958
|
+
for(let attempt = 1; attempt <= maxBootstrapAttempts; attempt++){
|
|
959
|
+
const cdp = new CDPClient(cdpPort, cdpHost);
|
|
960
|
+
try {
|
|
961
|
+
await cdp.connect();
|
|
962
|
+
await cdp.sendCommand('Target.setDiscoverTargets', {
|
|
963
|
+
discover: true
|
|
964
|
+
});
|
|
965
|
+
await cdp.sendCommand('Target.setAutoAttach', {
|
|
966
|
+
autoAttach: true,
|
|
967
|
+
waitForDebuggerOnStart: false,
|
|
968
|
+
flatten: true,
|
|
969
|
+
filter: EXTENSION_AUTO_ATTACH_FILTER
|
|
970
|
+
});
|
|
971
|
+
return cdp;
|
|
972
|
+
} catch (error) {
|
|
973
|
+
lastError = error;
|
|
974
|
+
cdp.disconnect();
|
|
975
|
+
const retryable = isRecoverableBootstrapError(error);
|
|
976
|
+
const hasMoreAttempts = attempt < maxBootstrapAttempts;
|
|
977
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) {
|
|
978
|
+
const base = String(error?.message || error);
|
|
979
|
+
console.warn(`[CDP] bootstrap attempt ${attempt}/${maxBootstrapAttempts} failed: ${base}`);
|
|
980
|
+
}
|
|
981
|
+
if (!retryable || !hasMoreAttempts) throw error;
|
|
982
|
+
const delayMs = 120 * attempt;
|
|
983
|
+
await new Promise((r)=>setTimeout(r, delayMs));
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
throw lastError instanceof Error ? lastError : new Error('Failed to bootstrap CDP connection');
|
|
987
|
+
}
|
|
925
988
|
async function deriveExtensionIdFromTargetsHelper(cdp, outPath, maxRetries = 6, backoffMs = 150, profilePath, extensionPaths) {
|
|
926
989
|
let expectedName;
|
|
927
990
|
let expectedVersion;
|
|
@@ -1073,71 +1136,6 @@ exports.modules = {
|
|
|
1073
1136
|
}
|
|
1074
1137
|
return deriveFromProfile() || deferredFirstEvalId || deferredUrlDerivedId;
|
|
1075
1138
|
}
|
|
1076
|
-
function isRecoverableBootstrapError(error) {
|
|
1077
|
-
const msg = String(error?.message || error || '').toLowerCase();
|
|
1078
|
-
return msg.includes('econnreset') || msg.includes('websocket is not open') || msg.includes('cdp transport is not open') || msg.includes('cdp connection closed') || msg.includes('cdp pipe closed') || msg.includes('socket hang up') || msg.includes('timed out') || msg.includes('no cdp websocket url');
|
|
1079
|
-
}
|
|
1080
|
-
async function connectToChromeCdpViaPipe(pipeIn, pipeOut, cdpPort = 0, cdpHost = '127.0.0.1') {
|
|
1081
|
-
const cdp = new CDPClient(cdpPort, cdpHost);
|
|
1082
|
-
try {
|
|
1083
|
-
await cdp.connectViaPipe(pipeIn, pipeOut);
|
|
1084
|
-
await cdp.sendCommand('Target.setDiscoverTargets', {
|
|
1085
|
-
discover: true
|
|
1086
|
-
});
|
|
1087
|
-
await cdp.sendCommand('Target.setAutoAttach', {
|
|
1088
|
-
autoAttach: true,
|
|
1089
|
-
waitForDebuggerOnStart: false,
|
|
1090
|
-
flatten: true,
|
|
1091
|
-
filter: EXTENSION_AUTO_ATTACH_FILTER
|
|
1092
|
-
});
|
|
1093
|
-
return cdp;
|
|
1094
|
-
} catch (error) {
|
|
1095
|
-
cdp.disconnect();
|
|
1096
|
-
throw error;
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
async function connectToChromeCdp(cdpPort, cdpHost = '127.0.0.1') {
|
|
1100
|
-
let retries = 0;
|
|
1101
|
-
const maxRetries = 60;
|
|
1102
|
-
const backoffMs = 250;
|
|
1103
|
-
while(retries < maxRetries){
|
|
1104
|
-
const ready = await (0, discovery.z)(cdpPort, cdpHost);
|
|
1105
|
-
if (ready) break;
|
|
1106
|
-
retries++;
|
|
1107
|
-
await new Promise((r)=>setTimeout(r, backoffMs));
|
|
1108
|
-
}
|
|
1109
|
-
const maxBootstrapAttempts = 4;
|
|
1110
|
-
let lastError = null;
|
|
1111
|
-
for(let attempt = 1; attempt <= maxBootstrapAttempts; attempt++){
|
|
1112
|
-
const cdp = new CDPClient(cdpPort, cdpHost);
|
|
1113
|
-
try {
|
|
1114
|
-
await cdp.connect();
|
|
1115
|
-
await cdp.sendCommand('Target.setDiscoverTargets', {
|
|
1116
|
-
discover: true
|
|
1117
|
-
});
|
|
1118
|
-
await cdp.sendCommand('Target.setAutoAttach', {
|
|
1119
|
-
autoAttach: true,
|
|
1120
|
-
waitForDebuggerOnStart: false,
|
|
1121
|
-
flatten: true,
|
|
1122
|
-
filter: EXTENSION_AUTO_ATTACH_FILTER
|
|
1123
|
-
});
|
|
1124
|
-
return cdp;
|
|
1125
|
-
} catch (error) {
|
|
1126
|
-
lastError = error;
|
|
1127
|
-
cdp.disconnect();
|
|
1128
|
-
const retryable = isRecoverableBootstrapError(error);
|
|
1129
|
-
const hasMoreAttempts = attempt < maxBootstrapAttempts;
|
|
1130
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) {
|
|
1131
|
-
const base = String(error?.message || error);
|
|
1132
|
-
console.warn(`[CDP] bootstrap attempt ${attempt}/${maxBootstrapAttempts} failed: ${base}`);
|
|
1133
|
-
}
|
|
1134
|
-
if (!retryable || !hasMoreAttempts) throw error;
|
|
1135
|
-
const delayMs = 120 * attempt;
|
|
1136
|
-
await new Promise((r)=>setTimeout(r, delayMs));
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
throw lastError instanceof Error ? lastError : new Error('Failed to bootstrap CDP connection');
|
|
1140
|
-
}
|
|
1141
1139
|
var ensure = __webpack_require__("./browsers/run-chromium/chromium-source-inspection/cdp-extension-controller/ensure.ts");
|
|
1142
1140
|
function registerAutoEnableLogging(cdp, getExtensionId) {
|
|
1143
1141
|
cdp.onProtocolEvent((message)=>{
|
|
@@ -1166,6 +1164,37 @@ exports.modules = {
|
|
|
1166
1164
|
}
|
|
1167
1165
|
});
|
|
1168
1166
|
}
|
|
1167
|
+
function ownership_normalizePath(input) {
|
|
1168
|
+
try {
|
|
1169
|
+
return external_fs_.realpathSync(external_path_.resolve(input));
|
|
1170
|
+
} catch {
|
|
1171
|
+
return external_path_.resolve(input);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
function classifyExtensionOwnership(profilePath, outPath, extensionId) {
|
|
1175
|
+
if (!profilePath || !extensionId) return 'unknown';
|
|
1176
|
+
const prefCandidates = [];
|
|
1177
|
+
const addPrefCandidate = (dir)=>{
|
|
1178
|
+
const prefPath = external_path_.join(dir, 'Preferences');
|
|
1179
|
+
if (external_fs_.existsSync(prefPath)) prefCandidates.push(prefPath);
|
|
1180
|
+
};
|
|
1181
|
+
try {
|
|
1182
|
+
addPrefCandidate(profilePath);
|
|
1183
|
+
addPrefCandidate(external_path_.join(profilePath, 'Default'));
|
|
1184
|
+
for (const entry of external_fs_.readdirSync(profilePath))if (/^Profile\s+\d+$/i.test(entry)) addPrefCandidate(external_path_.join(profilePath, entry));
|
|
1185
|
+
} catch {}
|
|
1186
|
+
if (0 === prefCandidates.length) return 'unknown';
|
|
1187
|
+
const normalizedOutPath = ownership_normalizePath(outPath);
|
|
1188
|
+
for (const prefPath of prefCandidates)try {
|
|
1189
|
+
const prefs = JSON.parse(external_fs_.readFileSync(prefPath, 'utf-8'));
|
|
1190
|
+
const settings = prefs?.extensions?.settings;
|
|
1191
|
+
const info = settings?.[extensionId];
|
|
1192
|
+
const storedPath = String(info?.path || '');
|
|
1193
|
+
if (!storedPath) continue;
|
|
1194
|
+
return ownership_normalizePath(storedPath) === normalizedOutPath ? 'mine' : 'not_mine';
|
|
1195
|
+
} catch {}
|
|
1196
|
+
return 'unknown';
|
|
1197
|
+
}
|
|
1169
1198
|
function cdp_extension_controller_define_property(obj, key, value) {
|
|
1170
1199
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1171
1200
|
value: value,
|
|
@@ -1212,8 +1241,22 @@ exports.modules = {
|
|
|
1212
1241
|
if (id) this.extensionId = id;
|
|
1213
1242
|
}
|
|
1214
1243
|
if (this.extensionId) {
|
|
1215
|
-
const
|
|
1216
|
-
if (
|
|
1244
|
+
const ownership = this.classifyOwnership(this.extensionId);
|
|
1245
|
+
if ('not_mine' === ownership) this.extensionId = null;
|
|
1246
|
+
else if ('unknown' === ownership && this.profilePath) for(let attempt = 0; attempt < 5; attempt++){
|
|
1247
|
+
await new Promise((r)=>setTimeout(r, 200));
|
|
1248
|
+
const candidate = this.extensionId || await this.deriveExtensionIdFromTargets(4, 150);
|
|
1249
|
+
if (!candidate) continue;
|
|
1250
|
+
const verdict = this.classifyOwnership(candidate);
|
|
1251
|
+
if ('mine' === verdict) {
|
|
1252
|
+
this.extensionId = candidate;
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
if ('not_mine' === verdict) {
|
|
1256
|
+
this.extensionId = null;
|
|
1257
|
+
break;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1217
1260
|
}
|
|
1218
1261
|
if (this.extensionId) try {
|
|
1219
1262
|
let info = null;
|
|
@@ -1266,36 +1309,8 @@ exports.modules = {
|
|
|
1266
1309
|
if (!this.cdp) return null;
|
|
1267
1310
|
return await deriveExtensionIdFromTargetsHelper(this.cdp, this.outPath, maxRetries, backoffMs, this.profilePath, this.extensionPaths);
|
|
1268
1311
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
return external_fs_.realpathSync(external_path_.resolve(input));
|
|
1272
|
-
} catch {
|
|
1273
|
-
return external_path_.resolve(input);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
extensionIdBelongsToOutPath(extensionId) {
|
|
1277
|
-
if (!this.profilePath || !extensionId) return null;
|
|
1278
|
-
const prefCandidates = [];
|
|
1279
|
-
const addPrefCandidate = (dir)=>{
|
|
1280
|
-
const prefPath = external_path_.join(dir, 'Preferences');
|
|
1281
|
-
if (external_fs_.existsSync(prefPath)) prefCandidates.push(prefPath);
|
|
1282
|
-
};
|
|
1283
|
-
try {
|
|
1284
|
-
addPrefCandidate(this.profilePath);
|
|
1285
|
-
addPrefCandidate(external_path_.join(this.profilePath, 'Default'));
|
|
1286
|
-
for (const entry of external_fs_.readdirSync(this.profilePath))if (/^Profile\s+\d+$/i.test(entry)) addPrefCandidate(external_path_.join(this.profilePath, entry));
|
|
1287
|
-
} catch {}
|
|
1288
|
-
if (0 === prefCandidates.length) return null;
|
|
1289
|
-
const normalizedOutPath = this.normalizePath(this.outPath);
|
|
1290
|
-
for (const prefPath of prefCandidates)try {
|
|
1291
|
-
const prefs = JSON.parse(external_fs_.readFileSync(prefPath, 'utf-8'));
|
|
1292
|
-
const settings = prefs?.extensions?.settings;
|
|
1293
|
-
const info = settings?.[extensionId];
|
|
1294
|
-
const storedPath = String(info?.path || '');
|
|
1295
|
-
if (!storedPath) continue;
|
|
1296
|
-
return this.normalizePath(storedPath) === normalizedOutPath;
|
|
1297
|
-
} catch {}
|
|
1298
|
-
return null;
|
|
1312
|
+
classifyOwnership(extensionId) {
|
|
1313
|
+
return classifyExtensionOwnership(this.profilePath, this.outPath, extensionId);
|
|
1299
1314
|
}
|
|
1300
1315
|
getDeveloperModeStatus() {
|
|
1301
1316
|
if (!this.profilePath) return 'unknown';
|
|
@@ -1323,413 +1338,6 @@ exports.modules = {
|
|
|
1323
1338
|
} catch {}
|
|
1324
1339
|
return 'unknown';
|
|
1325
1340
|
}
|
|
1326
|
-
getLastRuntimeReinjectionReport() {
|
|
1327
|
-
return this.lastRuntimeReinjectionReport;
|
|
1328
|
-
}
|
|
1329
|
-
async reloadMatchingTabsForContentScripts(rules, options = {}) {
|
|
1330
|
-
if (!this.cdp || 0 === rules.length) return 0;
|
|
1331
|
-
let reinjectedTabs = 0;
|
|
1332
|
-
const targets = await this.cdp.getTargets();
|
|
1333
|
-
for (const target of targets || []){
|
|
1334
|
-
const targetType = String(target?.type || '');
|
|
1335
|
-
const targetId = String(target?.targetId || '');
|
|
1336
|
-
const targetUrl = String(target?.url || '');
|
|
1337
|
-
if ('page' !== targetType || !targetId || !targetUrl) continue;
|
|
1338
|
-
const matchingRules = rules.filter((rule)=>(0, content_script_targets.lM)(targetUrl, [
|
|
1339
|
-
rule
|
|
1340
|
-
]));
|
|
1341
|
-
if (0 !== matchingRules.length) try {
|
|
1342
|
-
const sessionId = await this.cdp.attachToTarget(targetId);
|
|
1343
|
-
let reinjected = false;
|
|
1344
|
-
if (options.preferPageReload) reinjected = await this.reloadPageTarget(sessionId);
|
|
1345
|
-
else {
|
|
1346
|
-
for (const [index, rule] of matchingRules.entries()){
|
|
1347
|
-
const didReinject = await this.reinjectContentScriptRule(sessionId, rule, options.allowCoarseCleanup ?? 0 === index, options.sourceOverridesByBundleId);
|
|
1348
|
-
reinjected = reinjected || didReinject;
|
|
1349
|
-
}
|
|
1350
|
-
if (!reinjected) reinjected = await this.reloadPageTarget(sessionId);
|
|
1351
|
-
}
|
|
1352
|
-
if (reinjected) reinjectedTabs += 1;
|
|
1353
|
-
} catch (error) {
|
|
1354
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(`[CDP] Failed to reinject content scripts into ${targetUrl}: ${String(error?.message || error)}`);
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
return reinjectedTabs;
|
|
1358
|
-
}
|
|
1359
|
-
async registerContentScriptsForFutureNavigations(rules) {
|
|
1360
|
-
this.activeContentScriptRules = [
|
|
1361
|
-
...rules
|
|
1362
|
-
];
|
|
1363
|
-
if (!this.cdp) return;
|
|
1364
|
-
if (!this.contentScriptTargetListenerInstalled) {
|
|
1365
|
-
this.contentScriptTargetListenerInstalled = true;
|
|
1366
|
-
this.installContentScriptTargetListener();
|
|
1367
|
-
}
|
|
1368
|
-
try {
|
|
1369
|
-
const targets = await this.cdp.getTargets();
|
|
1370
|
-
for (const target of targets || []){
|
|
1371
|
-
if ('page' !== String(target?.type || '')) continue;
|
|
1372
|
-
const targetId = String(target?.targetId || '');
|
|
1373
|
-
const url = String(target?.url || '');
|
|
1374
|
-
if (targetId && url) {
|
|
1375
|
-
if (this.urlMatchesAnyActiveRule(url)) await this.ensureWatchedPageSession(targetId, url);
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
} catch {}
|
|
1379
|
-
}
|
|
1380
|
-
installContentScriptTargetListener() {
|
|
1381
|
-
if (!this.cdp) return;
|
|
1382
|
-
this.cdp.onProtocolEvent((raw)=>{
|
|
1383
|
-
const method = String(raw.method || '');
|
|
1384
|
-
const params = raw.params;
|
|
1385
|
-
const sessionId = String(raw.sessionId || '');
|
|
1386
|
-
if ('Target.targetCreated' === method || 'Target.targetInfoChanged' === method) {
|
|
1387
|
-
const targetInfo = params?.targetInfo;
|
|
1388
|
-
if (!targetInfo || 'page' !== targetInfo.type) return;
|
|
1389
|
-
const targetId = String(targetInfo.targetId || '');
|
|
1390
|
-
const url = String(targetInfo.url || '');
|
|
1391
|
-
if (!targetId) return;
|
|
1392
|
-
if (!this.urlMatchesAnyActiveRule(url)) {
|
|
1393
|
-
for (const info of this.watchedPageSessions.values())if (info.targetId === targetId) info.url = url;
|
|
1394
|
-
return;
|
|
1395
|
-
}
|
|
1396
|
-
this.ensureWatchedPageSession(targetId, url).catch(()=>{});
|
|
1397
|
-
return;
|
|
1398
|
-
}
|
|
1399
|
-
if ('Runtime.executionContextCreated' === method) {
|
|
1400
|
-
if (!sessionId) return;
|
|
1401
|
-
const session = this.watchedPageSessions.get(sessionId);
|
|
1402
|
-
if (!session) return;
|
|
1403
|
-
if (this.suppressInitialContextBurst.has(sessionId)) return;
|
|
1404
|
-
const context = params?.context;
|
|
1405
|
-
if (!context) return;
|
|
1406
|
-
this.evaluateContentScriptOnNewContext(sessionId, session, context).catch(()=>{});
|
|
1407
|
-
return;
|
|
1408
|
-
}
|
|
1409
|
-
if ('Target.detachedFromTarget' === method) {
|
|
1410
|
-
if (sessionId) {
|
|
1411
|
-
this.watchedPageSessions.delete(sessionId);
|
|
1412
|
-
this.releaseSessionContexts(sessionId);
|
|
1413
|
-
this.suppressInitialContextBurst.delete(sessionId);
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
});
|
|
1417
|
-
}
|
|
1418
|
-
urlMatchesAnyActiveRule(url) {
|
|
1419
|
-
if (!url || 0 === this.activeContentScriptRules.length) return false;
|
|
1420
|
-
return this.activeContentScriptRules.some((rule)=>(0, content_script_targets.lM)(url, [
|
|
1421
|
-
rule
|
|
1422
|
-
]));
|
|
1423
|
-
}
|
|
1424
|
-
async ensureWatchedPageSession(targetId, url) {
|
|
1425
|
-
if (!this.cdp) return;
|
|
1426
|
-
for (const info of this.watchedPageSessions.values())if (info.targetId === targetId) {
|
|
1427
|
-
info.url = url;
|
|
1428
|
-
return;
|
|
1429
|
-
}
|
|
1430
|
-
let sessionId;
|
|
1431
|
-
try {
|
|
1432
|
-
sessionId = await this.cdp.attachToTarget(targetId);
|
|
1433
|
-
} catch {
|
|
1434
|
-
return;
|
|
1435
|
-
}
|
|
1436
|
-
this.watchedPageSessions.set(sessionId, {
|
|
1437
|
-
targetId,
|
|
1438
|
-
url
|
|
1439
|
-
});
|
|
1440
|
-
this.suppressInitialContextBurst.add(sessionId);
|
|
1441
|
-
try {
|
|
1442
|
-
await this.cdp.sendCommand('Runtime.enable', {}, sessionId);
|
|
1443
|
-
setTimeout(()=>{
|
|
1444
|
-
this.suppressInitialContextBurst.delete(sessionId);
|
|
1445
|
-
}, 250);
|
|
1446
|
-
} catch {
|
|
1447
|
-
this.watchedPageSessions.delete(sessionId);
|
|
1448
|
-
this.suppressInitialContextBurst.delete(sessionId);
|
|
1449
|
-
}
|
|
1450
|
-
}
|
|
1451
|
-
async evaluateContentScriptOnNewContext(sessionId, session, context) {
|
|
1452
|
-
if (!this.cdp) return;
|
|
1453
|
-
const contextId = context.id;
|
|
1454
|
-
if ('number' != typeof contextId) return;
|
|
1455
|
-
if (!this.urlMatchesAnyActiveRule(session.url)) return;
|
|
1456
|
-
const auxData = context.auxData || {};
|
|
1457
|
-
const origin = String(context.origin || '');
|
|
1458
|
-
const extensionId = this.extensionId || await this.deriveExtensionIdFromTargets();
|
|
1459
|
-
const extensionOrigin = extensionId ? `chrome-extension://${extensionId}` : '';
|
|
1460
|
-
const matchingRules = this.activeContentScriptRules.filter((rule)=>{
|
|
1461
|
-
if (!(0, content_script_targets.lM)(session.url, [
|
|
1462
|
-
rule
|
|
1463
|
-
])) return false;
|
|
1464
|
-
if ('main' === rule.world) return 'default' === auxData.type && true === auxData.isDefault;
|
|
1465
|
-
return 'isolated' === auxData.type && origin === extensionOrigin;
|
|
1466
|
-
});
|
|
1467
|
-
if (0 === matchingRules.length) return;
|
|
1468
|
-
for (const rule of matchingRules){
|
|
1469
|
-
const bundlePath = (0, content_script_targets.nG)(this.outPath, rule.index, 'js');
|
|
1470
|
-
if (!bundlePath || !external_fs_.existsSync(bundlePath)) continue;
|
|
1471
|
-
const source = this.patchReinjectSourceForInvalidatedRuntime(readTextFileCached(bundlePath));
|
|
1472
|
-
if (!source.trim()) continue;
|
|
1473
|
-
const bundleId = (0, content_script_contracts.Y)(rule.index);
|
|
1474
|
-
const expression = this.buildReinjectExpression(bundleId, source, true);
|
|
1475
|
-
try {
|
|
1476
|
-
await this.cdp.evaluateInContext(sessionId, expression, contextId);
|
|
1477
|
-
} catch {}
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
async reinjectMatchingTabsViaExtensionRuntime(rules) {
|
|
1481
|
-
if (!this.cdp || 0 === rules.length) {
|
|
1482
|
-
this.lastRuntimeReinjectionReport = {
|
|
1483
|
-
phase: 'skipped',
|
|
1484
|
-
reason: 'missing_cdp_or_rules',
|
|
1485
|
-
hasCdp: !!this.cdp,
|
|
1486
|
-
ruleCount: rules.length
|
|
1487
|
-
};
|
|
1488
|
-
return 0;
|
|
1489
|
-
}
|
|
1490
|
-
const targets = await this.cdp.getTargets();
|
|
1491
|
-
const matchingUrlsByRule = new Map();
|
|
1492
|
-
for (const target of targets || []){
|
|
1493
|
-
const targetType = String(target?.type || '');
|
|
1494
|
-
const targetUrl = String(target?.url || '');
|
|
1495
|
-
if ('page' === targetType && targetUrl) for (const rule of rules){
|
|
1496
|
-
if (!(0, content_script_targets.lM)(targetUrl, [
|
|
1497
|
-
rule
|
|
1498
|
-
])) continue;
|
|
1499
|
-
const urls = matchingUrlsByRule.get(rule.index) || new Set();
|
|
1500
|
-
urls.add(targetUrl);
|
|
1501
|
-
matchingUrlsByRule.set(rule.index, urls);
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
const payload = rules.map((rule)=>{
|
|
1505
|
-
const jsPath = (0, content_script_targets.nG)(this.outPath, rule.index, 'js');
|
|
1506
|
-
const cssPath = (0, content_script_targets.nG)(this.outPath, rule.index, 'css');
|
|
1507
|
-
if (!jsPath || !external_fs_.existsSync(jsPath)) return null;
|
|
1508
|
-
const jsFile = external_path_.relative(this.outPath, jsPath).replace(/\\/g, '/');
|
|
1509
|
-
const cssFile = cssPath && external_fs_.existsSync(cssPath) ? external_path_.relative(this.outPath, cssPath).replace(/\\/g, '/') : null;
|
|
1510
|
-
const jsSource = readTextFileCached(jsPath);
|
|
1511
|
-
const buildTokenMatch = jsSource.match(/__EXTENSIONJS_REINJECT_BUILD_TOKEN\s*=\s*"([^"]+)"/);
|
|
1512
|
-
const proofMatch = jsSource.match(/extjs-chromium-live-content-css-modules:script-primary-\d+/) || jsSource.match(/Live Update Proof [A-Za-z0-9_-]+/);
|
|
1513
|
-
return {
|
|
1514
|
-
index: rule.index,
|
|
1515
|
-
world: rule.world,
|
|
1516
|
-
matches: [
|
|
1517
|
-
...rule.matches
|
|
1518
|
-
],
|
|
1519
|
-
urls: Array.from(matchingUrlsByRule.get(rule.index) || []).sort(),
|
|
1520
|
-
jsFile,
|
|
1521
|
-
cssFile,
|
|
1522
|
-
buildToken: buildTokenMatch?.[1] || null,
|
|
1523
|
-
proofMarker: proofMatch?.[0] || null
|
|
1524
|
-
};
|
|
1525
|
-
}).filter((entry)=>!!entry && entry.urls.length > 0);
|
|
1526
|
-
if (0 === payload.length) {
|
|
1527
|
-
this.lastRuntimeReinjectionReport = {
|
|
1528
|
-
phase: 'skipped',
|
|
1529
|
-
reason: 'no_payload',
|
|
1530
|
-
ruleCount: rules.length
|
|
1531
|
-
};
|
|
1532
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log('[CDP] extension-runtime reinjection skipped: no payload');
|
|
1533
|
-
return 0;
|
|
1534
|
-
}
|
|
1535
|
-
const runtimeTarget = await this.attachToExtensionRuntimeTarget();
|
|
1536
|
-
if (!runtimeTarget) {
|
|
1537
|
-
const targetSummary = (targets || []).map((target)=>({
|
|
1538
|
-
type: String(target?.type || ''),
|
|
1539
|
-
url: String(target?.url || '')
|
|
1540
|
-
})).filter((entry)=>entry.type || entry.url);
|
|
1541
|
-
this.lastRuntimeReinjectionReport = {
|
|
1542
|
-
phase: 'unavailable',
|
|
1543
|
-
reason: 'no_runtime_target',
|
|
1544
|
-
extensionId: this.extensionId,
|
|
1545
|
-
targets: targetSummary
|
|
1546
|
-
};
|
|
1547
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(`[CDP] extension-runtime reinjection unavailable: ${JSON.stringify({
|
|
1548
|
-
extensionId: this.extensionId,
|
|
1549
|
-
targets: targetSummary
|
|
1550
|
-
})}`);
|
|
1551
|
-
return 0;
|
|
1552
|
-
}
|
|
1553
|
-
const result = await this.cdp.evaluate(runtimeTarget.sessionId, `(() => (async () => {
|
|
1554
|
-
const payload = ${JSON.stringify(payload)};
|
|
1555
|
-
const chromeRuntime =
|
|
1556
|
-
typeof globalThis === 'object' && globalThis && globalThis.chrome
|
|
1557
|
-
? globalThis.chrome
|
|
1558
|
-
: null;
|
|
1559
|
-
const runtimeChrome =
|
|
1560
|
-
chromeRuntime &&
|
|
1561
|
-
chromeRuntime.scripting &&
|
|
1562
|
-
chromeRuntime.tabs
|
|
1563
|
-
? chromeRuntime
|
|
1564
|
-
: null;
|
|
1565
|
-
if (!runtimeChrome) {
|
|
1566
|
-
return {
|
|
1567
|
-
reinjectedTabs: 0,
|
|
1568
|
-
hasRuntime: false,
|
|
1569
|
-
hasChrome: !!chromeRuntime,
|
|
1570
|
-
hasScripting: !!(chromeRuntime && chromeRuntime.scripting),
|
|
1571
|
-
hasTabs: !!(chromeRuntime && chromeRuntime.tabs),
|
|
1572
|
-
entries: payload.length,
|
|
1573
|
-
matches: []
|
|
1574
|
-
};
|
|
1575
|
-
}
|
|
1576
|
-
let reinjectedTabs = 0;
|
|
1577
|
-
const matches = [];
|
|
1578
|
-
for (const entry of payload) {
|
|
1579
|
-
const queriedTabs = await runtimeChrome.tabs.query(
|
|
1580
|
-
entry.matches.length > 0 ? { url: entry.matches } : {}
|
|
1581
|
-
);
|
|
1582
|
-
const matchingTabs = queriedTabs.filter((tab) => {
|
|
1583
|
-
if (!tab || typeof tab.id !== 'number') return false;
|
|
1584
|
-
if (typeof tab.url !== 'string' || !tab.url) return true;
|
|
1585
|
-
return entry.urls.length === 0 || entry.urls.includes(tab.url);
|
|
1586
|
-
});
|
|
1587
|
-
matches.push({
|
|
1588
|
-
index: entry.index,
|
|
1589
|
-
queriedTabs: queriedTabs.length,
|
|
1590
|
-
matchingTabs: matchingTabs.length
|
|
1591
|
-
});
|
|
1592
|
-
for (const tab of matchingTabs) {
|
|
1593
|
-
const target = { tabId: tab.id, allFrames: false };
|
|
1594
|
-
if (entry.cssFile) {
|
|
1595
|
-
try {
|
|
1596
|
-
await runtimeChrome.scripting.insertCSS({
|
|
1597
|
-
target,
|
|
1598
|
-
files: [entry.cssFile]
|
|
1599
|
-
});
|
|
1600
|
-
} catch (error) {}
|
|
1601
|
-
}
|
|
1602
|
-
await runtimeChrome.scripting.executeScript({
|
|
1603
|
-
target,
|
|
1604
|
-
files: [entry.jsFile],
|
|
1605
|
-
world: entry.world === 'main' ? 'MAIN' : 'ISOLATED'
|
|
1606
|
-
});
|
|
1607
|
-
reinjectedTabs += 1;
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
return {
|
|
1611
|
-
reinjectedTabs,
|
|
1612
|
-
hasRuntime: true,
|
|
1613
|
-
entries: payload.length,
|
|
1614
|
-
matches
|
|
1615
|
-
};
|
|
1616
|
-
})())()`, {
|
|
1617
|
-
awaitPromise: true
|
|
1618
|
-
});
|
|
1619
|
-
this.lastRuntimeReinjectionReport = {
|
|
1620
|
-
phase: 'evaluated',
|
|
1621
|
-
targetType: runtimeTarget.targetType,
|
|
1622
|
-
targetUrl: runtimeTarget.targetUrl,
|
|
1623
|
-
result: result && 'object' == typeof result ? JSON.parse(JSON.stringify(result)) : result
|
|
1624
|
-
};
|
|
1625
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(`[CDP] extension-runtime reinjection result: ${JSON.stringify({
|
|
1626
|
-
targetType: runtimeTarget.targetType,
|
|
1627
|
-
targetUrl: runtimeTarget.targetUrl,
|
|
1628
|
-
result
|
|
1629
|
-
})}`);
|
|
1630
|
-
if ('number' == typeof result) return result;
|
|
1631
|
-
if (result && 'object' == typeof result) {
|
|
1632
|
-
const reinjectedTabs = Number(result.reinjectedTabs);
|
|
1633
|
-
return Number.isFinite(reinjectedTabs) ? reinjectedTabs : 0;
|
|
1634
|
-
}
|
|
1635
|
-
return 0;
|
|
1636
|
-
}
|
|
1637
|
-
async reloadPageTarget(sessionId) {
|
|
1638
|
-
if (!this.cdp) return false;
|
|
1639
|
-
try {
|
|
1640
|
-
await this.cdp.sendCommand('Page.reload', {
|
|
1641
|
-
ignoreCache: true
|
|
1642
|
-
}, sessionId);
|
|
1643
|
-
return true;
|
|
1644
|
-
} catch {
|
|
1645
|
-
return false;
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
async replayProgrammaticScripts(changedScriptFiles) {
|
|
1649
|
-
if (!this.cdp) return {
|
|
1650
|
-
replayed: 0
|
|
1651
|
-
};
|
|
1652
|
-
if (!Array.isArray(changedScriptFiles) || 0 === changedScriptFiles.length) return {
|
|
1653
|
-
replayed: 0
|
|
1654
|
-
};
|
|
1655
|
-
const runtimeTarget = await this.attachToExtensionRuntimeTarget();
|
|
1656
|
-
if (!runtimeTarget) return {
|
|
1657
|
-
replayed: 0
|
|
1658
|
-
};
|
|
1659
|
-
const result = await this.cdp.evaluate(runtimeTarget.sessionId, `(() => (async () => {
|
|
1660
|
-
if (typeof globalThis !== "object" || !globalThis) return {ok: false, reason: "no globalThis"};
|
|
1661
|
-
if (typeof globalThis.__extjsScriptsReplay !== "function") {
|
|
1662
|
-
return {ok: false, reason: "shim_missing"};
|
|
1663
|
-
}
|
|
1664
|
-
try {
|
|
1665
|
-
const outcome = await globalThis.__extjsScriptsReplay(${JSON.stringify(changedScriptFiles)});
|
|
1666
|
-
const list = Array.isArray(outcome) ? outcome : [];
|
|
1667
|
-
return {
|
|
1668
|
-
ok: true,
|
|
1669
|
-
replayed: list.filter((entry) => entry && entry.ok).length,
|
|
1670
|
-
failures: list.filter((entry) => entry && entry.ok === false).length
|
|
1671
|
-
};
|
|
1672
|
-
} catch (error) {
|
|
1673
|
-
return {ok: false, reason: "eval_error", message: String((error && error.message) || error)};
|
|
1674
|
-
}
|
|
1675
|
-
})())()`, {
|
|
1676
|
-
awaitPromise: true
|
|
1677
|
-
});
|
|
1678
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) try {
|
|
1679
|
-
console.log(`[CDP] scripts replay result: ${JSON.stringify({
|
|
1680
|
-
changedScriptFiles,
|
|
1681
|
-
result
|
|
1682
|
-
})}`);
|
|
1683
|
-
} catch {}
|
|
1684
|
-
if (result && 'object' == typeof result) {
|
|
1685
|
-
const replayed = Number(result.replayed);
|
|
1686
|
-
return {
|
|
1687
|
-
replayed: Number.isFinite(replayed) ? replayed : 0
|
|
1688
|
-
};
|
|
1689
|
-
}
|
|
1690
|
-
return {
|
|
1691
|
-
replayed: 0
|
|
1692
|
-
};
|
|
1693
|
-
}
|
|
1694
|
-
async hardReload() {
|
|
1695
|
-
if (!this.extensionId) return false;
|
|
1696
|
-
try {
|
|
1697
|
-
if (!this.cdp) await this.connectFreshClient();
|
|
1698
|
-
if (this.cdp && await this.cdp.forceReloadExtension(this.extensionId)) return true;
|
|
1699
|
-
} catch {}
|
|
1700
|
-
try {
|
|
1701
|
-
await this.reconnectForReload();
|
|
1702
|
-
return Boolean(this.cdp && this.extensionId && await this.cdp.forceReloadExtension(this.extensionId));
|
|
1703
|
-
} catch {
|
|
1704
|
-
return false;
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
async attachToExtensionRuntimeTarget() {
|
|
1708
|
-
if (!this.cdp) return;
|
|
1709
|
-
if (!this.extensionId) this.extensionId = await this.deriveExtensionIdFromTargets(10, 150);
|
|
1710
|
-
if (!this.extensionId) return;
|
|
1711
|
-
const extensionOrigin = `chrome-extension://${this.extensionId}/`;
|
|
1712
|
-
for(let attempt = 0; attempt < 20; attempt++){
|
|
1713
|
-
const targets = await this.cdp.getTargets();
|
|
1714
|
-
const runtimeTargets = (targets || []).filter((target)=>{
|
|
1715
|
-
const targetType = String(target?.type || '');
|
|
1716
|
-
const targetId = String(target?.targetId || '');
|
|
1717
|
-
return ('service_worker' === targetType || 'background_page' === targetType || 'worker' === targetType) && !!targetId;
|
|
1718
|
-
});
|
|
1719
|
-
const runtimeTarget = runtimeTargets.find((target)=>String(target?.url || '').startsWith(extensionOrigin)) || runtimeTargets.find((target)=>String(target?.url || '').startsWith('chrome-extension://'));
|
|
1720
|
-
if (runtimeTarget) try {
|
|
1721
|
-
const sessionId = await this.cdp.attachToTarget(String(runtimeTarget.targetId));
|
|
1722
|
-
await this.cdp.sendCommand('Runtime.enable', {}, sessionId);
|
|
1723
|
-
return {
|
|
1724
|
-
sessionId,
|
|
1725
|
-
targetType: String(runtimeTarget?.type || ''),
|
|
1726
|
-
targetUrl: String(runtimeTarget?.url || '')
|
|
1727
|
-
};
|
|
1728
|
-
} catch {}
|
|
1729
|
-
this.extensionId = await this.deriveExtensionIdFromTargets(4, 100) || this.extensionId;
|
|
1730
|
-
await new Promise((resolve)=>setTimeout(resolve, 250));
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
1341
|
async connectFreshClient() {
|
|
1734
1342
|
if (this.pipeIn && this.pipeOut && !this.pipeIn.destroyed) this.cdp = await connectToChromeCdpViaPipe(this.pipeIn, this.pipeOut, this.cdpPort);
|
|
1735
1343
|
else this.cdp = await connectToChromeCdp(this.cdpPort);
|
|
@@ -1748,22 +1356,10 @@ exports.modules = {
|
|
|
1748
1356
|
}
|
|
1749
1357
|
registerAutoEnableLogging(this.cdp, ()=>this.extensionId);
|
|
1750
1358
|
}
|
|
1751
|
-
async reconnectForReload() {
|
|
1752
|
-
try {
|
|
1753
|
-
this.cdp?.disconnect?.();
|
|
1754
|
-
} catch {}
|
|
1755
|
-
this.cdp = null;
|
|
1756
|
-
await this.connectFreshClient();
|
|
1757
|
-
try {
|
|
1758
|
-
const derivedExtensionId = await this.deriveExtensionIdFromTargets(10, 150);
|
|
1759
|
-
if (derivedExtensionId) this.extensionId = derivedExtensionId;
|
|
1760
|
-
} catch {}
|
|
1761
|
-
}
|
|
1762
1359
|
onProtocolEvent(cb) {
|
|
1763
1360
|
if (!this.cdp) throw new Error('CDP not connected');
|
|
1764
|
-
this.cdp.onProtocolEvent((
|
|
1765
|
-
|
|
1766
|
-
cb(evt);
|
|
1361
|
+
this.cdp.onProtocolEvent((message)=>{
|
|
1362
|
+
cb(message);
|
|
1767
1363
|
});
|
|
1768
1364
|
}
|
|
1769
1365
|
clearProtocolEventHandler() {
|
|
@@ -1788,12 +1384,6 @@ exports.modules = {
|
|
|
1788
1384
|
} catch {}
|
|
1789
1385
|
} catch {}
|
|
1790
1386
|
}
|
|
1791
|
-
async enableRuntimeForSession(sessionId) {
|
|
1792
|
-
if (!this.cdp) return;
|
|
1793
|
-
try {
|
|
1794
|
-
await this.cdp.enableRuntimeAndLog(sessionId);
|
|
1795
|
-
} catch {}
|
|
1796
|
-
}
|
|
1797
1387
|
async enableLogging() {
|
|
1798
1388
|
if (!this.cdp) return;
|
|
1799
1389
|
try {
|
|
@@ -1832,8 +1422,12 @@ exports.modules = {
|
|
|
1832
1422
|
if (!this.cdp) return null;
|
|
1833
1423
|
if (!this.extensionId) this.extensionId = await this.deriveExtensionIdFromTargets(6, 150);
|
|
1834
1424
|
if (this.extensionId) {
|
|
1835
|
-
const
|
|
1836
|
-
if (
|
|
1425
|
+
const ownership = this.classifyOwnership(this.extensionId);
|
|
1426
|
+
if ('not_mine' === ownership) this.extensionId = await this.deriveExtensionIdFromTargets(10, 150);
|
|
1427
|
+
else if ('unknown' === ownership && this.profilePath) {
|
|
1428
|
+
const rederived = await this.deriveExtensionIdFromTargets(6, 150);
|
|
1429
|
+
if (rederived && 'not_mine' !== this.classifyOwnership(rederived)) this.extensionId = rederived;
|
|
1430
|
+
}
|
|
1837
1431
|
}
|
|
1838
1432
|
if (!this.extensionId) return null;
|
|
1839
1433
|
let name;
|
|
@@ -1858,257 +1452,8 @@ exports.modules = {
|
|
|
1858
1452
|
return null;
|
|
1859
1453
|
}
|
|
1860
1454
|
}
|
|
1861
|
-
async reinjectContentScriptRule(sessionId, rule, allowCoarseCleanup, sourceOverridesByBundleId) {
|
|
1862
|
-
if (!this.cdp) return false;
|
|
1863
|
-
const bundleId = (0, content_script_contracts.Y)(rule.index);
|
|
1864
|
-
const bundlePath = (0, content_script_targets.nG)(this.outPath, rule.index, 'js');
|
|
1865
|
-
if (!bundlePath || !external_fs_.existsSync(bundlePath)) return false;
|
|
1866
|
-
const sourceOverride = sourceOverridesByBundleId && 'object' == typeof sourceOverridesByBundleId ? sourceOverridesByBundleId[bundleId] : void 0;
|
|
1867
|
-
const source = this.patchReinjectSourceForInvalidatedRuntime('string' == typeof sourceOverride ? sourceOverride : readTextFileCached(bundlePath));
|
|
1868
|
-
const buildTokenMatch = source.match(/__EXTENSIONJS_REINJECT_BUILD_TOKEN\s*=\s*"([^"]+)"/);
|
|
1869
|
-
const proofMatch = source.match(/extjs-chromium-live-content-css-modules:script-primary-\d+/) || source.match(/Live Update Proof [A-Za-z0-9_-]+/);
|
|
1870
|
-
if (!source.trim()) return false;
|
|
1871
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(`[CDP] reinject bundle ${bundleId} from ${bundlePath}${proofMatch ? ` (${proofMatch[0]})` : ''} build=${buildTokenMatch?.[1] || '<none>'} sourceOverride=${'string' == typeof sourceOverride}`);
|
|
1872
|
-
const contextId = await this.resolveExecutionContextId(sessionId, rule);
|
|
1873
|
-
if (!contextId) {
|
|
1874
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(`[CDP] No execution context found for ${bundleId} (${rule.world})`);
|
|
1875
|
-
return false;
|
|
1876
|
-
}
|
|
1877
|
-
const result = await this.cdp.evaluateInContext(sessionId, this.buildReinjectExpression(bundleId, source, allowCoarseCleanup), contextId);
|
|
1878
|
-
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(`[CDP] reinject result ${bundleId}: ${JSON.stringify(result)}`);
|
|
1879
|
-
if (result && 'object' == typeof result && 'ok' in result) return false !== result.ok;
|
|
1880
|
-
return true;
|
|
1881
|
-
}
|
|
1882
|
-
buildReinjectExpression(bundleId, source, allowCoarseCleanup) {
|
|
1883
|
-
const annotatedSource = `${source}\n//# sourceURL=extension.js-reinject://${bundleId}.js`;
|
|
1884
|
-
const extensionBase = this.extensionId ? `chrome-extension://${this.extensionId}/` : '';
|
|
1885
|
-
return `(() => {
|
|
1886
|
-
const bundleId = ${JSON.stringify(bundleId)};
|
|
1887
|
-
const source = ${JSON.stringify(annotatedSource)};
|
|
1888
|
-
const extensionBase = ${JSON.stringify(extensionBase)};
|
|
1889
|
-
const rootSelector = '[data-extension-root], #extension-root';
|
|
1890
|
-
const keyedSelector = '[data-extjs-reinject-key="${bundleId}"]';
|
|
1891
|
-
const registry = (typeof globalThis === 'object' && globalThis)
|
|
1892
|
-
? (globalThis.__EXTENSIONJS_DEV_REINJECT__ || (globalThis.__EXTENSIONJS_DEV_REINJECT__ = {}))
|
|
1893
|
-
: {};
|
|
1894
|
-
const existing = registry[bundleId];
|
|
1895
|
-
const readGeneration = (entry) => {
|
|
1896
|
-
try {
|
|
1897
|
-
if (!entry) return 0;
|
|
1898
|
-
if (typeof entry === 'function' && typeof entry.__extjsGeneration === 'number') {
|
|
1899
|
-
return entry.__extjsGeneration;
|
|
1900
|
-
}
|
|
1901
|
-
if (typeof entry === 'object') {
|
|
1902
|
-
if (typeof entry.__extjsGeneration === 'number') return entry.__extjsGeneration;
|
|
1903
|
-
if (typeof entry.generation === 'number') return entry.generation;
|
|
1904
|
-
if (typeof entry.cleanup === 'function' && typeof entry.cleanup.__extjsGeneration === 'number') {
|
|
1905
|
-
return entry.cleanup.__extjsGeneration;
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
} catch (error) {}
|
|
1909
|
-
return 0;
|
|
1910
|
-
};
|
|
1911
|
-
const previousGeneration = readGeneration(existing);
|
|
1912
|
-
try {
|
|
1913
|
-
if (typeof existing === 'function') existing();
|
|
1914
|
-
if (existing && typeof existing.cleanup === 'function') existing.cleanup();
|
|
1915
|
-
} catch (error) {}
|
|
1916
|
-
if (${allowCoarseCleanup ? 'true' : 'false'}) {
|
|
1917
|
-
// Bundle-scoped sweep: only remove roots owned by this bundleId. The inner
|
|
1918
|
-
// wrapper tags every host with data-extjs-reinject-key on mount, so this
|
|
1919
|
-
// catches roots from a manifest-cached run before the outer cleanup
|
|
1920
|
-
// registry was populated. A broad querySelector('[data-extension-root]')
|
|
1921
|
-
// would destroy roots owned by sibling content_scripts entries that
|
|
1922
|
-
// didn't change — leaving the page with only this bundle's roots.
|
|
1923
|
-
try {
|
|
1924
|
-
const staleKeyed = Array.from(document.querySelectorAll(keyedSelector));
|
|
1925
|
-
for (const root of staleKeyed) {
|
|
1926
|
-
if (root && typeof root.remove === 'function') root.remove();
|
|
1927
|
-
}
|
|
1928
|
-
} catch (error) {}
|
|
1929
|
-
}
|
|
1930
|
-
const trackedNodes = new Set();
|
|
1931
|
-
const trackNode = (node) => {
|
|
1932
|
-
try {
|
|
1933
|
-
if (!node || typeof Element !== 'function' || !(node instanceof Element)) return;
|
|
1934
|
-
const matchesRoot = typeof node.matches === 'function' && node.matches(rootSelector);
|
|
1935
|
-
if (!matchesRoot) return;
|
|
1936
|
-
trackedNodes.add(node);
|
|
1937
|
-
if (typeof node.setAttribute === 'function') {
|
|
1938
|
-
node.setAttribute('data-extjs-reinject-key', bundleId);
|
|
1939
|
-
}
|
|
1940
|
-
} catch (error) {}
|
|
1941
|
-
};
|
|
1942
|
-
const trackTree = (node) => {
|
|
1943
|
-
trackNode(node);
|
|
1944
|
-
try {
|
|
1945
|
-
if (!node || typeof node.querySelectorAll !== 'function') return;
|
|
1946
|
-
const nested = node.querySelectorAll(rootSelector);
|
|
1947
|
-
for (const nestedNode of nested) trackNode(nestedNode);
|
|
1948
|
-
} catch (error) {}
|
|
1949
|
-
};
|
|
1950
|
-
const observer = typeof MutationObserver === 'function'
|
|
1951
|
-
? new MutationObserver((mutations) => {
|
|
1952
|
-
for (const mutation of mutations) {
|
|
1953
|
-
const addedNodes = Array.from(mutation.addedNodes || []);
|
|
1954
|
-
for (const addedNode of addedNodes) {
|
|
1955
|
-
trackTree(addedNode);
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
})
|
|
1959
|
-
: null;
|
|
1960
|
-
try {
|
|
1961
|
-
if (observer && document && document.documentElement) {
|
|
1962
|
-
observer.observe(document.documentElement, {childList: true, subtree: true});
|
|
1963
|
-
}
|
|
1964
|
-
} catch (error) {}
|
|
1965
|
-
const cleanupTrackedNodes = () => {
|
|
1966
|
-
try {
|
|
1967
|
-
if (observer) observer.disconnect();
|
|
1968
|
-
} catch (error) {}
|
|
1969
|
-
try {
|
|
1970
|
-
const keyedNodes = Array.from(document.querySelectorAll(keyedSelector));
|
|
1971
|
-
for (const keyedNode of keyedNodes) {
|
|
1972
|
-
if (keyedNode && typeof keyedNode.remove === 'function') keyedNode.remove();
|
|
1973
|
-
}
|
|
1974
|
-
} catch (error) {}
|
|
1975
|
-
try {
|
|
1976
|
-
for (const trackedNode of trackedNodes) {
|
|
1977
|
-
if (trackedNode && trackedNode.isConnected && typeof trackedNode.remove === 'function') {
|
|
1978
|
-
trackedNode.remove();
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
} catch (error) {}
|
|
1982
|
-
};
|
|
1983
|
-
registry[bundleId] = {
|
|
1984
|
-
cleanup: cleanupTrackedNodes,
|
|
1985
|
-
generation: previousGeneration,
|
|
1986
|
-
__extjsGeneration: previousGeneration
|
|
1987
|
-
};
|
|
1988
|
-
try {
|
|
1989
|
-
if (typeof globalThis === 'object' && globalThis && extensionBase) {
|
|
1990
|
-
globalThis.__EXTJS_EXTENSION_BASE__ = extensionBase;
|
|
1991
|
-
}
|
|
1992
|
-
if (typeof document === 'object' && document && document.documentElement && extensionBase) {
|
|
1993
|
-
document.documentElement.setAttribute('data-extjs-extension-base', extensionBase);
|
|
1994
|
-
}
|
|
1995
|
-
(0, eval)(source);
|
|
1996
|
-
} catch (error) {
|
|
1997
|
-
return {
|
|
1998
|
-
ok: false,
|
|
1999
|
-
error: String((error && error.stack) || (error && error.message) || error || 'unknown'),
|
|
2000
|
-
trackedRoots: trackedNodes.size,
|
|
2001
|
-
existingRootCount: (() => {
|
|
2002
|
-
try { return document.querySelectorAll(rootSelector).length; } catch (innerError) { return -1; }
|
|
2003
|
-
})()
|
|
2004
|
-
};
|
|
2005
|
-
}
|
|
2006
|
-
setTimeout(() => {
|
|
2007
|
-
try {
|
|
2008
|
-
const keyedNodes = Array.from(document.querySelectorAll(keyedSelector));
|
|
2009
|
-
for (const keyedNode of keyedNodes) trackedNodes.add(keyedNode);
|
|
2010
|
-
} catch (error) {}
|
|
2011
|
-
}, 0);
|
|
2012
|
-
setTimeout(() => {
|
|
2013
|
-
try {
|
|
2014
|
-
if (observer) observer.disconnect();
|
|
2015
|
-
} catch (error) {}
|
|
2016
|
-
}, 2000);
|
|
2017
|
-
return {
|
|
2018
|
-
ok: true,
|
|
2019
|
-
trackedRoots: trackedNodes.size,
|
|
2020
|
-
existingRootCount: (() => {
|
|
2021
|
-
try { return document.querySelectorAll(rootSelector).length; } catch (innerError) { return -1; }
|
|
2022
|
-
})(),
|
|
2023
|
-
liveRoots: (() => {
|
|
2024
|
-
try {
|
|
2025
|
-
return Array.from(document.querySelectorAll(rootSelector)).map((node) => ({
|
|
2026
|
-
key: node && typeof node.getAttribute === 'function' ? node.getAttribute('data-extjs-reinject-key') || null : null,
|
|
2027
|
-
root: node && typeof node.getAttribute === 'function' ? node.getAttribute('data-extension-root') || null : null,
|
|
2028
|
-
build: node && typeof node.getAttribute === 'function' ? node.getAttribute('data-extjs-reinject-build') || null : null,
|
|
2029
|
-
text: String(node && node.textContent || '').slice(0, 120)
|
|
2030
|
-
}));
|
|
2031
|
-
} catch (error) {
|
|
2032
|
-
return [];
|
|
2033
|
-
}
|
|
2034
|
-
})(),
|
|
2035
|
-
hasChromeRuntime: (() => {
|
|
2036
|
-
try { return !!(globalThis && globalThis.chrome && globalThis.chrome.runtime); } catch (error) { return false; }
|
|
2037
|
-
})()
|
|
2038
|
-
};
|
|
2039
|
-
})()`;
|
|
2040
|
-
}
|
|
2041
|
-
patchReinjectSourceForInvalidatedRuntime(source) {
|
|
2042
|
-
return source.replace('__webpack_require__.p = __webpack_require__.webExtRt.runtime.getURL("/");', 'try {\n __webpack_require__.p = __webpack_require__.webExtRt.runtime.getURL("/");\n} catch (_extjsRuntimeError) {\n if (__extjsBase) {\n __webpack_require__.p = __extjsBase.replace(/\\/+$/, "/") + String("/").replace(/^\\/+/, "");\n } else {\n __webpack_require__.p = "";\n }\n}');
|
|
2043
|
-
}
|
|
2044
|
-
async resolveExecutionContextId(sessionId, rule) {
|
|
2045
|
-
if (!this.cdp) return;
|
|
2046
|
-
const frameId = await this.getTopFrameId(sessionId);
|
|
2047
|
-
const contexts = await this.collectExecutionContexts(sessionId);
|
|
2048
|
-
if ('main' === rule.world) {
|
|
2049
|
-
const defaultContext = contexts.find((context)=>{
|
|
2050
|
-
const auxData = context?.auxData || {};
|
|
2051
|
-
return 'default' === auxData.type && true === auxData.isDefault && (!frameId || !auxData.frameId || String(auxData.frameId) === frameId);
|
|
2052
|
-
});
|
|
2053
|
-
return 'number' == typeof defaultContext?.id ? defaultContext.id : void 0;
|
|
2054
|
-
}
|
|
2055
|
-
const extensionId = this.extensionId || await this.deriveExtensionIdFromTargets();
|
|
2056
|
-
if (!extensionId) return;
|
|
2057
|
-
const extensionOrigin = `chrome-extension://${extensionId}`;
|
|
2058
|
-
const isolatedContext = contexts.find((context)=>{
|
|
2059
|
-
const auxData = context?.auxData || {};
|
|
2060
|
-
return 'isolated' === auxData.type && String(context?.origin || '') === extensionOrigin && (!frameId || !auxData.frameId || String(auxData.frameId) === frameId);
|
|
2061
|
-
});
|
|
2062
|
-
return 'number' == typeof isolatedContext?.id ? isolatedContext.id : void 0;
|
|
2063
|
-
}
|
|
2064
|
-
async getTopFrameId(sessionId) {
|
|
2065
|
-
if (!this.cdp) return;
|
|
2066
|
-
try {
|
|
2067
|
-
const frameTree = await this.cdp.sendCommand('Page.getFrameTree', {}, sessionId);
|
|
2068
|
-
const frameId = frameTree?.frameTree?.frame?.id;
|
|
2069
|
-
return 'string' == typeof frameId && frameId ? frameId : void 0;
|
|
2070
|
-
} catch {
|
|
2071
|
-
return;
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
async collectExecutionContexts(sessionId) {
|
|
2075
|
-
if (!this.cdp) return [];
|
|
2076
|
-
const cached = this.sessionContexts.get(sessionId);
|
|
2077
|
-
if (cached) return Array.from(cached.values());
|
|
2078
|
-
const contextsById = new Map();
|
|
2079
|
-
this.sessionContexts.set(sessionId, contextsById);
|
|
2080
|
-
const unsubscribe = this.cdp.onProtocolEvent((message)=>{
|
|
2081
|
-
if (String(message.sessionId || '') !== sessionId) return;
|
|
2082
|
-
const method = String(message.method || '');
|
|
2083
|
-
if ('Runtime.executionContextCreated' === method) {
|
|
2084
|
-
const context = message.params?.context;
|
|
2085
|
-
const contextId = context?.id;
|
|
2086
|
-
if ('number' == typeof contextId) contextsById.set(contextId, context);
|
|
2087
|
-
return;
|
|
2088
|
-
}
|
|
2089
|
-
if ('Runtime.executionContextDestroyed' === method) {
|
|
2090
|
-
const params = message.params || {};
|
|
2091
|
-
if ('number' == typeof params.executionContextId) contextsById.delete(params.executionContextId);
|
|
2092
|
-
return;
|
|
2093
|
-
}
|
|
2094
|
-
if ('Runtime.executionContextsCleared' === method) contextsById.clear();
|
|
2095
|
-
});
|
|
2096
|
-
this.sessionContextsUnsubscribe.set(sessionId, unsubscribe);
|
|
2097
|
-
await this.cdp.sendCommand('Runtime.enable', {}, sessionId);
|
|
2098
|
-
await new Promise((resolve)=>setTimeout(resolve, 100));
|
|
2099
|
-
return Array.from(contextsById.values());
|
|
2100
|
-
}
|
|
2101
|
-
releaseSessionContexts(sessionId) {
|
|
2102
|
-
const unsubscribe = this.sessionContextsUnsubscribe.get(sessionId);
|
|
2103
|
-
if (unsubscribe) try {
|
|
2104
|
-
unsubscribe();
|
|
2105
|
-
} catch {}
|
|
2106
|
-
this.sessionContextsUnsubscribe.delete(sessionId);
|
|
2107
|
-
this.sessionContexts.delete(sessionId);
|
|
2108
|
-
}
|
|
2109
1455
|
constructor(args){
|
|
2110
1456
|
cdp_extension_controller_define_property(this, "outPath", void 0);
|
|
2111
|
-
cdp_extension_controller_define_property(this, "browser", void 0);
|
|
2112
1457
|
cdp_extension_controller_define_property(this, "cdpPort", void 0);
|
|
2113
1458
|
cdp_extension_controller_define_property(this, "profilePath", void 0);
|
|
2114
1459
|
cdp_extension_controller_define_property(this, "extensionPaths", void 0);
|
|
@@ -2116,15 +1461,7 @@ exports.modules = {
|
|
|
2116
1461
|
cdp_extension_controller_define_property(this, "pipeOut", void 0);
|
|
2117
1462
|
cdp_extension_controller_define_property(this, "cdp", null);
|
|
2118
1463
|
cdp_extension_controller_define_property(this, "extensionId", null);
|
|
2119
|
-
cdp_extension_controller_define_property(this, "lastRuntimeReinjectionReport", null);
|
|
2120
|
-
cdp_extension_controller_define_property(this, "activeContentScriptRules", []);
|
|
2121
|
-
cdp_extension_controller_define_property(this, "contentScriptTargetListenerInstalled", false);
|
|
2122
|
-
cdp_extension_controller_define_property(this, "watchedPageSessions", new Map());
|
|
2123
|
-
cdp_extension_controller_define_property(this, "sessionContexts", new Map());
|
|
2124
|
-
cdp_extension_controller_define_property(this, "sessionContextsUnsubscribe", new Map());
|
|
2125
|
-
cdp_extension_controller_define_property(this, "suppressInitialContextBurst", new Set());
|
|
2126
1464
|
this.outPath = args.outPath;
|
|
2127
|
-
this.browser = args.browser;
|
|
2128
1465
|
this.cdpPort = args.cdpPort;
|
|
2129
1466
|
this.profilePath = args.profilePath;
|
|
2130
1467
|
this.extensionPaths = args.extensionPaths;
|
|
@@ -2261,10 +1598,6 @@ exports.modules = {
|
|
|
2261
1598
|
}
|
|
2262
1599
|
},
|
|
2263
1600
|
"./browsers/run-chromium/chromium-source-inspection/cdp-extension-controller/ensure.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
2264
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
2265
|
-
M: ()=>readManifestInfo,
|
|
2266
|
-
loadUnpackedIfNeeded: ()=>loadUnpackedIfNeeded
|
|
2267
|
-
});
|
|
2268
1601
|
var fs__rspack_import_0 = __webpack_require__("fs");
|
|
2269
1602
|
var path__rspack_import_1 = __webpack_require__("path");
|
|
2270
1603
|
async function loadUnpackedIfNeeded(cdp, outPath) {
|
|
@@ -2293,5 +1626,9 @@ exports.modules = {
|
|
|
2293
1626
|
return null;
|
|
2294
1627
|
}
|
|
2295
1628
|
}
|
|
1629
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1630
|
+
M: ()=>readManifestInfo,
|
|
1631
|
+
loadUnpackedIfNeeded: ()=>loadUnpackedIfNeeded
|
|
1632
|
+
});
|
|
2296
1633
|
}
|
|
2297
1634
|
};
|