extension-develop 4.0.26 → 4.0.27
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 +5 -1
- package/dist/0~dev-server.mjs +5 -5
- package/dist/0~rspack-config.mjs +298 -139
- package/dist/101.mjs +1099 -972
- package/dist/494.mjs +12 -1
- package/dist/839.mjs +105 -25
- package/dist/command-preview.d.ts +7 -0
- package/dist/dev-server/control-bridge/producer-runtime.d.ts +2 -1
- package/dist/feature-scripts-content-script-wrapper.js +2 -1
- package/dist/feature-scripts-content-script-wrapper.mjs +2 -1
- package/dist/lib/atomic-dist.d.ts +5 -0
- package/dist/lib/config-loader.d.ts +12 -12
- package/dist/lib/constants.d.ts +2 -0
- package/dist/lib/merge-options.d.ts +67 -0
- package/dist/lib/paths.d.ts +1 -1
- package/dist/lib/session-paths.d.ts +1 -0
- package/dist/plugin-compilation/boring.d.ts +1 -0
- package/dist/plugin-compilation/zip.d.ts +2 -0
- package/dist/plugin-playwright/index.d.ts +2 -0
- package/dist/plugin-web-extension/feature-html/html-lib/utils.d.ts +2 -1
- package/dist/plugin-web-extension/feature-json/messages.d.ts +2 -0
- package/dist/plugin-web-extension/feature-manifest/messages.d.ts +1 -0
- package/dist/plugin-web-extension/feature-web-resources/collect-entry-imports.d.ts +1 -0
- package/dist/types.d.ts +24 -3
- package/package.json +1 -1
package/dist/494.mjs
CHANGED
|
@@ -33,6 +33,17 @@ function ensureSessionArtifactsIgnoreFile(projectPath) {
|
|
|
33
33
|
__rspack_external_node_fs_5ea92f0c.writeFileSync(ignoreFile, SESSION_ARTIFACTS_IGNORE_CONTENT);
|
|
34
34
|
} catch {}
|
|
35
35
|
}
|
|
36
|
+
function ensureSessionStateInProjectGitignore(projectPath) {
|
|
37
|
+
try {
|
|
38
|
+
const gitignorePath = __rspack_external_node_path_c5b9b54f.resolve(projectPath, '.gitignore');
|
|
39
|
+
if (!__rspack_external_node_fs_5ea92f0c.existsSync(gitignorePath)) return;
|
|
40
|
+
const content = __rspack_external_node_fs_5ea92f0c.readFileSync(gitignorePath, 'utf8');
|
|
41
|
+
const lines = content.split(/\r?\n/).map((line)=>line.trim());
|
|
42
|
+
if (lines.includes('.extension-js') || lines.includes('.extension-js/')) return;
|
|
43
|
+
const prefix = content.length > 0 && !content.endsWith('\n') ? '\n' : '';
|
|
44
|
+
__rspack_external_node_fs_5ea92f0c.appendFileSync(gitignorePath, `${prefix}\n# extension.js local session state\n.extension-js\n`);
|
|
45
|
+
} catch {}
|
|
46
|
+
}
|
|
36
47
|
function browserArtifactsDir(projectPath, browser) {
|
|
37
48
|
return __rspack_external_node_path_c5b9b54f.join(sessionArtifactsRootDir(projectPath), browser);
|
|
38
49
|
}
|
|
@@ -57,4 +68,4 @@ function actionsPath(projectPath, browser) {
|
|
|
57
68
|
function buildSummaryPath(projectPath, browser) {
|
|
58
69
|
return __rspack_external_node_path_c5b9b54f.join(browserArtifactsDir(projectPath, browser), 'build-summary.json');
|
|
59
70
|
}
|
|
60
|
-
export { actionsPath, browserArtifactsDir, browserDistDir, browserProfileRootDir, buildSummaryPath, controlPortFilePath, controlTokenPath, ensureSessionArtifactsIgnoreFile, eventsPath, legacyControlPortFilePath, legacyControlTokenPath, logsPath, readyContractPath, sessionArtifactsRootDir, sessionStateDir };
|
|
71
|
+
export { actionsPath, browserArtifactsDir, browserDistDir, browserProfileRootDir, buildSummaryPath, controlPortFilePath, controlTokenPath, ensureSessionArtifactsIgnoreFile, ensureSessionStateInProjectGitignore, eventsPath, legacyControlPortFilePath, legacyControlTokenPath, logsPath, readyContractPath, sessionArtifactsRootDir, sessionStateDir };
|
package/dist/839.mjs
CHANGED
|
@@ -5,10 +5,10 @@ import { buildExecEnv, detectPackageManagerFromLockfile } from "prefers-yarn";
|
|
|
5
5
|
import "pintor";
|
|
6
6
|
import { EventEmitter } from "node:events";
|
|
7
7
|
import { browserRowValue, ENVELOPE, CODES, prefix as messaging_prefix, card, isDebug, claimCardKey, isMachineOutput } from "./349.mjs";
|
|
8
|
-
import { package_namespaceObject, buildWarningsDetails,
|
|
8
|
+
import { package_namespaceObject, buildWarningsDetails, DEV_COMMAND_DEFAULTS, buildFailed, getDirs, stampReadyDistExtensionId, zipArtifactReady, stampReadyKnownExtensionId, projectInstallFallbackToNpm, assertNoManagedDependencyConflicts, debugDirs, browserLaunchFailed, START_BUILD_DEFAULTS, extensionLoadRecovered, extensionLoadStillRefused, writingTypeDefinitionsError, projectInstallScriptsDisabled, authorInstallNotice, getSpecialFoldersDataForProjectRoot, buildAssetsTree, loadCommandConfig, needsInstall, mergeOptionLayers, buildCommandFailed, writingTypeDefinitions, buildComplete, normalizeBrowser, debugBrowser, debugOutputPath, loadCustomConfig, devCommandFailed, getProjectStructure, getDistPath, resolveCompanionExtensionsConfig, buildShareHint, loadBrowserConfig, BUILD_COMMAND_DEFAULTS } from "./101.mjs";
|
|
9
9
|
import { stripBom, parseJsonSafe } from "./23.mjs";
|
|
10
10
|
import { hasProjectDependency, findNearestProjectManifestDirSync } from "./80.mjs";
|
|
11
|
-
import { buildSummaryPath, ensureSessionArtifactsIgnoreFile } from "./494.mjs";
|
|
11
|
+
import { buildSummaryPath, ensureSessionArtifactsIgnoreFile, ensureSessionStateInProjectGitignore } from "./494.mjs";
|
|
12
12
|
import { getCanonicalContentScriptEntryName } from "./291.mjs";
|
|
13
13
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
14
14
|
import { dirname as __rspack_dirname } from "node:path";
|
|
@@ -257,6 +257,64 @@ function attachLifecycleStream(compiler, stream) {
|
|
|
257
257
|
} catch {}
|
|
258
258
|
});
|
|
259
259
|
}
|
|
260
|
+
const DIST_STAGING_PREFIX = '.extension-build-';
|
|
261
|
+
function stagingDistPathFor(distPath) {
|
|
262
|
+
const unique = `${process.pid.toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
263
|
+
return __rspack_external_node_path_c5b9b54f.join(__rspack_external_node_path_c5b9b54f.dirname(distPath), `${DIST_STAGING_PREFIX}${__rspack_external_node_path_c5b9b54f.basename(distPath)}-${unique}`);
|
|
264
|
+
}
|
|
265
|
+
function removeStaleStagingDirs(distPath) {
|
|
266
|
+
const parent = __rspack_external_node_path_c5b9b54f.dirname(distPath);
|
|
267
|
+
const prefix = `${DIST_STAGING_PREFIX}${__rspack_external_node_path_c5b9b54f.basename(distPath)}-`;
|
|
268
|
+
let entries;
|
|
269
|
+
try {
|
|
270
|
+
entries = __rspack_external_node_fs_5ea92f0c.readdirSync(parent, {
|
|
271
|
+
withFileTypes: true
|
|
272
|
+
});
|
|
273
|
+
} catch {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
for (const entry of entries)try {
|
|
277
|
+
if (!entry.isDirectory() || !entry.name.startsWith(prefix)) continue;
|
|
278
|
+
__rspack_external_node_fs_5ea92f0c.rmSync(__rspack_external_node_path_c5b9b54f.join(parent, entry.name), {
|
|
279
|
+
recursive: true,
|
|
280
|
+
force: true
|
|
281
|
+
});
|
|
282
|
+
} catch {}
|
|
283
|
+
}
|
|
284
|
+
function removeStagingDir(stagingPath) {
|
|
285
|
+
try {
|
|
286
|
+
__rspack_external_node_fs_5ea92f0c.rmSync(stagingPath, {
|
|
287
|
+
recursive: true,
|
|
288
|
+
force: true
|
|
289
|
+
});
|
|
290
|
+
} catch {}
|
|
291
|
+
}
|
|
292
|
+
function promoteStagingDist(stagingPath, distPath) {
|
|
293
|
+
const parent = __rspack_external_node_path_c5b9b54f.dirname(distPath);
|
|
294
|
+
__rspack_external_node_fs_5ea92f0c.mkdirSync(parent, {
|
|
295
|
+
recursive: true
|
|
296
|
+
});
|
|
297
|
+
const retiredPath = `${stagingPath}-retired`;
|
|
298
|
+
let retired = false;
|
|
299
|
+
if (__rspack_external_node_fs_5ea92f0c.existsSync(distPath)) {
|
|
300
|
+
__rspack_external_node_fs_5ea92f0c.renameSync(distPath, retiredPath);
|
|
301
|
+
retired = true;
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
__rspack_external_node_fs_5ea92f0c.renameSync(stagingPath, distPath);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (retired) try {
|
|
307
|
+
__rspack_external_node_fs_5ea92f0c.renameSync(retiredPath, distPath);
|
|
308
|
+
} catch {}
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
if (retired) try {
|
|
312
|
+
__rspack_external_node_fs_5ea92f0c.rmSync(retiredPath, {
|
|
313
|
+
recursive: true,
|
|
314
|
+
force: true
|
|
315
|
+
});
|
|
316
|
+
} catch {}
|
|
317
|
+
}
|
|
260
318
|
const MAX_SUMMARY_WARNINGS = 20;
|
|
261
319
|
const build_summary_ANSI_PATTERN = /\u001b\[[0-9;]*m/g;
|
|
262
320
|
function getBuildSummary(browser, info, outputPath) {
|
|
@@ -976,9 +1034,10 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
|
|
|
976
1034
|
const projectStructure = await getProjectStructure(pathOrRemoteUrl);
|
|
977
1035
|
const isVitest = 'true' === process.env.VITEST;
|
|
978
1036
|
const shouldExitOnError = (buildOptions?.exitOnError ?? false) && !isVitest;
|
|
979
|
-
const browser = normalizeBrowser(buildOptions?.browser || 'chrome', buildOptions?.chromiumBinary, buildOptions?.geckoBinary || buildOptions?.firefoxBinary);
|
|
1037
|
+
const browser = normalizeBrowser(buildOptions?.browser || 'chrome', buildOptions?.chromiumBinary, buildOptions?.geckoBinary || buildOptions?.firefoxBinary, buildOptions?.safariBinary);
|
|
980
1038
|
const { manifestDir, packageJsonDir } = getDirs(projectStructure);
|
|
981
1039
|
const distPath = getDistPath(packageJsonDir, browser);
|
|
1040
|
+
const stagingDistPath = stagingDistPathFor(distPath);
|
|
982
1041
|
const isAuthor = isDebug();
|
|
983
1042
|
try {
|
|
984
1043
|
await ensureDevelopArtifacts();
|
|
@@ -994,14 +1053,12 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
|
|
|
994
1053
|
const debug = isAuthor;
|
|
995
1054
|
const userManifestPath = projectStructure.packageJsonPath || projectStructure.denoJsonPath;
|
|
996
1055
|
if (userManifestPath) assertNoManagedDependencyConflicts(userManifestPath, manifestDir);
|
|
997
|
-
const
|
|
1056
|
+
const commandKey = buildOptions?.metadataCommand === 'start' ? 'start' : 'build';
|
|
1057
|
+
const commandConfig = await loadCommandConfig(packageJsonDir, commandKey);
|
|
998
1058
|
const specialFoldersData = getSpecialFoldersDataForProjectRoot(packageJsonDir);
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
force: true
|
|
1003
|
-
});
|
|
1004
|
-
} catch {}
|
|
1059
|
+
const mergedBuildOptions = mergeOptionLayers('start' === commandKey ? START_BUILD_DEFAULTS : BUILD_COMMAND_DEFAULTS, commandConfig, buildOptions);
|
|
1060
|
+
const silent = Boolean(mergedBuildOptions.silent);
|
|
1061
|
+
removeStaleStagingDirs(distPath);
|
|
1005
1062
|
if (debug) {
|
|
1006
1063
|
console.log(debugDirs(manifestDir, packageJsonDir));
|
|
1007
1064
|
console.log(debugBrowser(browser, buildOptions?.chromiumBinary, buildOptions?.geckoBinary || buildOptions?.firefoxBinary));
|
|
@@ -1016,15 +1073,15 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
|
|
|
1016
1073
|
const resolvedMode = buildOptions?.mode === 'development' || buildOptions?.mode === 'none' || buildOptions?.mode === 'production' ? buildOptions.mode : 'production';
|
|
1017
1074
|
if ('development' === resolvedMode || 'production' === resolvedMode) process.env.NODE_ENV = resolvedMode;
|
|
1018
1075
|
const baseConfig = webpackConfig(projectStructure, {
|
|
1019
|
-
...
|
|
1020
|
-
...buildOptions,
|
|
1076
|
+
...mergedBuildOptions,
|
|
1021
1077
|
extensions: resolvedExtensionsConfig,
|
|
1022
1078
|
browser,
|
|
1023
1079
|
mode: resolvedMode,
|
|
1024
1080
|
metadataCommand: buildOptions?.metadataCommand || 'build',
|
|
1025
1081
|
output: {
|
|
1026
|
-
clean:
|
|
1027
|
-
path:
|
|
1082
|
+
clean: false,
|
|
1083
|
+
path: stagingDistPath,
|
|
1084
|
+
finalPath: distPath
|
|
1028
1085
|
}
|
|
1029
1086
|
});
|
|
1030
1087
|
const allPluginsButBrowserRunners = baseConfig.plugins?.filter((plugin)=>plugin?.constructor.name !== 'plugin-browsers');
|
|
@@ -1035,6 +1092,14 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
|
|
|
1035
1092
|
});
|
|
1036
1093
|
const compilerConfig = merge(userConfig);
|
|
1037
1094
|
compilerConfig.stats = false;
|
|
1095
|
+
const mergedOutputPath = 'string' == typeof compilerConfig.output?.path ? __rspack_external_node_path_c5b9b54f.resolve(compilerConfig.output.path) : '';
|
|
1096
|
+
const useStagingSwap = mergedOutputPath === __rspack_external_node_path_c5b9b54f.resolve(stagingDistPath);
|
|
1097
|
+
if (!useStagingSwap && mergedOutputPath) try {
|
|
1098
|
+
__rspack_external_node_fs_5ea92f0c.rmSync(mergedOutputPath, {
|
|
1099
|
+
recursive: true,
|
|
1100
|
+
force: true
|
|
1101
|
+
});
|
|
1102
|
+
} catch {}
|
|
1038
1103
|
const compiler = rspack(compilerConfig);
|
|
1039
1104
|
let summary = {
|
|
1040
1105
|
browser,
|
|
@@ -1049,17 +1114,22 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
|
|
|
1049
1114
|
compiler.run(async (err, stats)=>{
|
|
1050
1115
|
if (err) {
|
|
1051
1116
|
console.error(err.stack || err);
|
|
1117
|
+
removeStagingDir(stagingDistPath);
|
|
1052
1118
|
return reject(err);
|
|
1053
1119
|
}
|
|
1054
|
-
if (!stats || 'function' != typeof stats.hasErrors)
|
|
1120
|
+
if (!stats || 'function' != typeof stats.hasErrors) {
|
|
1121
|
+
removeStagingDir(stagingDistPath);
|
|
1122
|
+
return reject(new Error('Build failed: bundler returned invalid stats output (no reliable compilation result).'));
|
|
1123
|
+
}
|
|
1055
1124
|
try {
|
|
1056
1125
|
printBuildCard(projectStructure.manifestPath, browser, distPath);
|
|
1057
|
-
if (!
|
|
1126
|
+
if (!silent) {
|
|
1058
1127
|
const assetsTree = buildAssetsTree(stats);
|
|
1059
1128
|
if (assetsTree) humanLine(assetsTree);
|
|
1060
1129
|
}
|
|
1061
1130
|
} catch {}
|
|
1062
1131
|
if (stats.hasErrors()) {
|
|
1132
|
+
removeStagingDir(stagingDistPath);
|
|
1063
1133
|
handleStatsErrors(stats);
|
|
1064
1134
|
let errorCount = 1;
|
|
1065
1135
|
try {
|
|
@@ -1077,6 +1147,15 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
|
|
|
1077
1147
|
}
|
|
1078
1148
|
process.exit(1);
|
|
1079
1149
|
} else {
|
|
1150
|
+
if (useStagingSwap && __rspack_external_node_fs_5ea92f0c.existsSync(stagingDistPath)) {
|
|
1151
|
+
try {
|
|
1152
|
+
promoteStagingDist(stagingDistPath, distPath);
|
|
1153
|
+
} catch (promoteError) {
|
|
1154
|
+
removeStagingDir(stagingDistPath);
|
|
1155
|
+
return reject(promoteError);
|
|
1156
|
+
}
|
|
1157
|
+
stampReadyDistExtensionId(packageJsonDir, browser, distPath);
|
|
1158
|
+
}
|
|
1080
1159
|
const info = stats?.toJson({
|
|
1081
1160
|
all: false,
|
|
1082
1161
|
assets: true,
|
|
@@ -1090,6 +1169,7 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
|
|
|
1090
1169
|
recursive: true
|
|
1091
1170
|
});
|
|
1092
1171
|
ensureSessionArtifactsIgnoreFile(packageJsonDir);
|
|
1172
|
+
ensureSessionStateInProjectGitignore(packageJsonDir);
|
|
1093
1173
|
__rspack_external_node_fs_5ea92f0c.writeFileSync(summaryFile, JSON.stringify(summary));
|
|
1094
1174
|
} catch {}
|
|
1095
1175
|
if (summary.warnings_count > 0) {
|
|
@@ -1099,7 +1179,8 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
|
|
|
1099
1179
|
const distDisplay = relativeToCwd(distPath) || collapseHomeDir(distPath);
|
|
1100
1180
|
humanLine(buildComplete(browser, distDisplay, summary.total_bytes));
|
|
1101
1181
|
for (const artifact of getZipArtifacts(stats.compilation)){
|
|
1102
|
-
const
|
|
1182
|
+
const artifactPath = useStagingSwap && artifact.path.startsWith(stagingDistPath) ? distPath + artifact.path.slice(stagingDistPath.length) : artifact.path;
|
|
1183
|
+
const zipDisplay = relativeToCwd(artifactPath) || artifactPath;
|
|
1103
1184
|
humanLine(zipArtifactReady(zipDisplay, artifact.size));
|
|
1104
1185
|
}
|
|
1105
1186
|
humanLine(buildShareHint());
|
|
@@ -1124,10 +1205,12 @@ async function extensionBuild(pathOrRemoteUrl, buildOptions) {
|
|
|
1124
1205
|
try {
|
|
1125
1206
|
__rspack_external_node_fs_5ea92f0c.writeFileSync(buildSummaryPath(packageJsonDir, browser), JSON.stringify(summary));
|
|
1126
1207
|
} catch {}
|
|
1208
|
+
if (safari.bundleId) stampReadyKnownExtensionId(packageJsonDir, browser, `${safari.bundleId}.Extension`);
|
|
1127
1209
|
}
|
|
1128
1210
|
}
|
|
1129
1211
|
return summary;
|
|
1130
1212
|
} catch (error) {
|
|
1213
|
+
removeStagingDir(stagingDistPath);
|
|
1131
1214
|
const alreadyReported = error instanceof Error && reportedBuildFailures.has(error);
|
|
1132
1215
|
if (!alreadyReported) {
|
|
1133
1216
|
if (isDebug()) console.error(error);
|
|
@@ -1586,7 +1669,7 @@ async function extensionDev(pathOrRemoteUrl, devOptions) {
|
|
|
1586
1669
|
if (isUsingTypeScript(manifestDir)) await generateExtensionTypes(manifestDir, packageJsonDir);
|
|
1587
1670
|
const userManifestPath = projectStructure.packageJsonPath || projectStructure.denoJsonPath;
|
|
1588
1671
|
if (userManifestPath) assertNoManagedDependencyConflicts(userManifestPath, manifestDir);
|
|
1589
|
-
const browser = normalizeBrowser(devOptions.browser || 'chrome', devOptions.chromiumBinary, devOptions.geckoBinary || devOptions.firefoxBinary);
|
|
1672
|
+
const browser = normalizeBrowser(devOptions.browser || 'chrome', devOptions.chromiumBinary, devOptions.geckoBinary || devOptions.firefoxBinary, devOptions.safariBinary);
|
|
1590
1673
|
const geckoBinary = devOptions.geckoBinary || devOptions.firefoxBinary;
|
|
1591
1674
|
if (debug) {
|
|
1592
1675
|
console.log(debugDirs(manifestDir, packageJsonDir));
|
|
@@ -1594,11 +1677,7 @@ async function extensionDev(pathOrRemoteUrl, devOptions) {
|
|
|
1594
1677
|
}
|
|
1595
1678
|
const browserConfig = await loadBrowserConfig(packageJsonDir, browser);
|
|
1596
1679
|
const commandConfig = await loadCommandConfig(packageJsonDir, 'dev');
|
|
1597
|
-
const merged =
|
|
1598
|
-
...sanitize(browserConfig),
|
|
1599
|
-
...sanitize(commandConfig),
|
|
1600
|
-
...sanitize(devOptions)
|
|
1601
|
-
};
|
|
1680
|
+
const merged = mergeOptionLayers(DEV_COMMAND_DEFAULTS, browserConfig, commandConfig, devOptions);
|
|
1602
1681
|
if (('safari' === browser || 'webkit-based' === browser) && !devOptions.noBrowser && devOptions.safariPackager) {
|
|
1603
1682
|
const safariPackager = devOptions.safariPackager;
|
|
1604
1683
|
const safariOverrides = {
|
|
@@ -1606,7 +1685,8 @@ async function extensionDev(pathOrRemoteUrl, devOptions) {
|
|
|
1606
1685
|
bundleId: merged.bundleId,
|
|
1607
1686
|
macOsOnly: merged.macOsOnly,
|
|
1608
1687
|
forceRegenerate: merged.forceRegenerate,
|
|
1609
|
-
safariBinary: merged.safariBinary
|
|
1688
|
+
safariBinary: merged.safariBinary,
|
|
1689
|
+
noOpen: merged.noOpen
|
|
1610
1690
|
};
|
|
1611
1691
|
browsersPlugin = new SafariDevPlugin((distPath, packagerMode)=>safariPackager(distPath, packagerMode, safariOverrides));
|
|
1612
1692
|
emitter = browsersPlugin.emitter;
|
|
@@ -1643,7 +1723,7 @@ async function extensionDev(pathOrRemoteUrl, devOptions) {
|
|
|
1643
1723
|
if ('true' === process.env.EXTENSION_DEV_DRY_RUN) return emitter;
|
|
1644
1724
|
const { devServer } = await import("./0~dev-server.mjs");
|
|
1645
1725
|
await devServer(projectStructure, {
|
|
1646
|
-
...
|
|
1726
|
+
...merged,
|
|
1647
1727
|
mode: 'development',
|
|
1648
1728
|
browser,
|
|
1649
1729
|
geckoBinary,
|
|
@@ -21,6 +21,13 @@ export interface ResolvedPreviewOptions {
|
|
|
21
21
|
instanceId?: string;
|
|
22
22
|
port?: number | string;
|
|
23
23
|
dryRun?: boolean;
|
|
24
|
+
logLevel?: string;
|
|
25
|
+
logContexts?: string[];
|
|
26
|
+
logFormat?: 'pretty' | 'json' | 'ndjson';
|
|
27
|
+
logTimestamps?: boolean;
|
|
28
|
+
logColor?: boolean;
|
|
29
|
+
logUrl?: string;
|
|
30
|
+
logTab?: number | string;
|
|
24
31
|
}
|
|
25
32
|
/**
|
|
26
33
|
* Browser launcher callback. When provided, extensionPreview calls it
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare const BRIDGE_PRODUCER_SOURCE = ";(function () {\n try {\n var g = (typeof globalThis === \"object\" && globalThis) ? globalThis : this;\n if (!g || g.__extjsBridgeProducerInstalled) return;\n\n var PORT = parseInt(\"__EXTJS_CONTROL_PORT__\", 10);\n var INSTANCE_ID = \"__EXTJS_INSTANCE_ID__\";\n var CONTEXT = \"__EXTJS_CONTEXT__\";\n // Connectable host of the dev-server control WS. Baked from the resolved\n // connectable host (loopback locally; the public host for remote/devcontainer).\n var HOST = \"__EXTJS_CONTROL_HOST__\";\n if (!HOST || HOST.indexOf(\"__EXTJS\") === 0) HOST = \"127.0.0.1\";\n if (!PORT || PORT < 1) return;\n\n var WS = g.WebSocket;\n if (typeof WS !== \"function\") return;\n\n var consoleRef = g.console || {};\n g.__extjsBridgeProducerInstalled = true;\n\n // Capture extension event listeners at install time: these wraps run\n // BEFORE user code, and no platform API exists to dispatch these events.\n function captureEvent(event, sink) {\n try {\n if (!event || typeof event.addListener !== \"function\") return;\n var origAdd = event.addListener.bind(event);\n event.addListener = function (cb) {\n if (typeof cb === \"function\" && sink.indexOf(cb) === -1) sink.push(cb);\n return origAdd(cb);\n };\n if (typeof event.removeListener === \"function\") {\n var origRemove = event.removeListener.bind(event);\n event.removeListener = function (cb) {\n var i = sink.indexOf(cb);\n if (i !== -1) sink.splice(i, 1);\n return origRemove(cb);\n };\n }\n } catch (e) { /* non-fatal: trigger falls back to its no-listener reply */ }\n }\n\n // Use g.chrome (not the hoisted chrome var below). This runs first.\n var actionClickedListeners = [];\n var commandListeners = [];\n if (g.chrome) {\n captureEvent(g.chrome.action && g.chrome.action.onClicked, actionClickedListeners);\n captureEvent(g.chrome.commands && g.chrome.commands.onCommand, commandListeners);\n }\n\n var LEVELS = [\"log\", \"info\", \"warn\", \"error\", \"debug\", \"trace\"];\n var socket = null;\n var open = false;\n var queue = [];\n var backoff = 250;\n var MAX_BACKOFF = 5000;\n var MAX_QUEUE = 1000;\n var MAX_RESULT_BYTES = 256 * 1024;\n\n function nowId() {\n return Date.now().toString(36) + Math.random().toString(36).slice(2, 8);\n }\n\n function engineName() {\n try {\n return (typeof navigator !== \"undefined\" && /firefox/i.test(navigator.userAgent)) ? \"firefox\" : \"chromium\";\n } catch (e) { return \"chromium\"; }\n }\n\n function safeValue(v) {\n try {\n var s = JSON.stringify(v);\n if (s === undefined) return {value: undefined, truncated: false};\n if (s.length > MAX_RESULT_BYTES) {\n return {value: {__type: \"truncated\", preview: s.slice(0, 1024)}, truncated: true};\n }\n return {value: JSON.parse(s), truncated: false};\n } catch (e) {\n return {value: {__type: \"unserializable\", preview: String(v).slice(0, 512)}, truncated: false};\n }\n }\n\n function replyOk(cmdId, value) {\n var s = safeValue(value);\n var frame = {type: \"result\", cmdId: cmdId, ok: true, value: s.value};\n if (s.truncated) frame.truncated = true;\n try { socket && socket.send(JSON.stringify(frame)); } catch (e) {\n // Ignore\n }\n }\n\n function replyErr(cmdId, name, message, code) {\n var frame = {type: \"result\", cmdId: cmdId, ok: false, error: {name: name, message: String(message), engine: engineName()}};\n if (code) frame.error.code = code;\n try { socket && socket.send(JSON.stringify(frame)); } catch (e) {\n // Ignore\n }\n }\n\n // Name the refusal the browser wrote as prose, so a consumer branches on\n // error.code instead of matching the engine's sentence.\n function openRefusalCode(message) {\n var m = String(message == null ? \"\" : message);\n if (/user gesture|user input|user interaction|user action/i.test(m)) return \"needs_user_gesture\";\n if (/browser window|active window/i.test(m)) return \"needs_headed_window\";\n return undefined;\n }\n\n // Resolve a numeric tab id when the caller did not pass one: match\n // target.url against open tabs, else default to the active tab. (#51)\n function resolveTargetTab(target, cb) {\n var chrome = g.chrome;\n if (!chrome || !chrome.tabs) { cb(null, \"chrome.tabs is not available\"); return; }\n var url = target && target.url;\n if (url) {\n var substringMatch = function () {\n try {\n chrome.tabs.query({}, function (all) {\n var hit = (all || []).filter(function (t) { return t.url && String(t.url).indexOf(url) !== -1; })[0];\n if (hit && typeof hit.id === \"number\") { cb(hit.id, null); return; }\n cb(null, \"no open tab matches url: \" + url);\n });\n } catch (e2) { cb(null, \"tab query failed\"); }\n };\n try {\n // chrome.tabs.query accepts URL match patterns; a bare url/glob may\n // not be a valid pattern, so fall back to a substring scan.\n chrome.tabs.query({url: url}, function (tabs) {\n if (chrome.runtime && chrome.runtime.lastError) { substringMatch(); return; }\n if (tabs && tabs.length && typeof tabs[0].id === \"number\") { cb(tabs[0].id, null); return; }\n substringMatch();\n });\n } catch (e) { substringMatch(); }\n return;\n }\n try {\n chrome.tabs.query({active: true, lastFocusedWindow: true}, function (tabs) {\n var t = tabs && tabs[0];\n if (t && typeof t.id === \"number\") { cb(t.id, null); return; }\n cb(null, \"no active tab to target\");\n });\n } catch (e3) { cb(null, \"tab query failed\"); }\n }\n\n // chrome.* async APIs are callback-only on Gecko. Prefer promisified\n // browser.* when present, else the chrome.* callback form. cb(err, result).\n function nsCall(nsName, method, callArgs, cb) {\n var chromeG = g.chrome;\n var done = false;\n var once = function (err, r) { if (!done) { done = true; cb(err, r); } };\n var viaPromise = function (ns) {\n try {\n var ret = ns[method].apply(ns, callArgs);\n if (ret && typeof ret.then === \"function\") {\n ret.then(function (r) { once(null, r); }, function (e) { once(e); });\n return true;\n }\n } catch (e) { once(e); return true; }\n return false;\n };\n var bNS = g.browser && g.browser[nsName];\n if (bNS && typeof bNS[method] === \"function\" && viaPromise(bNS)) return;\n var cNS = chromeG && chromeG[nsName];\n if (!cNS || typeof cNS[method] !== \"function\") {\n once(new Error(\"chrome.\" + nsName + \".\" + method + \" is not available (engine: \" + engineName() + \")\"));\n return;\n }\n try {\n var ret2 = cNS[method].apply(cNS, callArgs.concat([function (r) {\n var le = chromeG.runtime && chromeG.runtime.lastError;\n if (le) once(le); else once(null, r);\n }]));\n // A promise-only implementation ignores the trailing callback and\n // returns a thenable instead; resolve through it (once() dedupes).\n if (ret2 && typeof ret2.then === \"function\") {\n ret2.then(function (r) { once(null, r); }, function (e) { once(e); });\n }\n } catch (e2) {\n if (!viaPromise(cNS)) once(e2);\n }\n }\n\n function executeCommand(cmd) {\n var op = cmd.op, target = cmd.target || {}, args = cmd.args || {};\n var ctx = target.context || \"background\";\n var chrome = g.chrome;\n var cmdId = cmd.cmdId;\n // content/page eval & inspect need a numeric tab id: resolve --url (or\n // nothing) to a tab and re-dispatch with target.tabId filled in. (#51)\n if ((op === \"eval\" || op === \"inspect\") && (ctx === \"content\" || ctx === \"page\") && target.tabId == null) {\n resolveTargetTab(target, function (tabId, err) {\n if (tabId == null) {\n replyErr(cmdId, \"Unsupported\", err || (\"eval/inspect in context \" + ctx + \" needs a --tab id, a --url to match, or an active tab\"));\n return;\n }\n var next = {};\n for (var k in cmd) { if (Object.prototype.hasOwnProperty.call(cmd, k)) next[k] = cmd[k]; }\n next.target = {};\n for (var tk in target) { if (Object.prototype.hasOwnProperty.call(target, tk)) next.target[tk] = target[tk]; }\n next.target.tabId = tabId;\n executeCommand(next);\n });\n return;\n }\n try {\n if (!chrome) { replyErr(cmdId, \"Unsupported\", \"chrome.* not available in this context\"); return; }\n if (op === \"eval\") {\n if (ctx === \"background\") {\n Promise.resolve().then(function () { return (0, eval)(args.expression); })\n .then(function (r) { replyOk(cmdId, r); }, function (e) {\n var msg = (e && e.message) || String(e);\n // MV3 forbids eval of strings in the SW/extension pages and\n // rejects 'unsafe-eval'. Surface it honestly with an alternative.\n if (/Content Security Policy|unsafe-eval/i.test(msg)) {\n replyErr(cmdId, \"Unsupported\", \"eval is blocked in the MV3 service worker by CSP. Use --context page --tab <id> (eval runs in the page's MAIN world), or run on an MV2/Firefox build. Engine: \" + engineName());\n } else {\n replyErr(cmdId, (e && e.name) || \"EvalError\", msg);\n }\n });\n } else if ((ctx === \"content\" || ctx === \"page\") && target.tabId && chrome.scripting) {\n // Wrap the eval so a throw INSIDE the tab comes back as data:\n // Chrome swallows an injected function's exception (null result).\n nsCall(\"scripting\", \"executeScript\", [{\n target: {tabId: target.tabId},\n world: ctx === \"page\" ? \"MAIN\" : \"ISOLATED\",\n func: function (src) {\n try { return {__extjsEval: 1, ok: true, value: eval(src)}; }\n catch (e) { return {__extjsEval: 1, ok: false, name: (e && e.name) || \"EvalError\", message: (e && e.message) || String(e)}; }\n },\n args: [String(args.expression)]\n }], function (err, res) {\n if (err) { replyErr(cmdId, \"TargetNotFound\", (err && err.message) || err); return; }\n var frame = res && res[0] ? res[0].result : undefined;\n if (!frame || frame.__extjsEval !== 1) {\n replyErr(cmdId, \"TargetNotFound\", \"the expression never executed in tab \" + target.tabId + \": no injectable frame returned a result (restricted page, or outside host_permissions)\");\n return;\n }\n if (frame.ok) { replyOk(cmdId, frame.value); return; }\n if (ctx === \"content\" && /Content Security Policy|unsafe-eval|EvalError/i.test(String(frame.name) + \" \" + String(frame.message))) {\n replyErr(cmdId, \"Unsupported\", \"eval of a string is blocked in the ISOLATED (content) world by the extension CSP. Use --context page (runs in the page's MAIN world). Original: \" + frame.message);\n return;\n }\n replyErr(cmdId, frame.name || \"EvalError\", frame.message);\n });\n } else if (ctx === \"popup\" || ctx === \"options\" || ctx === \"sidebar\" || ctx === \"devtools\" || ctx === \"newtab\" || ctx === \"history\" || ctx === \"bookmarks\") {\n // The SW can't eval in another extension page; ask the surface's\n // own in-bundle relay (only the open, matching-context page responds).\n chrome.runtime.sendMessage(\n {__extjsEvalRequest: true, target: target, args: {expression: String(args.expression)}},\n function (resp) {\n if ((chrome.runtime && chrome.runtime.lastError) || !resp) {\n replyErr(cmdId, \"Unsupported\", \"surface '\" + ctx + \"' is not open (open it first: extension open \" + ctx + \")\", \"surface_not_open\");\n } else if (resp.ok) {\n replyOk(cmdId, resp.value);\n } else {\n replyErr(cmdId, (resp.error && resp.error.name) || \"EvalError\", (resp.error && resp.error.message) || \"eval failed\");\n }\n }\n );\n } else if (ctx === \"content\" || ctx === \"page\") {\n replyErr(cmdId, \"Unsupported\", target.tabId\n ? \"chrome.scripting is not available on this engine (MV2 has no scripting API); use --context background\"\n : \"eval in context \" + ctx + \" requires a tabId\");\n } else {\n replyErr(cmdId, \"BadRequest\", \"unknown eval context: \" + ctx);\n }\n return;\n }\n if (op === \"storage.get\" || op === \"storage.set\") {\n // chrome.* storage is callback-only on Gecko and older Chromium.\n // Prefer promisified browser.*, then fall back to the callback shape.\n var storageNS = (g.browser && g.browser.storage) ? g.browser.storage : chrome.storage;\n var storageArea = storageNS && storageNS[args.area || \"local\"];\n if (!storageArea) { replyErr(cmdId, \"StorageError\", \"storage.\" + (args.area || \"local\") + \" unavailable\"); return; }\n var isSet = op === \"storage.set\";\n var callArgs = isSet ? [args.items || {}] : [args.key != null ? args.key : null];\n var onStorageOk = function (r) { replyOk(cmdId, isSet ? {set: Object.keys(args.items || {})} : r); };\n var onStorageErr = function (e) { replyErr(cmdId, \"StorageError\", (e && e.message) || String(e)); };\n var storageFn = isSet ? storageArea.set : storageArea.get;\n try {\n var storageRet = storageFn.apply(storageArea, callArgs);\n if (storageRet && typeof storageRet.then === \"function\") {\n storageRet.then(onStorageOk, onStorageErr);\n return;\n }\n } catch (e) { /* not thenable / threw synchronously: fall back to callback */ }\n try {\n storageFn.apply(storageArea, callArgs.concat([function (r) {\n var le = chrome.runtime && chrome.runtime.lastError;\n if (le) onStorageErr(le); else onStorageOk(r);\n }]));\n } catch (e) { onStorageErr(e); }\n return;\n }\n if (op === \"reload\") {\n if (ctx === \"background\") {\n replyOk(cmdId, {reloading: true});\n setTimeout(function () { try { chrome.runtime.reload(); } catch (e) {\n // Ignore\n } }, 50);\n } else if (target.tabId) {\n nsCall(\"tabs\", \"reload\", [target.tabId], function (err) {\n if (err) replyErr(cmdId, \"ReloadError\", (err && err.message) || err);\n else replyOk(cmdId, {reloaded: target.tabId});\n });\n } else {\n replyErr(cmdId, \"Unsupported\", \"reload needs background or a tabId\");\n }\n return;\n }\n if (op === \"open\") {\n var surface = args.surface || ctx;\n // getPopup is promise-style on Gecko and (MV3) Chromium; fall back to\n // callback-style for older Chromium. Always resolves to a string.\n var getActionPopup = function (cb) {\n try {\n var r = chrome.action && chrome.action.getPopup && chrome.action.getPopup({});\n if (r && typeof r.then === \"function\") {\n r.then(function (p) { cb(p || \"\"); }, function () { cb(\"\"); });\n return;\n }\n } catch (e) {\n // Ignore\n }\n try { chrome.action.getPopup({}, function (p) { cb(p || \"\"); }); }\n catch (e) { cb(\"\"); }\n };\n var resolveActiveTab = function (a, cb) {\n if (a && typeof a.tabId === \"number\") {\n try { chrome.tabs.get(a.tabId, function (t) { cb(t || {id: a.tabId}); }); return; }\n catch (e) {\n // Ignore\n }\n }\n try { chrome.tabs.query({active: true, lastFocusedWindow: true}, function (tabs) { cb((tabs && tabs[0]) || undefined); }); }\n catch (e) { cb(undefined); }\n };\n // Replaying a listener carries no user gesture, so activeTab is never\n // granted. Warn when the manifest declares it.\n var activeTabWarning = function () {\n try {\n var m = chrome.runtime.getManifest();\n var perms = (m && m.permissions) || [];\n if (perms.indexOf(\"activeTab\") !== -1) {\n return \"replayed without a user gesture: activeTab is NOT granted, so APIs that depend on it (scripting on the active tab, captureVisibleTab) behave differently than a real click\";\n }\n } catch (e) {\n // Ignore\n }\n return null;\n };\n if (surface === \"popup\") {\n if (chrome.action && chrome.action.openPopup) {\n nsCall(\"action\", \"openPopup\", [], function (err) {\n if (err) {\n var openMsg = (err && err.message) || err;\n replyErr(cmdId, \"Unsupported\", \"openPopup: \" + openMsg, openRefusalCode(openMsg));\n } else replyOk(cmdId, {opened: \"popup\"});\n });\n } else { replyErr(cmdId, \"Unsupported\", \"action.openPopup not available\", \"api_unavailable\"); }\n } else if (surface === \"options\") {\n try { chrome.runtime.openOptionsPage(function () { replyOk(cmdId, {opened: \"options\"}); }); }\n catch (e) { replyErr(cmdId, \"Unsupported\", \"openOptionsPage: \" + e); }\n } else if (surface === \"sidebar\") {\n if (chrome.sidePanel && chrome.sidePanel.open && chrome.windows) {\n chrome.windows.getCurrent(function (w) {\n nsCall(\"sidePanel\", \"open\", [{windowId: w.id}], function (err) {\n if (err) {\n var sideMsg = (err && err.message) || err;\n replyErr(cmdId, \"Unsupported\", \"sidePanel.open: \" + sideMsg, openRefusalCode(sideMsg));\n } else replyOk(cmdId, {opened: \"sidebar\"});\n });\n });\n } else { replyErr(cmdId, \"Unsupported\", \"sidePanel not available (engine: \" + engineName() + \")\", \"api_unavailable\"); }\n } else if (surface === \"action\") {\n // With a default_popup the click opens it; without one, replay the\n // onClicked listeners captured at install time.\n if (chrome.action) {\n getActionPopup(function (popup) {\n if (popup) {\n nsCall(\"action\", \"openPopup\", [], function (err) {\n if (err) {\n var actMsg = (err && err.message) || err;\n replyErr(cmdId, \"Unsupported\", \"openPopup: \" + actMsg, openRefusalCode(actMsg));\n } else replyOk(cmdId, {triggered: \"popup\"});\n });\n } else if (actionClickedListeners.length) {\n resolveActiveTab(args, function (tab) {\n var fired = 0;\n for (var i = 0; i < actionClickedListeners.length; i++) {\n try { actionClickedListeners[i](tab); fired++; } catch (e) {\n // Ignore\n }\n }\n var reply = {triggered: \"onClicked\", listeners: fired, gesture: false};\n var warning = activeTabWarning();\n if (warning) reply.warning = warning;\n replyOk(cmdId, reply);\n });\n } else {\n replyErr(cmdId, \"Unsupported\", \"action has no popup and no onClicked listener registered\");\n }\n });\n } else { replyErr(cmdId, \"Unsupported\", \"chrome.action not available (engine: \" + engineName() + \")\", \"api_unavailable\"); }\n } else if (surface === \"command\") {\n var commandName = (args && args.name) || undefined;\n if (!commandListeners.length) {\n replyErr(cmdId, \"Unsupported\", \"no chrome.commands.onCommand listener registered\");\n } else {\n resolveActiveTab(args, function (tab) {\n var fired = 0;\n for (var i = 0; i < commandListeners.length; i++) {\n try { commandListeners[i](commandName, tab); fired++; } catch (e) {\n // Ignore\n }\n }\n replyOk(cmdId, {triggered: \"command\", command: commandName || null, listeners: fired, gesture: false});\n });\n }\n } else { replyErr(cmdId, \"BadRequest\", \"unknown surface: \" + surface); }\n return;\n }\n if (op === \"tabs.query\") {\n nsCall(\"tabs\", \"query\", [args || {}], function (err, tabs) {\n if (err) { replyErr(cmdId, \"TabsError\", (err && err.message) || err); return; }\n replyOk(cmdId, (tabs || []).map(function (t) { return {id: t.id, url: t.url, title: t.title, active: t.active, windowId: t.windowId}; }));\n });\n return;\n }\n if (op === \"inspect\") {\n // Extract a DOM snapshot from the target page via chrome.scripting\n // (CDP-free). Closed shadow roots need CDP; here we read open ones.\n if ((ctx === \"content\" || ctx === \"page\") && target.tabId && chrome.scripting) {\n var maxBytes = (args && args.maxBytes) || 262144;\n var includeHtml = !args || !args.include || args.include.indexOf(\"html\") !== -1;\n nsCall(\"scripting\", \"executeScript\", [{\n target: {tabId: target.tabId},\n world: ctx === \"page\" ? \"MAIN\" : \"ISOLATED\",\n func: function (wantHtml, cap) {\n function countShadow(root) {\n var n = 0, els = root.querySelectorAll(\"*\");\n for (var i = 0; i < els.length; i++) { if (els[i].shadowRoot) { n++; n += countShadow(els[i].shadowRoot); } }\n return n;\n }\n var doc = document;\n var roots = doc.querySelectorAll('#extension-root,[data-extension-root]');\n var out = {\n url: location.href,\n title: doc.title,\n summary: {\n htmlLength: doc.documentElement.outerHTML.length,\n scriptCount: doc.querySelectorAll(\"script\").length,\n styleCount: doc.querySelectorAll(\"style,link[rel=stylesheet]\").length,\n extensionRootCount: roots.length,\n openShadowRoots: countShadow(doc),\n bodyChildCount: doc.body ? doc.body.children.length : 0\n }\n };\n if (wantHtml) {\n var html = doc.documentElement.outerHTML;\n if (cap > 0 && html.length > cap) { out.html = html.slice(0, cap); out.htmlTruncated = true; }\n else { out.html = html; }\n }\n return out;\n },\n args: [includeHtml, maxBytes]\n }], function (err, res) {\n if (err) { replyErr(cmdId, \"TargetNotFound\", (err && err.message) || err); return; }\n var snap = res && res[0] ? res[0].result : undefined;\n if (snap == null) { replyErr(cmdId, \"TargetNotFound\", \"no injectable frame returned a snapshot for tab \" + target.tabId + \" (restricted page, or outside host_permissions)\"); return; }\n replyOk(cmdId, snap);\n });\n } else if (ctx === \"popup\" || ctx === \"options\" || ctx === \"sidebar\" || ctx === \"devtools\" || ctx === \"newtab\" || ctx === \"history\" || ctx === \"bookmarks\") {\n // The SW can't read a surface page's DOM; ask the surface's own\n // in-bundle relay (only the open, matching-context page responds).\n chrome.runtime.sendMessage(\n {__extjsInspectRequest: true, target: target, args: args},\n function (resp) {\n if (chrome.runtime.lastError || !resp) {\n replyErr(cmdId, \"Unsupported\", \"surface '\" + ctx + \"' is not open (open it first: extension open \" + ctx + \")\", \"surface_not_open\");\n } else if (resp.ok) {\n replyOk(cmdId, resp.value);\n } else {\n replyErr(cmdId, (resp.error && resp.error.name) || \"InspectError\", (resp.error && resp.error.message) || \"inspect failed\");\n }\n }\n );\n } else if (ctx === \"background\") {\n replyErr(cmdId, \"Unsupported\", \"the service worker has no DOM; inspect a content/page (with --tab) or an open surface\");\n } else {\n replyErr(cmdId, \"Unsupported\", \"inspect of \" + ctx + \" requires a tabId (content/page) or an open surface\");\n }\n return;\n }\n replyErr(cmdId, \"BadRequest\", \"unknown op: \" + op);\n } catch (e) {\n replyErr(cmdId, \"ExecutorError\", e);\n }\n }\n\n function noopLastError() { try { void g.chrome.runtime.lastError; } catch (e) {\n // Ignore\n } }\n\n // Only http(s)/file/ftp tabs can run a content script; skip chrome://, the\n // extension's own pages, about:blank, etc.\n function isInjectableUrl(url) {\n return typeof url === \"string\" && /^(https?|file|ftp):/i.test(url);\n }\n\n // Re-inject one declared entry's fresh files into every matching open tab.\n // exclude_matches MUST be honored: query the excludes and subtract them.\n function reinjectContentScriptEntry(entry) {\n var chrome = g.chrome;\n var matches = (entry && entry.matches) || [];\n if (!Array.isArray(matches) || !matches.length) return;\n var excludeMatches = (entry && entry.exclude_matches) || [];\n var jsFiles = ((entry && entry.js) || []).filter(function (f) { return typeof f === \"string\"; });\n var cssFiles = ((entry && entry.css) || []).filter(function (f) { return typeof f === \"string\"; });\n if (!jsFiles.length && !cssFiles.length) return;\n var world = entry.world === \"MAIN\" ? \"MAIN\" : \"ISOLATED\";\n var allFrames = !!entry.all_frames;\n function injectInto(excludedTabIds) {\n try {\n chrome.tabs.query({url: matches}, function (tabs) {\n var err = null;\n try { err = chrome.runtime.lastError; } catch (e) {\n // Ignore\n }\n if (err || !tabs) return;\n for (var i = 0; i < tabs.length; i++) {\n (function (tab) {\n if (!tab || tab.id == null || !isInjectableUrl(tab.url)) return;\n if (excludedTabIds[tab.id]) return;\n var target = {tabId: tab.id, allFrames: allFrames};\n if (cssFiles.length && chrome.scripting.insertCSS) {\n try { chrome.scripting.insertCSS({target: target, files: cssFiles}, noopLastError); } catch (e) {\n // Ignore\n }\n }\n if (jsFiles.length && chrome.scripting.executeScript) {\n try {\n chrome.scripting.executeScript(\n {target: target, files: jsFiles, world: world, injectImmediately: true},\n noopLastError\n );\n } catch (e) {\n // Ignore\n }\n }\n })(tabs[i]);\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n if (Array.isArray(excludeMatches) && excludeMatches.length) {\n try {\n chrome.tabs.query({url: excludeMatches}, function (excludedTabs) {\n try { void chrome.runtime.lastError; } catch (e) {\n // Ignore\n }\n var excluded = {};\n if (excludedTabs) {\n for (var i = 0; i < excludedTabs.length; i++) {\n if (excludedTabs[i] && excludedTabs[i].id != null) excluded[excludedTabs[i].id] = true;\n }\n }\n injectInto(excluded);\n });\n return;\n } catch (e) {\n // Ignore\n }\n }\n injectInto({});\n }\n\n // Re-inject all content scripts into their open tabs. Reads the manifest\n // FROM DISK: getManifest() is frozen and dev filenames are content-hashed.\n function reinjectContentScripts(onDone) {\n var chrome = g.chrome;\n try {\n if (typeof g.fetch !== \"function\" || !chrome.scripting) return false;\n g.fetch(chrome.runtime.getURL(\"manifest.json\"), {cache: \"no-store\"})\n .then(function (r) { return r.json(); })\n .then(function (manifest) {\n var entries = (manifest && manifest.content_scripts) || [];\n for (var i = 0; i < entries.length; i++) reinjectContentScriptEntry(entries[i]);\n reregisterForFutureNavigations(entries);\n if (onDone) { try { onDone(); } catch (e) {\n // Ignore\n } }\n })\n .catch(function () {\n // Ignore\n });\n return true;\n } catch (e) { return false; }\n }\n\n function mapRunAt(runAt) {\n if (runAt === \"document_start\") return \"document_start\";\n if (runAt === \"document_end\") return \"document_end\";\n return \"document_idle\";\n }\n\n // Re-register content scripts dynamically at the fresh files, so tabs\n // opened AFTER an edit also get the new build. Idempotent per entry id.\n function reregisterForFutureNavigations(entries) {\n var chrome = g.chrome;\n if (\n !chrome.scripting ||\n !chrome.scripting.registerContentScripts ||\n !chrome.scripting.getRegisteredContentScripts\n ) return;\n\n var scripts = [];\n for (var i = 0; i < entries.length; i++) {\n var e = entries[i] || {};\n if (!Array.isArray(e.matches) || !e.matches.length) continue;\n var js = (e.js || []).filter(function (f) { return typeof f === \"string\"; });\n var css = (e.css || []).filter(function (f) { return typeof f === \"string\"; });\n if (!js.length && !css.length) continue;\n var s = {\n id: \"extjs-dev-cs-\" + i,\n matches: e.matches,\n runAt: mapRunAt(e.run_at),\n allFrames: !!e.all_frames,\n world: e.world === \"MAIN\" ? \"MAIN\" : \"ISOLATED\"\n };\n // Dev registration must not be BROADER than the static one: dropping\n // exclude_matches injects into pages the browser itself would skip.\n if (Array.isArray(e.exclude_matches) && e.exclude_matches.length) {\n s.excludeMatches = e.exclude_matches;\n }\n if (js.length) s.js = js;\n if (css.length) s.css = css;\n scripts.push(s);\n }\n if (!scripts.length) return;\n\n try {\n chrome.scripting.getRegisteredContentScripts(function (existing) {\n try { void chrome.runtime.lastError; } catch (e) {\n // Ignore\n }\n var have = {};\n if (existing) for (var k = 0; k < existing.length; k++) have[existing[k].id] = true;\n var toRegister = [], toUpdate = [];\n for (var j = 0; j < scripts.length; j++) {\n (have[scripts[j].id] ? toUpdate : toRegister).push(scripts[j]);\n }\n if (toRegister.length) {\n try { chrome.scripting.registerContentScripts(toRegister, noopLastError); } catch (e) {\n // Ignore\n }\n }\n if (toUpdate.length) {\n try { chrome.scripting.updateContentScripts(toUpdate, noopLastError); } catch (e) {\n // Ignore\n }\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n\n // Dev-loop reload without the CDP controller: content-scripts re-inject in\n // place into open tabs; service-worker/full/manifest restart the extension.\n function performDevReload(type, onDone) {\n var chrome = g.chrome;\n if (!chrome) return;\n\n var fullReload = function () {\n // Flag a pending reinject for the NEXT producer generation: the\n // boot-time heal is what converges open tabs after a SW/full reload.\n try {\n if (chrome.storage && chrome.storage.local) {\n chrome.storage.local.set({__extjsDevPendingReinject: Date.now()}, noopLastError);\n }\n } catch (e) {\n // Ignore\n }\n // Deferred so in-flight frames and the tab console announcement flush\n // before the SW dies; the devtools companion confirms completion.\n try { setTimeout(function () { try { chrome.runtime.reload(); } catch (e) {\n // Ignore\n } }, 150); } catch (e) {}\n };\n\n if (type === \"content-scripts\" && chrome.scripting && chrome.tabs && chrome.tabs.query) {\n if (reinjectContentScripts(onDone)) return;\n }\n\n fullReload();\n }\n\n // One server-built label travels the ReloadFrame; both announcement\n // surfaces fire HERE, next to the actual reload action, so they stay true.\n\n // Stable IDs of the bundled extension-js-devtools companion: Chromium pins\n // via the manifest \"key\"; Firefox via browser_specific_settings.gecko.id.\n var DEVTOOLS_COMPANION_ID_CHROMIUM = \"kgdaecdpfkikjncaalnmmnjjfpofkcbl\";\n var DEVTOOLS_COMPANION_ID_FIREFOX = \"devtools@extension.js\";\n\n function notifyDevtoolsCompanion(phase, label, kind) {\n try {\n var chrome = g.chrome;\n if (!chrome || !chrome.runtime || typeof chrome.runtime.sendMessage !== \"function\") return;\n var id = engineName() === \"firefox\" ? DEVTOOLS_COMPANION_ID_FIREFOX : DEVTOOLS_COMPANION_ID_CHROMIUM;\n chrome.runtime.sendMessage(\n id,\n {type: \"extjs-dev-reload-state\", phase: phase, label: label || \"\", kind: kind || \"\", instanceId: INSTANCE_ID},\n function () { noopLastError(); }\n );\n } catch (e) {\n // Ignore\n }\n }\n\n // console.log the reload line into every open injectable tab; the patched\n // ISOLATED-world console also lands it in the dev-server log stream.\n function announceReloadInTabs(text) {\n var chrome = g.chrome;\n if (!chrome || !chrome.tabs || !chrome.tabs.query) return;\n try {\n chrome.tabs.query({}, function (tabs) {\n noopLastError();\n if (!tabs) return;\n for (var i = 0; i < tabs.length; i++) {\n (function (tab) {\n if (!tab || tab.id == null || !isInjectableUrl(tab.url)) return;\n if (chrome.scripting && chrome.scripting.executeScript) {\n try {\n chrome.scripting.executeScript(\n {target: {tabId: tab.id}, func: function (t) { console.log(t); }, args: [text]},\n noopLastError\n );\n return;\n } catch (e) {\n // Ignore\n }\n }\n // MV2 fallback (Firefox without the scripting API).\n if (chrome.tabs.executeScript) {\n try {\n chrome.tabs.executeScript(tab.id, {code: \"console.log(\" + JSON.stringify(text) + \");\"}, noopLastError);\n } catch (e) {\n // Ignore\n }\n }\n })(tabs[i]);\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n\n function handleDevReloadFrame(frame) {\n var kind = frame.reloadType || \"full\";\n var label = typeof frame.label === \"string\" ? frame.label : \"\";\n // The server always builds the label; the kind-derived fallback only\n // covers a malformed frame so the announcement stays truthful.\n var fallback = kind === \"content-scripts\" ? \"content_script\"\n : kind === \"service-worker\" ? \"service_worker\"\n : \"extension\";\n var announced = \"[Extension.js] Reloading \" + (label || fallback) + \"\u2026\";\n\n notifyDevtoolsCompanion(\"reloading\", label, kind);\n\n if (kind === \"page\") {\n // Notify-only: rspack-dev-server's livereload refreshes the open\n // surface; reloading the extension here would race it.\n return;\n }\n\n // Delivery ack for the broker: proves this SW's message pump processed\n // the frame (a socket write proves nothing). Sent on receipt, by design.\n send({type: \"reload-ack\", reloadType: kind, label: label});\n\n announceReloadInTabs(announced);\n performDevReload(kind, function () {\n // Only the content-scripts path confirms from here; full/SW reloads\n // are confirmed by the devtools companion's chrome.management listeners.\n notifyDevtoolsCompanion(\"reloaded\", label, kind);\n });\n }\n\n function sanitize(args) {\n var out = [];\n for (var i = 0; i < args.length; i++) {\n var p = args[i];\n try {\n if (typeof p === \"string\") out.push(p.length > 2048 ? p.slice(0, 2048) + \"...\" : p);\n else if (p instanceof Error) out.push(p.name + \": \" + p.message);\n else out.push(JSON.stringify(p));\n } catch (e) {\n out.push(String(p));\n }\n if (out.join(\" \").length > 8192) break;\n }\n return out;\n }\n\n function flush() {\n while (queue.length && open && socket) {\n var f = queue.shift();\n try { socket.send(JSON.stringify(f)); } catch (e) { break; }\n }\n }\n\n function send(frame) {\n if (open && socket) {\n try { socket.send(JSON.stringify(frame)); return; } catch (e) {\n // Ignore\n }\n }\n if (queue.length < MAX_QUEUE) queue.push(frame);\n }\n\n function schedule() {\n var delay = backoff;\n backoff = Math.min(backoff * 2, MAX_BACKOFF);\n try { setTimeout(connect, delay); } catch (e) {\n // Ignore\n }\n }\n\n function connect() {\n try {\n socket = new WS(\"ws://\" + HOST + \":\" + PORT + \"/extjs-control\");\n } catch (e) {\n schedule();\n return;\n }\n socket.onopen = function () {\n open = true;\n backoff = 250;\n try {\n socket.send(JSON.stringify({type: \"hello\", v: 1, role: \"producer\", instanceId: INSTANCE_ID}));\n } catch (e) {\n // Ignore\n }\n flush();\n };\n socket.onmessage = function (ev) {\n var frame;\n try { frame = JSON.parse(typeof ev.data === \"string\" ? ev.data : \"\"); } catch (e) { return; }\n if (frame && frame.type === \"command\") {\n try { executeCommand(frame); } catch (e) { replyErr(frame.cmdId, \"ExecutorError\", e); }\n } else if (frame && frame.type === \"reload\") {\n // Dev-loop reload broadcast (see broker.broadcastReload).\n // Fire-and-forget: no result frame is expected.\n try { handleDevReloadFrame(frame); } catch (e) {\n // Ignore\n }\n } else if (frame && frame.type === \"ping\") {\n // Server keepalive: merely RECEIVING this resets the MV3 SW's ~30s\n // idle timer (Chrome 116+), keeping it reachable. Nothing to do.\n }\n };\n socket.onclose = function () {\n open = false;\n socket = null;\n schedule();\n };\n socket.onerror = function () {\n try { socket && socket.close(); } catch (e) {\n // Ignore\n }\n };\n }\n\n // Uncaught errors don't route through the patched console; the handlers\n // below forward them, using these signatures to skip already-logged throws.\n var recentErrorSigs = [];\n function errorSig(message, stack) {\n return String(message == null ? \"\" : message) + \"::\" + String(stack == null ? \"\" : stack).slice(0, 200);\n }\n function noteErrorSig(sig) {\n recentErrorSigs.push({sig: sig, t: Date.now()});\n if (recentErrorSigs.length > 50) recentErrorSigs.shift();\n }\n function errorSigSeenRecently(sig) {\n var now = Date.now();\n for (var i = recentErrorSigs.length - 1; i >= 0; i--) {\n if (now - recentErrorSigs[i].t > 3000) { recentErrorSigs.splice(i, 1); continue; }\n if (recentErrorSigs[i].sig === sig) return true;\n }\n return false;\n }\n\n LEVELS.forEach(function (level) {\n var orig = typeof consoleRef[level] === \"function\"\n ? consoleRef[level].bind(consoleRef)\n : function () {};\n consoleRef[level] = function () {\n try {\n if (level === \"error\") {\n for (var ai = 0; ai < arguments.length; ai++) {\n if (arguments[ai] instanceof Error) noteErrorSig(errorSig(arguments[ai].message, arguments[ai].stack));\n }\n }\n send({\n type: \"log\",\n event: {\n v: 1,\n id: nowId(),\n timestamp: Date.now(),\n level: level,\n context: CONTEXT,\n messageParts: sanitize([].slice.call(arguments)),\n runId: INSTANCE_ID\n }\n });\n } catch (e) {\n // Ignore\n }\n return orig.apply(consoleRef, arguments);\n };\n });\n\n // Forward uncaught throws / unhandled rejections as level:\"error\", deduped\n // so a logged-then-rethrown Error emits once.\n function shipUncaughtError(message, stack, url) {\n try {\n var sig = errorSig(message, stack);\n if (errorSigSeenRecently(sig)) return;\n noteErrorSig(sig);\n send({\n type: \"log\",\n event: {\n v: 1,\n id: nowId(),\n timestamp: Date.now(),\n level: \"error\",\n context: CONTEXT,\n messageParts: sanitize([String(message) + (stack ? \"\\n\" + stack : \"\")]),\n url: url,\n runId: INSTANCE_ID\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n try {\n if (typeof g.addEventListener === \"function\") {\n g.addEventListener(\"error\", function (ev) {\n var err = ev && ev.error;\n var message = (err && err.message) || (ev && ev.message) || \"Uncaught error\";\n shipUncaughtError(message, err && err.stack, ev && ev.filename);\n });\n g.addEventListener(\"unhandledrejection\", function (ev) {\n var reason = ev && ev.reason;\n var message = (reason && reason.message) || (reason != null ? String(reason) : \"Unhandled rejection\");\n shipUncaughtError(\"Unhandled promise rejection: \" + message, reason && reason.stack, undefined);\n });\n }\n } catch (e) {\n // Ignore\n }\n\n // Other contexts relay console logs to this SW over a NAMED runtime.Port:\n // they can't open the WS under page CSP, and sendMessage can echo-loop.\n function shipRelayedLog(ev, sender) {\n try {\n send({\n type: \"log\",\n event: {\n v: 1,\n id: nowId(),\n timestamp: Date.now(),\n level: ev.level || \"log\",\n context: ev.context || \"content\",\n messageParts: Array.isArray(ev.messageParts) ? ev.messageParts : [],\n url: ev.url || (sender ? sender.url : undefined),\n tabId: sender && sender.tab ? sender.tab.id : undefined,\n frameId: sender ? sender.frameId : undefined,\n runId: INSTANCE_ID\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n try {\n var rtPort = g.chrome;\n if (rtPort && rtPort.runtime && rtPort.runtime.onConnect) {\n rtPort.runtime.onConnect.addListener(function (port) {\n if (!port || port.name !== \"__extjs-bridge-log__\") return;\n try {\n port.onMessage.addListener(function (msg) {\n if (!msg || !msg.__extjsBridgeLog) return;\n shipRelayedLog(msg.__extjsBridgeLog, port.sender);\n });\n } catch (e) {\n // Ignore\n }\n });\n }\n } catch (e) {\n // Ignore\n }\n // Legacy sendMessage path: kept for any surface still relaying the old way\n // (harmless one-predicate listener; new relays never use it).\n try {\n var rt = g.chrome;\n if (rt && rt.runtime && rt.runtime.onMessage) {\n rt.runtime.onMessage.addListener(function (msg, sender) {\n if (!msg || !msg.__extjsBridgeLog) return;\n shipRelayedLog(msg.__extjsBridgeLog, sender);\n });\n }\n } catch (e) {\n // Ignore\n }\n\n // Chrome never injects manifest content scripts into already-open tabs, so\n // fire one reinject on onInstalled (which skips idle-stop SW wakes).\n try {\n var rtBoot = g.chrome;\n if (rtBoot && rtBoot.runtime && rtBoot.runtime.onInstalled) {\n rtBoot.runtime.onInstalled.addListener(function () {\n try {\n setTimeout(function () {\n try { reinjectContentScripts(); } catch (e) {\n // Ignore\n }\n }, 250);\n } catch (e) {\n // Ignore\n }\n });\n }\n } catch (e) {\n // Ignore\n }\n\n // runtime.reload() does NOT fire onInstalled (verified Chromium 146), so\n // consume the pre-reload storage flag here (fresh only) to heal open tabs.\n try {\n var stBoot = g.chrome;\n if (stBoot && stBoot.storage && stBoot.storage.local) {\n stBoot.storage.local.get(\"__extjsDevPendingReinject\", function (res) {\n noopLastError();\n var ts = res && res.__extjsDevPendingReinject;\n if (ts == null) return;\n try { stBoot.storage.local.remove(\"__extjsDevPendingReinject\", noopLastError); } catch (e) {\n // Ignore\n }\n if (typeof ts !== \"number\" || Date.now() - ts > 30000) return;\n setTimeout(function () {\n try { reinjectContentScripts(); } catch (e) {\n // Ignore\n }\n }, 250);\n });\n }\n } catch (e) {\n // Ignore\n }\n\n connect();\n } catch (e) {\n // Ignore\n }\n})();\n";
|
|
1
|
+
export declare const CONTROL_PORT_ASSET_NAME = "extension-js-control.json";
|
|
2
|
+
export declare const BRIDGE_PRODUCER_SOURCE = ";(function () {\n try {\n var g = (typeof globalThis === \"object\" && globalThis) ? globalThis : this;\n if (!g || g.__extjsBridgeProducerInstalled) return;\n\n var PORT = parseInt(\"__EXTJS_CONTROL_PORT__\", 10);\n var INSTANCE_ID = \"__EXTJS_INSTANCE_ID__\";\n var CONTEXT = \"__EXTJS_CONTEXT__\";\n // Connectable host of the dev-server control WS. Baked from the resolved\n // connectable host (loopback locally; the public host for remote/devcontainer).\n var HOST = \"__EXTJS_CONTROL_HOST__\";\n if (!HOST || HOST.indexOf(\"__EXTJS\") === 0) HOST = \"127.0.0.1\";\n if (!PORT || PORT < 1) return;\n\n var WS = g.WebSocket;\n if (typeof WS !== \"function\") return;\n\n var consoleRef = g.console || {};\n g.__extjsBridgeProducerInstalled = true;\n\n // Capture extension event listeners at install time: these wraps run\n // BEFORE user code, and no platform API exists to dispatch these events.\n function captureEvent(event, sink) {\n try {\n if (!event || typeof event.addListener !== \"function\") return;\n var origAdd = event.addListener.bind(event);\n event.addListener = function (cb) {\n if (typeof cb === \"function\" && sink.indexOf(cb) === -1) sink.push(cb);\n return origAdd(cb);\n };\n if (typeof event.removeListener === \"function\") {\n var origRemove = event.removeListener.bind(event);\n event.removeListener = function (cb) {\n var i = sink.indexOf(cb);\n if (i !== -1) sink.splice(i, 1);\n return origRemove(cb);\n };\n }\n } catch (e) { /* non-fatal: trigger falls back to its no-listener reply */ }\n }\n\n // Use the raw globals (not the hoisted chrome var below). This runs first.\n // On Gecko browser.* is a DISTINCT wrapper object: hook BOTH namespaces.\n var actionClickedListeners = [];\n var commandListeners = [];\n var capturedEvents = [];\n function captureEventOnce(event, sink) {\n // Polyfilled extensions expose ONE event object on both namespaces:\n // wrap it once, and the sink dedupes callbacks shared across wrappers.\n if (!event || capturedEvents.indexOf(event) !== -1) return;\n capturedEvents.push(event);\n captureEvent(event, sink);\n }\n var captureNamespaces = [g.chrome, g.browser];\n for (var cn = 0; cn < captureNamespaces.length; cn++) {\n var capNS = captureNamespaces[cn];\n if (!capNS) continue;\n captureEventOnce(capNS.action && capNS.action.onClicked, actionClickedListeners);\n captureEventOnce(capNS.commands && capNS.commands.onCommand, commandListeners);\n }\n\n var LEVELS = [\"log\", \"info\", \"warn\", \"error\", \"debug\", \"trace\"];\n var socket = null;\n var open = false;\n var queue = [];\n var backoff = 250;\n var MAX_BACKOFF = 5000;\n var connectFailures = 0;\n var MAX_QUEUE = 1000;\n var MAX_RESULT_BYTES = 256 * 1024;\n\n function nowId() {\n return Date.now().toString(36) + Math.random().toString(36).slice(2, 8);\n }\n\n function engineName() {\n try {\n return (typeof navigator !== \"undefined\" && /firefox/i.test(navigator.userAgent)) ? \"firefox\" : \"chromium\";\n } catch (e) { return \"chromium\"; }\n }\n\n function safeValue(v) {\n try {\n var s = JSON.stringify(v);\n if (s === undefined) return {value: undefined, truncated: false};\n if (s.length > MAX_RESULT_BYTES) {\n return {value: {__type: \"truncated\", preview: s.slice(0, 1024)}, truncated: true};\n }\n return {value: JSON.parse(s), truncated: false};\n } catch (e) {\n return {value: {__type: \"unserializable\", preview: String(v).slice(0, 512)}, truncated: false};\n }\n }\n\n function replyOk(cmdId, value) {\n var s = safeValue(value);\n var frame = {type: \"result\", cmdId: cmdId, ok: true, value: s.value};\n if (s.truncated) frame.truncated = true;\n try { socket && socket.send(JSON.stringify(frame)); } catch (e) {\n // Ignore\n }\n }\n\n function replyErr(cmdId, name, message, code) {\n var frame = {type: \"result\", cmdId: cmdId, ok: false, error: {name: name, message: String(message), engine: engineName()}};\n if (code) frame.error.code = code;\n try { socket && socket.send(JSON.stringify(frame)); } catch (e) {\n // Ignore\n }\n }\n\n // Name the refusal the browser wrote as prose, so a consumer branches on\n // error.code instead of matching the engine's sentence.\n function openRefusalCode(message) {\n var m = String(message == null ? \"\" : message);\n if (/user gesture|user input|user interaction|user action/i.test(m)) return \"needs_user_gesture\";\n if (/browser window|active window/i.test(m)) return \"needs_headed_window\";\n return undefined;\n }\n\n // Resolve a numeric tab id when the caller did not pass one: match\n // target.url against open tabs, else default to the active tab. (#51)\n function resolveTargetTab(target, cb) {\n var chrome = g.chrome;\n if (!chrome || !chrome.tabs) { cb(null, \"chrome.tabs is not available\"); return; }\n var url = target && target.url;\n if (url) {\n var substringMatch = function () {\n try {\n chrome.tabs.query({}, function (all) {\n var hit = (all || []).filter(function (t) { return t.url && String(t.url).indexOf(url) !== -1; })[0];\n if (hit && typeof hit.id === \"number\") { cb(hit.id, null); return; }\n cb(null, \"no open tab matches url: \" + url);\n });\n } catch (e2) { cb(null, \"tab query failed\"); }\n };\n try {\n // chrome.tabs.query accepts URL match patterns; a bare url/glob may\n // not be a valid pattern, so fall back to a substring scan.\n chrome.tabs.query({url: url}, function (tabs) {\n if (chrome.runtime && chrome.runtime.lastError) { substringMatch(); return; }\n if (tabs && tabs.length && typeof tabs[0].id === \"number\") { cb(tabs[0].id, null); return; }\n substringMatch();\n });\n } catch (e) { substringMatch(); }\n return;\n }\n try {\n chrome.tabs.query({active: true, lastFocusedWindow: true}, function (tabs) {\n var t = tabs && tabs[0];\n if (t && typeof t.id === \"number\") { cb(t.id, null); return; }\n cb(null, \"no active tab to target\");\n });\n } catch (e3) { cb(null, \"tab query failed\"); }\n }\n\n // chrome.* async APIs are callback-only on Gecko. Prefer promisified\n // browser.* when present, else the chrome.* callback form. cb(err, result).\n function nsCall(nsName, method, callArgs, cb) {\n var chromeG = g.chrome;\n var done = false;\n var once = function (err, r) { if (!done) { done = true; cb(err, r); } };\n var viaPromise = function (ns) {\n try {\n var ret = ns[method].apply(ns, callArgs);\n if (ret && typeof ret.then === \"function\") {\n ret.then(function (r) { once(null, r); }, function (e) { once(e); });\n return true;\n }\n } catch (e) { once(e); return true; }\n return false;\n };\n var bNS = g.browser && g.browser[nsName];\n if (bNS && typeof bNS[method] === \"function\" && viaPromise(bNS)) return;\n var cNS = chromeG && chromeG[nsName];\n if (!cNS || typeof cNS[method] !== \"function\") {\n once(new Error(\"chrome.\" + nsName + \".\" + method + \" is not available (engine: \" + engineName() + \")\"));\n return;\n }\n try {\n var ret2 = cNS[method].apply(cNS, callArgs.concat([function (r) {\n var le = chromeG.runtime && chromeG.runtime.lastError;\n if (le) once(le); else once(null, r);\n }]));\n // A promise-only implementation ignores the trailing callback and\n // returns a thenable instead; resolve through it (once() dedupes).\n if (ret2 && typeof ret2.then === \"function\") {\n ret2.then(function (r) { once(null, r); }, function (e) { once(e); });\n }\n } catch (e2) {\n if (!viaPromise(cNS)) once(e2);\n }\n }\n\n function executeCommand(cmd) {\n var op = cmd.op, target = cmd.target || {}, args = cmd.args || {};\n var ctx = target.context || \"background\";\n var chrome = g.chrome;\n var cmdId = cmd.cmdId;\n // content/page eval & inspect need a numeric tab id: resolve --url (or\n // nothing) to a tab and re-dispatch with target.tabId filled in. (#51)\n if ((op === \"eval\" || op === \"inspect\") && (ctx === \"content\" || ctx === \"page\") && target.tabId == null) {\n resolveTargetTab(target, function (tabId, err) {\n if (tabId == null) {\n replyErr(cmdId, \"Unsupported\", err || (\"eval/inspect in context \" + ctx + \" needs a --tab id, a --url to match, or an active tab\"));\n return;\n }\n var next = {};\n for (var k in cmd) { if (Object.prototype.hasOwnProperty.call(cmd, k)) next[k] = cmd[k]; }\n next.target = {};\n for (var tk in target) { if (Object.prototype.hasOwnProperty.call(target, tk)) next.target[tk] = target[tk]; }\n next.target.tabId = tabId;\n executeCommand(next);\n });\n return;\n }\n try {\n if (!chrome) { replyErr(cmdId, \"Unsupported\", \"chrome.* not available in this context\"); return; }\n if (op === \"eval\") {\n if (ctx === \"background\") {\n Promise.resolve().then(function () { return (0, eval)(args.expression); })\n .then(function (r) { replyOk(cmdId, r); }, function (e) {\n var msg = (e && e.message) || String(e);\n // MV3 forbids eval of strings in the SW/extension pages and\n // rejects 'unsafe-eval'. Surface it honestly with an alternative.\n if (/Content Security Policy|unsafe-eval/i.test(msg)) {\n replyErr(cmdId, \"Unsupported\", \"eval is blocked in the MV3 service worker by CSP. Use --context page --tab <id> (eval runs in the page's MAIN world), or run on an MV2/Firefox build. Engine: \" + engineName());\n } else {\n replyErr(cmdId, (e && e.name) || \"EvalError\", msg);\n }\n });\n } else if ((ctx === \"content\" || ctx === \"page\") && target.tabId && chrome.scripting) {\n // Wrap the eval so a throw INSIDE the tab comes back as data:\n // Chrome swallows an injected function's exception (null result).\n nsCall(\"scripting\", \"executeScript\", [{\n target: {tabId: target.tabId},\n world: ctx === \"page\" ? \"MAIN\" : \"ISOLATED\",\n func: function (src) {\n try { return {__extjsEval: 1, ok: true, value: eval(src)}; }\n catch (e) { return {__extjsEval: 1, ok: false, name: (e && e.name) || \"EvalError\", message: (e && e.message) || String(e)}; }\n },\n args: [String(args.expression)]\n }], function (err, res) {\n if (err) { replyErr(cmdId, \"TargetNotFound\", (err && err.message) || err); return; }\n var frame = res && res[0] ? res[0].result : undefined;\n if (!frame || frame.__extjsEval !== 1) {\n replyErr(cmdId, \"TargetNotFound\", \"the expression never executed in tab \" + target.tabId + \": no injectable frame returned a result (restricted page, or outside host_permissions)\");\n return;\n }\n if (frame.ok) { replyOk(cmdId, frame.value); return; }\n if (ctx === \"content\" && /Content Security Policy|unsafe-eval|EvalError/i.test(String(frame.name) + \" \" + String(frame.message))) {\n replyErr(cmdId, \"Unsupported\", \"eval of a string is blocked in the ISOLATED (content) world by the extension CSP. Use --context page (runs in the page's MAIN world). Original: \" + frame.message);\n return;\n }\n replyErr(cmdId, frame.name || \"EvalError\", frame.message);\n });\n } else if (ctx === \"popup\" || ctx === \"options\" || ctx === \"sidebar\" || ctx === \"devtools\" || ctx === \"newtab\" || ctx === \"history\" || ctx === \"bookmarks\") {\n // The SW can't eval in another extension page; ask the surface's\n // own in-bundle relay (only the open, matching-context page responds).\n chrome.runtime.sendMessage(\n {__extjsEvalRequest: true, target: target, args: {expression: String(args.expression)}},\n function (resp) {\n if ((chrome.runtime && chrome.runtime.lastError) || !resp) {\n replyErr(cmdId, \"Unsupported\", \"surface '\" + ctx + \"' is not open (open it first: extension open \" + ctx + \")\", \"surface_not_open\");\n } else if (resp.ok) {\n replyOk(cmdId, resp.value);\n } else {\n replyErr(cmdId, (resp.error && resp.error.name) || \"EvalError\", (resp.error && resp.error.message) || \"eval failed\");\n }\n }\n );\n } else if (ctx === \"content\" || ctx === \"page\") {\n replyErr(cmdId, \"Unsupported\", target.tabId\n ? \"chrome.scripting is not available on this engine (MV2 has no scripting API); use --context background\"\n : \"eval in context \" + ctx + \" requires a tabId\");\n } else {\n replyErr(cmdId, \"BadRequest\", \"unknown eval context: \" + ctx);\n }\n return;\n }\n if (op === \"storage.get\" || op === \"storage.set\") {\n // chrome.* storage is callback-only on Gecko and older Chromium.\n // Prefer promisified browser.*, then fall back to the callback shape.\n var storageNS = (g.browser && g.browser.storage) ? g.browser.storage : chrome.storage;\n var storageArea = storageNS && storageNS[args.area || \"local\"];\n if (!storageArea) { replyErr(cmdId, \"StorageError\", \"storage.\" + (args.area || \"local\") + \" unavailable\"); return; }\n var isSet = op === \"storage.set\";\n var callArgs = isSet ? [args.items || {}] : [args.key != null ? args.key : null];\n var onStorageOk = function (r) { replyOk(cmdId, isSet ? {set: Object.keys(args.items || {})} : r); };\n var onStorageErr = function (e) { replyErr(cmdId, \"StorageError\", (e && e.message) || String(e)); };\n var storageFn = isSet ? storageArea.set : storageArea.get;\n try {\n var storageRet = storageFn.apply(storageArea, callArgs);\n if (storageRet && typeof storageRet.then === \"function\") {\n storageRet.then(onStorageOk, onStorageErr);\n return;\n }\n } catch (e) { /* not thenable / threw synchronously: fall back to callback */ }\n try {\n storageFn.apply(storageArea, callArgs.concat([function (r) {\n var le = chrome.runtime && chrome.runtime.lastError;\n if (le) onStorageErr(le); else onStorageOk(r);\n }]));\n } catch (e) { onStorageErr(e); }\n return;\n }\n if (op === \"reload\") {\n if (ctx === \"background\") {\n replyOk(cmdId, {reloading: true});\n setTimeout(function () { try { chrome.runtime.reload(); } catch (e) {\n // Ignore\n } }, 50);\n } else if (target.tabId) {\n nsCall(\"tabs\", \"reload\", [target.tabId], function (err) {\n if (err) replyErr(cmdId, \"ReloadError\", (err && err.message) || err);\n else replyOk(cmdId, {reloaded: target.tabId});\n });\n } else {\n replyErr(cmdId, \"Unsupported\", \"reload needs background or a tabId\");\n }\n return;\n }\n if (op === \"open\") {\n var surface = args.surface || ctx;\n // getPopup is promise-style on Gecko and (MV3) Chromium; fall back to\n // callback-style for older Chromium. Always resolves to a string.\n var getActionPopup = function (cb) {\n try {\n var r = chrome.action && chrome.action.getPopup && chrome.action.getPopup({});\n if (r && typeof r.then === \"function\") {\n r.then(function (p) { cb(p || \"\"); }, function () { cb(\"\"); });\n return;\n }\n } catch (e) {\n // Ignore\n }\n try { chrome.action.getPopup({}, function (p) { cb(p || \"\"); }); }\n catch (e) { cb(\"\"); }\n };\n var resolveActiveTab = function (a, cb) {\n if (a && typeof a.tabId === \"number\") {\n try { chrome.tabs.get(a.tabId, function (t) { cb(t || {id: a.tabId}); }); return; }\n catch (e) {\n // Ignore\n }\n }\n try { chrome.tabs.query({active: true, lastFocusedWindow: true}, function (tabs) { cb((tabs && tabs[0]) || undefined); }); }\n catch (e) { cb(undefined); }\n };\n // Replaying a listener carries no user gesture, so activeTab is never\n // granted. Warn when the manifest declares it.\n var activeTabWarning = function () {\n try {\n var m = chrome.runtime.getManifest();\n var perms = (m && m.permissions) || [];\n if (perms.indexOf(\"activeTab\") !== -1) {\n return \"replayed without a user gesture: activeTab is NOT granted, so APIs that depend on it (scripting on the active tab, captureVisibleTab) behave differently than a real click\";\n }\n } catch (e) {\n // Ignore\n }\n return null;\n };\n if (surface === \"popup\") {\n if (chrome.action && chrome.action.openPopup) {\n nsCall(\"action\", \"openPopup\", [], function (err) {\n if (err) {\n var openMsg = (err && err.message) || err;\n replyErr(cmdId, \"Unsupported\", \"openPopup: \" + openMsg, openRefusalCode(openMsg));\n } else replyOk(cmdId, {opened: \"popup\"});\n });\n } else { replyErr(cmdId, \"Unsupported\", \"action.openPopup not available\", \"api_unavailable\"); }\n } else if (surface === \"options\") {\n try { chrome.runtime.openOptionsPage(function () { replyOk(cmdId, {opened: \"options\"}); }); }\n catch (e) { replyErr(cmdId, \"Unsupported\", \"openOptionsPage: \" + e); }\n } else if (surface === \"sidebar\") {\n if (chrome.sidePanel && chrome.sidePanel.open && chrome.windows) {\n chrome.windows.getCurrent(function (w) {\n nsCall(\"sidePanel\", \"open\", [{windowId: w.id}], function (err) {\n if (err) {\n var sideMsg = (err && err.message) || err;\n replyErr(cmdId, \"Unsupported\", \"sidePanel.open: \" + sideMsg, openRefusalCode(sideMsg));\n } else replyOk(cmdId, {opened: \"sidebar\"});\n });\n });\n } else { replyErr(cmdId, \"Unsupported\", \"sidePanel not available (engine: \" + engineName() + \")\", \"api_unavailable\"); }\n } else if (surface === \"action\") {\n // With a default_popup the click opens it; without one, replay the\n // onClicked listeners captured at install time.\n if (chrome.action) {\n getActionPopup(function (popup) {\n if (popup) {\n nsCall(\"action\", \"openPopup\", [], function (err) {\n if (err) {\n var actMsg = (err && err.message) || err;\n replyErr(cmdId, \"Unsupported\", \"openPopup: \" + actMsg, openRefusalCode(actMsg));\n } else replyOk(cmdId, {triggered: \"popup\"});\n });\n } else if (actionClickedListeners.length) {\n resolveActiveTab(args, function (tab) {\n var fired = 0;\n for (var i = 0; i < actionClickedListeners.length; i++) {\n try { actionClickedListeners[i](tab); fired++; } catch (e) {\n // Ignore\n }\n }\n var reply = {triggered: \"onClicked\", listeners: fired, gesture: false};\n var warning = activeTabWarning();\n if (warning) reply.warning = warning;\n replyOk(cmdId, reply);\n });\n } else {\n replyErr(cmdId, \"Unsupported\", \"action has no popup and no onClicked listener registered\");\n }\n });\n } else { replyErr(cmdId, \"Unsupported\", \"chrome.action not available (engine: \" + engineName() + \")\", \"api_unavailable\"); }\n } else if (surface === \"command\") {\n var commandName = (args && args.name) || undefined;\n if (!commandListeners.length) {\n replyErr(cmdId, \"Unsupported\", \"no chrome.commands.onCommand listener registered\");\n } else {\n resolveActiveTab(args, function (tab) {\n var fired = 0;\n for (var i = 0; i < commandListeners.length; i++) {\n try { commandListeners[i](commandName, tab); fired++; } catch (e) {\n // Ignore\n }\n }\n replyOk(cmdId, {triggered: \"command\", command: commandName || null, listeners: fired, gesture: false});\n });\n }\n } else { replyErr(cmdId, \"BadRequest\", \"unknown surface: \" + surface); }\n return;\n }\n if (op === \"tabs.query\") {\n nsCall(\"tabs\", \"query\", [args || {}], function (err, tabs) {\n if (err) { replyErr(cmdId, \"TabsError\", (err && err.message) || err); return; }\n replyOk(cmdId, (tabs || []).map(function (t) { return {id: t.id, url: t.url, title: t.title, active: t.active, windowId: t.windowId}; }));\n });\n return;\n }\n if (op === \"inspect\") {\n // Extract a DOM snapshot from the target page via chrome.scripting\n // (CDP-free). Closed shadow roots need CDP; here we read open ones.\n if ((ctx === \"content\" || ctx === \"page\") && target.tabId && chrome.scripting) {\n var maxBytes = (args && args.maxBytes) || 262144;\n var includeHtml = !args || !args.include || args.include.indexOf(\"html\") !== -1;\n nsCall(\"scripting\", \"executeScript\", [{\n target: {tabId: target.tabId},\n world: ctx === \"page\" ? \"MAIN\" : \"ISOLATED\",\n func: function (wantHtml, cap) {\n function countShadow(root) {\n var n = 0, els = root.querySelectorAll(\"*\");\n for (var i = 0; i < els.length; i++) { if (els[i].shadowRoot) { n++; n += countShadow(els[i].shadowRoot); } }\n return n;\n }\n var doc = document;\n var roots = doc.querySelectorAll('#extension-root,[data-extension-root]');\n var out = {\n url: location.href,\n title: doc.title,\n summary: {\n htmlLength: doc.documentElement.outerHTML.length,\n scriptCount: doc.querySelectorAll(\"script\").length,\n styleCount: doc.querySelectorAll(\"style,link[rel=stylesheet]\").length,\n extensionRootCount: roots.length,\n openShadowRoots: countShadow(doc),\n bodyChildCount: doc.body ? doc.body.children.length : 0\n }\n };\n if (wantHtml) {\n var html = doc.documentElement.outerHTML;\n if (cap > 0 && html.length > cap) { out.html = html.slice(0, cap); out.htmlTruncated = true; }\n else { out.html = html; }\n }\n return out;\n },\n args: [includeHtml, maxBytes]\n }], function (err, res) {\n if (err) { replyErr(cmdId, \"TargetNotFound\", (err && err.message) || err); return; }\n var snap = res && res[0] ? res[0].result : undefined;\n if (snap == null) { replyErr(cmdId, \"TargetNotFound\", \"no injectable frame returned a snapshot for tab \" + target.tabId + \" (restricted page, or outside host_permissions)\"); return; }\n replyOk(cmdId, snap);\n });\n } else if (ctx === \"popup\" || ctx === \"options\" || ctx === \"sidebar\" || ctx === \"devtools\" || ctx === \"newtab\" || ctx === \"history\" || ctx === \"bookmarks\") {\n // The SW can't read a surface page's DOM; ask the surface's own\n // in-bundle relay (only the open, matching-context page responds).\n chrome.runtime.sendMessage(\n {__extjsInspectRequest: true, target: target, args: args},\n function (resp) {\n if (chrome.runtime.lastError || !resp) {\n replyErr(cmdId, \"Unsupported\", \"surface '\" + ctx + \"' is not open (open it first: extension open \" + ctx + \")\", \"surface_not_open\");\n } else if (resp.ok) {\n replyOk(cmdId, resp.value);\n } else {\n replyErr(cmdId, (resp.error && resp.error.name) || \"InspectError\", (resp.error && resp.error.message) || \"inspect failed\");\n }\n }\n );\n } else if (ctx === \"background\") {\n replyErr(cmdId, \"Unsupported\", \"the service worker has no DOM; inspect a content/page (with --tab) or an open surface\");\n } else {\n replyErr(cmdId, \"Unsupported\", \"inspect of \" + ctx + \" requires a tabId (content/page) or an open surface\");\n }\n return;\n }\n replyErr(cmdId, \"BadRequest\", \"unknown op: \" + op);\n } catch (e) {\n replyErr(cmdId, \"ExecutorError\", e);\n }\n }\n\n function noopLastError() { try { void g.chrome.runtime.lastError; } catch (e) {\n // Ignore\n } }\n\n // Only http(s)/file/ftp tabs can run a content script; skip chrome://, the\n // extension's own pages, about:blank, etc.\n function isInjectableUrl(url) {\n return typeof url === \"string\" && /^(https?|file|ftp):/i.test(url);\n }\n\n // Re-inject one declared entry's fresh files into every matching open tab.\n // exclude_matches MUST be honored: query the excludes and subtract them.\n function reinjectContentScriptEntry(entry) {\n var chrome = g.chrome;\n var matches = (entry && entry.matches) || [];\n if (!Array.isArray(matches) || !matches.length) return;\n var excludeMatches = (entry && entry.exclude_matches) || [];\n var jsFiles = ((entry && entry.js) || []).filter(function (f) { return typeof f === \"string\"; });\n var cssFiles = ((entry && entry.css) || []).filter(function (f) { return typeof f === \"string\"; });\n if (!jsFiles.length && !cssFiles.length) return;\n var world = entry.world === \"MAIN\" ? \"MAIN\" : \"ISOLATED\";\n var allFrames = !!entry.all_frames;\n function injectInto(excludedTabIds) {\n try {\n chrome.tabs.query({url: matches}, function (tabs) {\n var err = null;\n try { err = chrome.runtime.lastError; } catch (e) {\n // Ignore\n }\n if (err || !tabs) return;\n for (var i = 0; i < tabs.length; i++) {\n (function (tab) {\n if (!tab || tab.id == null || !isInjectableUrl(tab.url)) return;\n if (excludedTabIds[tab.id]) return;\n var target = {tabId: tab.id, allFrames: allFrames};\n if (cssFiles.length && chrome.scripting.insertCSS) {\n try { chrome.scripting.insertCSS({target: target, files: cssFiles}, noopLastError); } catch (e) {\n // Ignore\n }\n }\n if (jsFiles.length && chrome.scripting.executeScript) {\n try {\n chrome.scripting.executeScript(\n {target: target, files: jsFiles, world: world, injectImmediately: true},\n noopLastError\n );\n } catch (e) {\n // Ignore\n }\n }\n })(tabs[i]);\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n if (Array.isArray(excludeMatches) && excludeMatches.length) {\n try {\n chrome.tabs.query({url: excludeMatches}, function (excludedTabs) {\n try { void chrome.runtime.lastError; } catch (e) {\n // Ignore\n }\n var excluded = {};\n if (excludedTabs) {\n for (var i = 0; i < excludedTabs.length; i++) {\n if (excludedTabs[i] && excludedTabs[i].id != null) excluded[excludedTabs[i].id] = true;\n }\n }\n injectInto(excluded);\n });\n return;\n } catch (e) {\n // Ignore\n }\n }\n injectInto({});\n }\n\n // Re-inject all content scripts into their open tabs. Reads the manifest\n // FROM DISK: getManifest() is frozen and dev filenames are content-hashed.\n function reinjectContentScripts(onDone) {\n var chrome = g.chrome;\n try {\n if (typeof g.fetch !== \"function\" || !chrome.scripting) return false;\n g.fetch(chrome.runtime.getURL(\"manifest.json\"), {cache: \"no-store\"})\n .then(function (r) { return r.json(); })\n .then(function (manifest) {\n var entries = (manifest && manifest.content_scripts) || [];\n for (var i = 0; i < entries.length; i++) reinjectContentScriptEntry(entries[i]);\n reregisterForFutureNavigations(entries);\n if (onDone) { try { onDone(); } catch (e) {\n // Ignore\n } }\n })\n .catch(function () {\n // Ignore\n });\n return true;\n } catch (e) { return false; }\n }\n\n function mapRunAt(runAt) {\n if (runAt === \"document_start\") return \"document_start\";\n if (runAt === \"document_end\") return \"document_end\";\n return \"document_idle\";\n }\n\n // Re-register content scripts dynamically at the fresh files, so tabs\n // opened AFTER an edit also get the new build. Idempotent per entry id.\n function reregisterForFutureNavigations(entries) {\n var chrome = g.chrome;\n if (\n !chrome.scripting ||\n !chrome.scripting.registerContentScripts ||\n !chrome.scripting.getRegisteredContentScripts\n ) return;\n\n var scripts = [];\n for (var i = 0; i < entries.length; i++) {\n var e = entries[i] || {};\n if (!Array.isArray(e.matches) || !e.matches.length) continue;\n var js = (e.js || []).filter(function (f) { return typeof f === \"string\"; });\n var css = (e.css || []).filter(function (f) { return typeof f === \"string\"; });\n if (!js.length && !css.length) continue;\n var s = {\n id: \"extjs-dev-cs-\" + i,\n matches: e.matches,\n runAt: mapRunAt(e.run_at),\n allFrames: !!e.all_frames,\n world: e.world === \"MAIN\" ? \"MAIN\" : \"ISOLATED\"\n };\n // Dev registration must not be BROADER than the static one: dropping\n // exclude_matches injects into pages the browser itself would skip.\n if (Array.isArray(e.exclude_matches) && e.exclude_matches.length) {\n s.excludeMatches = e.exclude_matches;\n }\n if (js.length) s.js = js;\n if (css.length) s.css = css;\n scripts.push(s);\n }\n if (!scripts.length) return;\n\n try {\n chrome.scripting.getRegisteredContentScripts(function (existing) {\n try { void chrome.runtime.lastError; } catch (e) {\n // Ignore\n }\n var have = {};\n if (existing) for (var k = 0; k < existing.length; k++) have[existing[k].id] = true;\n var toRegister = [], toUpdate = [];\n for (var j = 0; j < scripts.length; j++) {\n (have[scripts[j].id] ? toUpdate : toRegister).push(scripts[j]);\n }\n if (toRegister.length) {\n try { chrome.scripting.registerContentScripts(toRegister, noopLastError); } catch (e) {\n // Ignore\n }\n }\n if (toUpdate.length) {\n try { chrome.scripting.updateContentScripts(toUpdate, noopLastError); } catch (e) {\n // Ignore\n }\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n\n // Dev-loop reload without the CDP controller: content-scripts re-inject in\n // place into open tabs; service-worker/full/manifest restart the extension.\n function performDevReload(type, onDone) {\n var chrome = g.chrome;\n if (!chrome) return;\n\n var fullReload = function () {\n // Flag a pending reinject for the NEXT producer generation: the\n // boot-time heal is what converges open tabs after a SW/full reload.\n try {\n if (chrome.storage && chrome.storage.local) {\n chrome.storage.local.set({__extjsDevPendingReinject: Date.now()}, noopLastError);\n }\n } catch (e) {\n // Ignore\n }\n // Deferred so in-flight frames and the tab console announcement flush\n // before the SW dies; the devtools companion confirms completion.\n try { setTimeout(function () { try { chrome.runtime.reload(); } catch (e) {\n // Ignore\n } }, 150); } catch (e) {}\n };\n\n if (type === \"content-scripts\" && chrome.scripting && chrome.tabs && chrome.tabs.query) {\n if (reinjectContentScripts(onDone)) return;\n }\n\n fullReload();\n }\n\n // One server-built label travels the ReloadFrame; both announcement\n // surfaces fire HERE, next to the actual reload action, so they stay true.\n\n // Stable IDs of the bundled extension-js-devtools companion: Chromium pins\n // via the manifest \"key\"; Firefox via browser_specific_settings.gecko.id.\n var DEVTOOLS_COMPANION_ID_CHROMIUM = \"kgdaecdpfkikjncaalnmmnjjfpofkcbl\";\n var DEVTOOLS_COMPANION_ID_FIREFOX = \"devtools@extension.js\";\n\n function notifyDevtoolsCompanion(phase, label, kind) {\n try {\n var chrome = g.chrome;\n if (!chrome || !chrome.runtime || typeof chrome.runtime.sendMessage !== \"function\") return;\n var id = engineName() === \"firefox\" ? DEVTOOLS_COMPANION_ID_FIREFOX : DEVTOOLS_COMPANION_ID_CHROMIUM;\n chrome.runtime.sendMessage(\n id,\n {type: \"extjs-dev-reload-state\", phase: phase, label: label || \"\", kind: kind || \"\", instanceId: INSTANCE_ID},\n function () { noopLastError(); }\n );\n } catch (e) {\n // Ignore\n }\n }\n\n // console.log the reload line into every open injectable tab; the patched\n // ISOLATED-world console also lands it in the dev-server log stream.\n function announceReloadInTabs(text) {\n var chrome = g.chrome;\n if (!chrome || !chrome.tabs || !chrome.tabs.query) return;\n try {\n chrome.tabs.query({}, function (tabs) {\n noopLastError();\n if (!tabs) return;\n for (var i = 0; i < tabs.length; i++) {\n (function (tab) {\n if (!tab || tab.id == null || !isInjectableUrl(tab.url)) return;\n if (chrome.scripting && chrome.scripting.executeScript) {\n try {\n chrome.scripting.executeScript(\n {target: {tabId: tab.id}, func: function (t) { console.log(t); }, args: [text]},\n noopLastError\n );\n return;\n } catch (e) {\n // Ignore\n }\n }\n // MV2 fallback (Firefox without the scripting API).\n if (chrome.tabs.executeScript) {\n try {\n chrome.tabs.executeScript(tab.id, {code: \"console.log(\" + JSON.stringify(text) + \");\"}, noopLastError);\n } catch (e) {\n // Ignore\n }\n }\n })(tabs[i]);\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n\n function handleDevReloadFrame(frame) {\n var kind = frame.reloadType || \"full\";\n var label = typeof frame.label === \"string\" ? frame.label : \"\";\n // The server always builds the label; the kind-derived fallback only\n // covers a malformed frame so the announcement stays truthful.\n var fallback = kind === \"content-scripts\" ? \"content_script\"\n : kind === \"service-worker\" ? \"service_worker\"\n : \"extension\";\n var announced = \"[Extension.js] Reloading \" + (label || fallback) + \"\u2026\";\n\n notifyDevtoolsCompanion(\"reloading\", label, kind);\n\n if (kind === \"page\") {\n // Notify-only: rspack-dev-server's livereload refreshes the open\n // surface; reloading the extension here would race it.\n return;\n }\n\n // Delivery ack for the broker: proves this SW's message pump processed\n // the frame (a socket write proves nothing). Sent on receipt, by design.\n send({type: \"reload-ack\", reloadType: kind, label: label});\n\n announceReloadInTabs(announced);\n performDevReload(kind, function () {\n // Only the content-scripts path confirms from here; full/SW reloads\n // are confirmed by the devtools companion's chrome.management listeners.\n notifyDevtoolsCompanion(\"reloaded\", label, kind);\n });\n }\n\n function sanitize(args) {\n var out = [];\n for (var i = 0; i < args.length; i++) {\n var p = args[i];\n try {\n if (typeof p === \"string\") out.push(p.length > 2048 ? p.slice(0, 2048) + \"...\" : p);\n else if (p instanceof Error) out.push(p.name + \": \" + p.message);\n else out.push(JSON.stringify(p));\n } catch (e) {\n out.push(String(p));\n }\n if (out.join(\" \").length > 8192) break;\n }\n return out;\n }\n\n function flush() {\n while (queue.length && open && socket) {\n var f = queue.shift();\n try { socket.send(JSON.stringify(f)); } catch (e) { break; }\n }\n }\n\n function send(frame) {\n if (open && socket) {\n try { socket.send(JSON.stringify(frame)); return; } catch (e) {\n // Ignore\n }\n }\n if (queue.length < MAX_QUEUE) queue.push(frame);\n }\n\n // The baked PORT is a snapshot of an ephemeral port. After a dev-server\n // restart, the port file shipped in the unpacked extension names the\n // live one, and unpacked resources are read from disk on every fetch.\n function refreshControlPort(done) {\n try {\n var runtime = (g.chrome && g.chrome.runtime) || (g.browser && g.browser.runtime);\n if (!runtime || typeof runtime.getURL !== \"function\" || typeof g.fetch !== \"function\") { done(); return; }\n g.fetch(runtime.getURL(\"extension-js-control.json\"), {cache: \"no-store\"})\n .then(function (res) { return res.json(); })\n .then(function (data) {\n var next = data && parseInt(data.port, 10);\n if (next && next > 0 && next < 65536 && next !== PORT) PORT = next;\n done();\n })\n .catch(function () { done(); });\n } catch (e) { done(); }\n }\n\n function schedule() {\n var delay = backoff;\n backoff = Math.min(backoff * 2, MAX_BACKOFF);\n connectFailures++;\n try {\n setTimeout(function () {\n // Two straight failures make the baked port suspect (a restarted\n // server dials out on a new port): re-resolve before re-dialing.\n if (connectFailures >= 2) refreshControlPort(connect);\n else connect();\n }, delay);\n } catch (e) {\n // Ignore\n }\n }\n\n function connect() {\n try {\n socket = new WS(\"ws://\" + HOST + \":\" + PORT + \"/extjs-control\");\n } catch (e) {\n schedule();\n return;\n }\n socket.onopen = function () {\n open = true;\n backoff = 250;\n connectFailures = 0;\n try {\n socket.send(JSON.stringify({type: \"hello\", v: 1, role: \"producer\", instanceId: INSTANCE_ID}));\n } catch (e) {\n // Ignore\n }\n flush();\n };\n socket.onmessage = function (ev) {\n var frame;\n try { frame = JSON.parse(typeof ev.data === \"string\" ? ev.data : \"\"); } catch (e) { return; }\n if (frame && frame.type === \"command\") {\n try { executeCommand(frame); } catch (e) { replyErr(frame.cmdId, \"ExecutorError\", e); }\n } else if (frame && frame.type === \"reload\") {\n // Dev-loop reload broadcast (see broker.broadcastReload).\n // Fire-and-forget: no result frame is expected.\n try { handleDevReloadFrame(frame); } catch (e) {\n // Ignore\n }\n } else if (frame && frame.type === \"ping\") {\n // Server keepalive: merely RECEIVING this resets the MV3 SW's ~30s\n // idle timer (Chrome 116+), keeping it reachable. Nothing to do.\n }\n };\n socket.onclose = function () {\n open = false;\n socket = null;\n schedule();\n };\n socket.onerror = function () {\n try { socket && socket.close(); } catch (e) {\n // Ignore\n }\n };\n }\n\n // Uncaught errors don't route through the patched console; the handlers\n // below forward them, using these signatures to skip already-logged throws.\n var recentErrorSigs = [];\n function errorSig(message, stack) {\n return String(message == null ? \"\" : message) + \"::\" + String(stack == null ? \"\" : stack).slice(0, 200);\n }\n function noteErrorSig(sig) {\n recentErrorSigs.push({sig: sig, t: Date.now()});\n if (recentErrorSigs.length > 50) recentErrorSigs.shift();\n }\n function errorSigSeenRecently(sig) {\n var now = Date.now();\n for (var i = recentErrorSigs.length - 1; i >= 0; i--) {\n if (now - recentErrorSigs[i].t > 3000) { recentErrorSigs.splice(i, 1); continue; }\n if (recentErrorSigs[i].sig === sig) return true;\n }\n return false;\n }\n\n LEVELS.forEach(function (level) {\n var orig = typeof consoleRef[level] === \"function\"\n ? consoleRef[level].bind(consoleRef)\n : function () {};\n consoleRef[level] = function () {\n try {\n if (level === \"error\") {\n for (var ai = 0; ai < arguments.length; ai++) {\n if (arguments[ai] instanceof Error) noteErrorSig(errorSig(arguments[ai].message, arguments[ai].stack));\n }\n }\n send({\n type: \"log\",\n event: {\n v: 1,\n id: nowId(),\n timestamp: Date.now(),\n level: level,\n context: CONTEXT,\n messageParts: sanitize([].slice.call(arguments)),\n runId: INSTANCE_ID\n }\n });\n } catch (e) {\n // Ignore\n }\n return orig.apply(consoleRef, arguments);\n };\n });\n\n // Forward uncaught throws / unhandled rejections as level:\"error\", deduped\n // so a logged-then-rethrown Error emits once.\n function shipUncaughtError(message, stack, url) {\n try {\n var sig = errorSig(message, stack);\n if (errorSigSeenRecently(sig)) return;\n noteErrorSig(sig);\n send({\n type: \"log\",\n event: {\n v: 1,\n id: nowId(),\n timestamp: Date.now(),\n level: \"error\",\n context: CONTEXT,\n messageParts: sanitize([String(message) + (stack ? \"\\n\" + stack : \"\")]),\n url: url,\n runId: INSTANCE_ID\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n try {\n if (typeof g.addEventListener === \"function\") {\n g.addEventListener(\"error\", function (ev) {\n var err = ev && ev.error;\n var message = (err && err.message) || (ev && ev.message) || \"Uncaught error\";\n shipUncaughtError(message, err && err.stack, ev && ev.filename);\n });\n g.addEventListener(\"unhandledrejection\", function (ev) {\n var reason = ev && ev.reason;\n var message = (reason && reason.message) || (reason != null ? String(reason) : \"Unhandled rejection\");\n shipUncaughtError(\"Unhandled promise rejection: \" + message, reason && reason.stack, undefined);\n });\n }\n } catch (e) {\n // Ignore\n }\n\n // Other contexts relay console logs to this SW over a NAMED runtime.Port:\n // they can't open the WS under page CSP, and sendMessage can echo-loop.\n function shipRelayedLog(ev, sender) {\n try {\n send({\n type: \"log\",\n event: {\n v: 1,\n id: nowId(),\n timestamp: Date.now(),\n level: ev.level || \"log\",\n context: ev.context || \"content\",\n messageParts: Array.isArray(ev.messageParts) ? ev.messageParts : [],\n url: ev.url || (sender ? sender.url : undefined),\n tabId: sender && sender.tab ? sender.tab.id : undefined,\n frameId: sender ? sender.frameId : undefined,\n runId: INSTANCE_ID\n }\n });\n } catch (e) {\n // Ignore\n }\n }\n try {\n var rtPort = g.chrome;\n if (rtPort && rtPort.runtime && rtPort.runtime.onConnect) {\n rtPort.runtime.onConnect.addListener(function (port) {\n if (!port || port.name !== \"__extjs-bridge-log__\") return;\n try {\n port.onMessage.addListener(function (msg) {\n if (!msg || !msg.__extjsBridgeLog) return;\n shipRelayedLog(msg.__extjsBridgeLog, port.sender);\n });\n } catch (e) {\n // Ignore\n }\n });\n }\n } catch (e) {\n // Ignore\n }\n // Legacy sendMessage path: kept for any surface still relaying the old way\n // (harmless one-predicate listener; new relays never use it).\n try {\n var rt = g.chrome;\n if (rt && rt.runtime && rt.runtime.onMessage) {\n rt.runtime.onMessage.addListener(function (msg, sender) {\n if (!msg || !msg.__extjsBridgeLog) return;\n shipRelayedLog(msg.__extjsBridgeLog, sender);\n });\n }\n } catch (e) {\n // Ignore\n }\n\n // Chrome never injects manifest content scripts into already-open tabs, so\n // fire one reinject on onInstalled (which skips idle-stop SW wakes).\n try {\n var rtBoot = g.chrome;\n if (rtBoot && rtBoot.runtime && rtBoot.runtime.onInstalled) {\n rtBoot.runtime.onInstalled.addListener(function () {\n try {\n setTimeout(function () {\n try { reinjectContentScripts(); } catch (e) {\n // Ignore\n }\n }, 250);\n } catch (e) {\n // Ignore\n }\n });\n }\n } catch (e) {\n // Ignore\n }\n\n // runtime.reload() does NOT fire onInstalled (verified Chromium 146), so\n // consume the pre-reload storage flag here (fresh only) to heal open tabs.\n try {\n var stBoot = g.chrome;\n if (stBoot && stBoot.storage && stBoot.storage.local) {\n stBoot.storage.local.get(\"__extjsDevPendingReinject\", function (res) {\n noopLastError();\n var ts = res && res.__extjsDevPendingReinject;\n if (ts == null) return;\n try { stBoot.storage.local.remove(\"__extjsDevPendingReinject\", noopLastError); } catch (e) {\n // Ignore\n }\n if (typeof ts !== \"number\" || Date.now() - ts > 30000) return;\n setTimeout(function () {\n try { reinjectContentScripts(); } catch (e) {\n // Ignore\n }\n }, 250);\n });\n }\n } catch (e) {\n // Ignore\n }\n\n connect();\n } catch (e) {\n // Ignore\n }\n})();\n";
|
|
2
3
|
export declare const BRIDGE_RELAY_SOURCE = ";(function () {\n try {\n var g = (typeof globalThis === \"object\" && globalThis) ? globalThis : this;\n if (!g || g.__extjsBridgeRelayInstalled) return;\n\n var CONTEXT = \"__EXTJS_CONTEXT__\";\n var chrome = g.chrome;\n if (!chrome || !chrome.runtime) return;\n var canRelay = typeof chrome.runtime.connect === \"function\";\n\n g.__extjsBridgeRelayInstalled = true;\n var consoleRef = g.console || {};\n var LEVELS = [\"log\", \"info\", \"warn\", \"error\", \"debug\", \"trace\"];\n\n function sanitize(args) {\n var out = [];\n for (var i = 0; i < args.length; i++) {\n var p = args[i];\n try {\n if (typeof p === \"string\") out.push(p.length > 2048 ? p.slice(0, 2048) + \"...\" : p);\n else if (p instanceof Error) out.push(p.name + \": \" + p.message);\n else out.push(JSON.stringify(p));\n } catch (e) { out.push(String(p)); }\n if (out.join(\" \").length > 8192) break;\n }\n return out;\n }\n\n function here() { try { return g.location ? g.location.href : undefined; } catch (e) { return undefined; } }\n\n // Lazy named port to the SW producer: connecting wakes an idle SW, but\n // port frames never reach the extension's own onMessage listeners.\n var logPort = null;\n function getLogPort() {\n if (!canRelay) return null;\n if (logPort) return logPort;\n try {\n logPort = chrome.runtime.connect({name: \"__extjs-bridge-log__\"});\n logPort.onDisconnect.addListener(function () {\n try { void chrome.runtime.lastError; } catch (e) {\n // Ignore\n }\n logPort = null;\n });\n } catch (e) { logPort = null; }\n return logPort;\n }\n\n // Relay one log payload to the SW producer over the named port, redialing\n // once if the port went stale (SW restarted).\n function postLog(payload) {\n var p = getLogPort();\n if (!p) return;\n try {\n p.postMessage({__extjsBridgeLog: payload});\n } catch (e) {\n logPort = null;\n var p2 = getLogPort();\n if (p2) { try { p2.postMessage({__extjsBridgeLog: payload}); } catch (e2) {\n // Ignore\n } }\n }\n }\n\n // Uncaught throws / unhandled rejections never route through the patched\n // console; forward them, deduped against console.error Error signatures.\n var recentErrorSigs = [];\n function errorSig(message, stack) {\n return String(message == null ? \"\" : message) + \"::\" + String(stack == null ? \"\" : stack).slice(0, 200);\n }\n function noteErrorSig(sig) {\n recentErrorSigs.push({sig: sig, t: Date.now()});\n if (recentErrorSigs.length > 50) recentErrorSigs.shift();\n }\n function errorSigSeenRecently(sig) {\n var now = Date.now();\n for (var i = recentErrorSigs.length - 1; i >= 0; i--) {\n if (now - recentErrorSigs[i].t > 3000) { recentErrorSigs.splice(i, 1); continue; }\n if (recentErrorSigs[i].sig === sig) return true;\n }\n return false;\n }\n\n LEVELS.forEach(function (level) {\n var orig = typeof consoleRef[level] === \"function\" ? consoleRef[level].bind(consoleRef) : function () {};\n consoleRef[level] = function () {\n try {\n if (level === \"error\") {\n for (var ai = 0; ai < arguments.length; ai++) {\n if (arguments[ai] instanceof Error) noteErrorSig(errorSig(arguments[ai].message, arguments[ai].stack));\n }\n }\n postLog({level: level, context: CONTEXT, messageParts: sanitize([].slice.call(arguments)), url: here()});\n } catch (e) {\n // Ignore\n }\n return orig.apply(consoleRef, arguments);\n };\n });\n\n function shipUncaughtError(message, stack, url) {\n try {\n var sig = errorSig(message, stack);\n if (errorSigSeenRecently(sig)) return;\n noteErrorSig(sig);\n postLog({level: \"error\", context: CONTEXT, messageParts: sanitize([String(message) + (stack ? \"\\n\" + stack : \"\")]), url: url || here()});\n } catch (e) {\n // Ignore\n }\n }\n try {\n if (typeof g.addEventListener === \"function\") {\n g.addEventListener(\"error\", function (ev) {\n var err = ev && ev.error;\n var message = (err && err.message) || (ev && ev.message) || \"Uncaught error\";\n shipUncaughtError(message, err && err.stack, (ev && ev.filename) || undefined);\n });\n g.addEventListener(\"unhandledrejection\", function (ev) {\n var reason = ev && ev.reason;\n var message = (reason && reason.message) || (reason != null ? String(reason) : \"Unhandled rejection\");\n shipUncaughtError(\"Unhandled promise rejection: \" + message, reason && reason.stack, undefined);\n });\n }\n } catch (e) {\n // Ignore\n }\n\n // The SW executor can't reach another extension page's DOM or eval there,\n // so THIS surface answers inspect/eval requests for its own context.\n try {\n if (chrome.runtime && chrome.runtime.onMessage) {\n chrome.runtime.onMessage.addListener(function (msg, _sender, sendResponse) {\n if (!msg || !msg.__extjsEvalRequest) return;\n if (!msg.target || msg.target.context !== CONTEXT) return; // not for me\n try {\n var value = (0, eval)(String((msg.args && msg.args.expression) || \"\"));\n try { sendResponse({ok: true, value: value}); }\n catch (eSend) { sendResponse({ok: true, value: String(value)}); }\n } catch (e) {\n var emsg = (e && e.message) || String(e);\n if (/Content Security Policy|unsafe-eval|call to eval/i.test(emsg)) {\n sendResponse({ok: false, error: {name: \"Unsupported\", message: \"eval of a string is blocked in the \" + CONTEXT + \" page by the MV3 extension CSP. Use extension inspect \" + CONTEXT + \" to read its DOM, or --context background on an MV2/Firefox build. Original: \" + emsg}});\n } else {\n sendResponse({ok: false, error: {name: (e && e.name) || \"EvalError\", message: emsg}});\n }\n }\n return true; // responded\n });\n }\n } catch (e) {\n // Ignore\n }\n\n try {\n if (chrome.runtime && chrome.runtime.onMessage) {\n chrome.runtime.onMessage.addListener(function (msg, _sender, sendResponse) {\n if (!msg || !msg.__extjsInspectRequest) return;\n if (!msg.target || msg.target.context !== CONTEXT) return; // not for me\n try {\n var args = msg.args || {};\n var wantHtml = !args.include || args.include.indexOf(\"html\") !== -1;\n var cap = args.maxBytes || 262144;\n function countShadow(root) {\n var n = 0, els = root.querySelectorAll(\"*\");\n for (var i = 0; i < els.length; i++) { if (els[i].shadowRoot) { n++; n += countShadow(els[i].shadowRoot); } }\n return n;\n }\n var doc = g.document;\n var roots = doc.querySelectorAll('#extension-root,[data-extension-root]');\n var snap = {\n context: CONTEXT,\n url: here(),\n title: doc.title,\n summary: {\n htmlLength: doc.documentElement.outerHTML.length,\n scriptCount: doc.querySelectorAll(\"script\").length,\n styleCount: doc.querySelectorAll(\"style,link[rel=stylesheet]\").length,\n extensionRootCount: roots.length,\n openShadowRoots: countShadow(doc),\n bodyChildCount: doc.body ? doc.body.children.length : 0\n }\n };\n if (wantHtml) {\n var html = doc.documentElement.outerHTML;\n if (cap > 0 && html.length > cap) { snap.html = html.slice(0, cap); snap.htmlTruncated = true; }\n else { snap.html = html; }\n }\n sendResponse({ok: true, value: snap});\n } catch (e) {\n sendResponse({ok: false, error: {name: \"InspectError\", message: String(e)}});\n }\n return true; // responded\n });\n }\n } catch (e) {\n // Ignore\n }\n } catch (e) {\n // Ignore\n }\n})();\n";
|
|
3
4
|
export interface BuildRelayOptions {
|
|
4
5
|
context: string;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
2
|
import node_fs from "node:fs";
|
|
3
3
|
import node_path from "node:path";
|
|
4
|
-
import { parse } from "es-module-lexer
|
|
4
|
+
import { initSync, parse } from "es-module-lexer";
|
|
5
5
|
import { validate } from "schema-utils";
|
|
6
6
|
import { reservedScriptsFolder } from "./266.mjs";
|
|
7
7
|
import { stripBom } from "./23.mjs";
|
|
8
8
|
import { canonicalizeDir, canonicalizeResourcePath } from "./93.mjs";
|
|
9
9
|
import { findNearestProjectManifestSync } from "./80.mjs";
|
|
10
10
|
import { getCanonicalContentScriptEntryName, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX } from "./291.mjs";
|
|
11
|
+
initSync();
|
|
11
12
|
const schema = {
|
|
12
13
|
type: 'object',
|
|
13
14
|
properties: {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
2
|
import node_fs from "node:fs";
|
|
3
3
|
import node_path from "node:path";
|
|
4
|
-
import { parse } from "es-module-lexer
|
|
4
|
+
import { initSync, parse } from "es-module-lexer";
|
|
5
5
|
import { validate } from "schema-utils";
|
|
6
6
|
import { reservedScriptsFolder } from "./266.mjs";
|
|
7
7
|
import { stripBom } from "./23.mjs";
|
|
8
8
|
import { canonicalizeDir, canonicalizeResourcePath } from "./93.mjs";
|
|
9
9
|
import { findNearestProjectManifestSync } from "./80.mjs";
|
|
10
10
|
import { getCanonicalContentScriptEntryName, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX } from "./291.mjs";
|
|
11
|
+
initSync();
|
|
11
12
|
const schema = {
|
|
12
13
|
type: 'object',
|
|
13
14
|
properties: {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const DIST_STAGING_PREFIX = ".extension-build-";
|
|
2
|
+
export declare function stagingDistPathFor(distPath: string): string;
|
|
3
|
+
export declare function removeStaleStagingDirs(distPath: string): void;
|
|
4
|
+
export declare function removeStagingDir(stagingPath: string): void;
|
|
5
|
+
export declare function promoteStagingDist(stagingPath: string, distPath: string): void;
|