extension-develop 4.1.39 → 4.1.40-canary.459.2c1ba7b

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.
Files changed (210) hide show
  1. package/README.md +13 -10
  2. package/dist/{771~0.mjs → 5h~0.mjs} +13 -3
  3. package/dist/{273~0.mjs → 6l~0.mjs} +1 -1
  4. package/dist/{524~0.mjs → 9~0.mjs} +18 -2
  5. package/dist/{640~0.mjs → bh~0.mjs} +6 -1
  6. package/dist/bridge.mjs +14 -8
  7. package/dist/b~0.mjs +8644 -0
  8. package/dist/command-dev.d.ts +2 -0
  9. package/dist/command-preview.d.ts +2 -0
  10. package/dist/contracts.mjs +2 -1
  11. package/dist/{469~0.mjs → cp~0.mjs} +66 -17
  12. package/dist/css-parse-guard-loader.mjs +2 -2
  13. package/dist/c~0.mjs +56 -0
  14. package/dist/dead-css-url-loader.mjs +20 -119
  15. package/dist/dev-server/control-bridge/actions-file.d.ts +7 -0
  16. package/dist/dev-server/control-bridge/broker.d.ts +42 -2
  17. package/dist/dev-server/control-bridge/consumer-client.d.ts +7 -0
  18. package/dist/dev-server/control-bridge/contracts.d.ts +29 -1
  19. package/dist/dev-server/control-bridge/logs-file.d.ts +6 -0
  20. package/dist/dev-server/control-bridge/loopback.d.ts +1 -0
  21. package/dist/dev-server/control-bridge/producer-runtime.d.ts +5 -2
  22. package/dist/dev-server/control-bridge/production-control.d.ts +1 -0
  23. package/dist/dev-server/control-bridge/session-token.d.ts +5 -2
  24. package/dist/dev-server/cors.d.ts +4 -2
  25. package/dist/dev-server/messages.d.ts +6 -0
  26. package/dist/dev-server/session-restart.d.ts +3 -1
  27. package/dist/dev-server~0.mjs +71 -129
  28. package/dist/df~0.mjs +197 -0
  29. package/dist/{846~0.mjs → d~0.mjs} +4 -3
  30. package/dist/ensure-hmr-for-scripts.js +3 -3
  31. package/dist/ensure-hmr-for-scripts.mjs +3 -3
  32. package/dist/extension-js-devtools/build-stamp.json +2 -2
  33. package/dist/extension-js-devtools/chrome/background/service_worker.js +2 -2
  34. package/dist/extension-js-devtools/chrome/pages/welcome.js +2 -2
  35. package/dist/extension-js-devtools/chromium/background/service_worker.js +2 -2
  36. package/dist/extension-js-devtools/chromium/pages/welcome.js +2 -2
  37. package/dist/extension-js-devtools/edge/background/service_worker.js +2 -2
  38. package/dist/extension-js-devtools/edge/pages/welcome.js +2 -2
  39. package/dist/extension-js-devtools/firefox/background/scripts.js +2 -2
  40. package/dist/extension-js-devtools/firefox/pages/welcome.js +2 -2
  41. package/dist/extension-js-theme/build-stamp.json +2 -2
  42. package/dist/{143~0.mjs → ey~0.mjs} +2 -2
  43. package/dist/e~0.mjs +33 -0
  44. package/dist/feature-scripts-classic-traced-globals-loader.mjs +7 -2
  45. package/dist/feature-scripts-content-script-wrapper.js +56 -18
  46. package/dist/feature-scripts-content-script-wrapper.mjs +56 -18
  47. package/dist/feature-scripts-native-geturl-import-loader.mjs +1 -1
  48. package/dist/{105~0.mjs → g0~0.mjs} +1 -1
  49. package/dist/{88~0.mjs → j6~0.mjs} +9 -1
  50. package/dist/{731~0.mjs → j~0.mjs} +2 -2
  51. package/dist/{712~0.mjs → ka~0.mjs} +18 -2
  52. package/dist/{852~0.mjs → k~0.mjs} +4 -2
  53. package/dist/late-css-import-loader.mjs +1 -1
  54. package/dist/lib/addon-lint.d.ts +6 -0
  55. package/dist/lib/build-summary.d.ts +6 -0
  56. package/dist/lib/dev-additions.d.ts +12 -0
  57. package/dist/lib/extension-base-from-stack.d.ts +16 -0
  58. package/dist/lib/localized-manifest-name.d.ts +9 -0
  59. package/dist/lib/manifest-types.d.ts +276 -0
  60. package/dist/lib/messages.d.ts +6 -2
  61. package/dist/lib/process-started-at.d.ts +1 -0
  62. package/dist/lib/real-path.d.ts +8 -0
  63. package/dist/lib/resource-path.d.ts +1 -0
  64. package/dist/lib/session-paths.d.ts +2 -0
  65. package/dist/lib/split-chunks.d.ts +2 -1
  66. package/dist/lib/stats-handler.d.ts +1 -0
  67. package/dist/lib/tsconfig-includes-file.d.ts +1 -0
  68. package/dist/l~0.mjs +2290 -0
  69. package/dist/main-world-bridge.js +92 -23
  70. package/dist/main-world-bridge.mjs +92 -23
  71. package/dist/manifest-entry.d.ts +2 -0
  72. package/dist/manifest.mjs +3 -1
  73. package/dist/module.mjs +3 -3
  74. package/dist/{832~0.mjs → m~0.mjs} +2244 -288
  75. package/dist/o~0.mjs +47 -0
  76. package/dist/plugin-browsers/index.d.ts +7 -0
  77. package/dist/plugin-browsers/safari-dev-plugin.d.ts +2 -0
  78. package/dist/plugin-compatibility/compatibility-lib/messages.d.ts +5 -1
  79. package/dist/plugin-compatibility/compatibility-lib/native-browser-namespace.d.ts +5 -0
  80. package/dist/plugin-compatibility/feature-browser-global.d.ts +11 -1
  81. package/dist/plugin-compatibility/index.d.ts +2 -0
  82. package/dist/plugin-compilation/compilation-lib/messages.d.ts +4 -1
  83. package/dist/plugin-compilation/env.d.ts +1 -0
  84. package/dist/plugin-compilation/index.d.ts +2 -0
  85. package/dist/plugin-compilation/node-builtins.d.ts +5 -0
  86. package/dist/plugin-compilation/one-diagnostic-per-location.d.ts +13 -0
  87. package/dist/plugin-compilation/resolve-file-requests.d.ts +16 -0
  88. package/dist/plugin-compilation/warm-ancestor-watchers.d.ts +19 -0
  89. package/dist/plugin-compilation/watch-real-project-path.d.ts +27 -0
  90. package/dist/plugin-compilation/zip.d.ts +2 -0
  91. package/dist/plugin-css/css-in-content-script-loader.d.ts +1 -1
  92. package/dist/plugin-css/css-lib/build-css-rules.d.ts +3 -0
  93. package/dist/plugin-css/css-lib/inline-content-script-css.d.ts +3 -1
  94. package/dist/plugin-css/css-lib/messages.d.ts +4 -0
  95. package/dist/plugin-css/css-lib/sfc-style-block.d.ts +26 -0
  96. package/dist/plugin-css/css-lib/unplaced-style-imports.d.ts +7 -0
  97. package/dist/plugin-css/css-lib/verbatim-css.d.ts +1 -0
  98. package/dist/plugin-css/dead-css-url-loader.d.ts +9 -1
  99. package/dist/plugin-css/index.d.ts +1 -0
  100. package/dist/plugin-css/sfc-style-block-loader.d.ts +18 -0
  101. package/dist/plugin-css/unplaced-style-import-loader.d.ts +16 -0
  102. package/dist/plugin-playwright/index.d.ts +22 -0
  103. package/dist/plugin-reload/classify-reload.d.ts +20 -0
  104. package/dist/plugin-reload/index.d.ts +4 -2
  105. package/dist/plugin-reload/messages.d.ts +1 -0
  106. package/dist/plugin-reload/reload-dispatch.d.ts +21 -2
  107. package/dist/plugin-reload/reload-lib/dev-content-scripts.d.ts +6 -0
  108. package/dist/plugin-reload/reload-lib/scripts-replay-shim.d.ts +1 -1
  109. package/dist/plugin-reload/steps/inject-bridge-producer.d.ts +6 -0
  110. package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/ChunkLoader.d.ts +3 -0
  111. package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/AutoPublicPath.d.ts +1 -1
  112. package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/BaseUri.d.ts +1 -1
  113. package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/LoadScript.d.ts +1 -1
  114. package/dist/plugin-reload/steps/setup-reload-strategy/webpack-target-webextension-fork/lib/webpack5/RuntimeModules/PublicPath.d.ts +1 -1
  115. package/dist/plugin-special-folders/get-data.d.ts +2 -0
  116. package/dist/plugin-special-folders/hint-import-only-scripts.d.ts +4 -0
  117. package/dist/plugin-special-folders/include-files.d.ts +2 -0
  118. package/dist/plugin-special-folders/messages.d.ts +1 -0
  119. package/dist/plugin-web-extension/feature-html/html-lib/inject.d.ts +1 -1
  120. package/dist/plugin-web-extension/feature-html/html-lib/patch-html.d.ts +1 -0
  121. package/dist/plugin-web-extension/feature-html/steps/update-html-file.d.ts +1 -0
  122. package/dist/plugin-web-extension/feature-icons/extract-action-theme-icons.d.ts +1 -0
  123. package/dist/plugin-web-extension/feature-icons/extract-icon-variants.d.ts +2 -0
  124. package/dist/plugin-web-extension/feature-json/json-validation.d.ts +2 -1
  125. package/dist/plugin-web-extension/feature-json/messages.d.ts +2 -0
  126. package/dist/plugin-web-extension/feature-json/process-assets.d.ts +1 -1
  127. package/dist/plugin-web-extension/feature-manifest/manifest-lib/filter-keys-gecko.d.ts +21 -0
  128. package/dist/plugin-web-extension/feature-manifest/manifest-lib/filter-keys-safari.d.ts +1 -1
  129. package/dist/plugin-web-extension/feature-manifest/manifest-lib/icon-variants-fallback.d.ts +15 -0
  130. package/dist/plugin-web-extension/feature-manifest/manifest-lib/sanitize-fatal-shapes.d.ts +2 -1
  131. package/dist/plugin-web-extension/feature-manifest/manifest-lib/webkit-unsupported-keys.d.ts +15 -0
  132. package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/content_scripts.d.ts +1 -1
  133. package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/icons.d.ts +3 -2
  134. package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/omnibox.d.ts +1 -1
  135. package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/page_action.d.ts +2 -1
  136. package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/permissions.d.ts +1 -1
  137. package/dist/plugin-web-extension/feature-manifest/manifest-overrides/common/sandbox.d.ts +1 -1
  138. package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv2/browser_action.d.ts +4 -3
  139. package/dist/plugin-web-extension/feature-manifest/manifest-overrides/mv3/action.d.ts +3 -2
  140. package/dist/plugin-web-extension/feature-manifest/messages.d.ts +15 -1
  141. package/dist/plugin-web-extension/feature-manifest/normalize-manifest-path.d.ts +2 -0
  142. package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/dev-additions.d.ts +8 -0
  143. package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/patch-background.d.ts +2 -2
  144. package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/patch-externally-connectable.d.ts +1 -1
  145. package/dist/plugin-web-extension/feature-manifest/steps/patch-gecko-background.d.ts +1 -0
  146. package/dist/plugin-web-extension/feature-manifest/steps/warn-content-script-host-access.d.ts +17 -0
  147. package/dist/plugin-web-extension/feature-manifest/steps/warn-description-length.d.ts +26 -0
  148. package/dist/plugin-web-extension/feature-manifest/steps/warn-gecko-unsupported-apis.d.ts +37 -2
  149. package/dist/plugin-web-extension/feature-scripts/contracts.d.ts +3 -0
  150. package/dist/plugin-web-extension/feature-scripts/index.d.ts +1 -0
  151. package/dist/plugin-web-extension/feature-scripts/messages.d.ts +10 -1
  152. package/dist/plugin-web-extension/feature-scripts/scripts-lib/completion-value.d.ts +13 -0
  153. package/dist/plugin-web-extension/feature-scripts/scripts-lib/injected-sheet-urls.d.ts +5 -0
  154. package/dist/plugin-web-extension/feature-scripts/scripts-lib/main-world-bridge-pairing.d.ts +5 -0
  155. package/dist/plugin-web-extension/feature-scripts/scripts-lib/main-world-copy-routing.d.ts +2 -0
  156. package/dist/plugin-web-extension/feature-scripts/scripts-lib/registration-worlds.d.ts +10 -0
  157. package/dist/plugin-web-extension/feature-scripts/scripts-lib/runtime-main-world-scripts.d.ts +25 -2
  158. package/dist/plugin-web-extension/feature-scripts/scripts-lib/runtime-script-sheet.d.ts +14 -0
  159. package/dist/plugin-web-extension/feature-scripts/scripts-lib/taken-extension-base.d.ts +10 -0
  160. package/dist/plugin-web-extension/feature-scripts/steps/add-base-uri-runtime-module.d.ts +7 -1
  161. package/dist/plugin-web-extension/feature-scripts/steps/add-content-script-wrapper/content-script-wrapper.d.ts +2 -0
  162. package/dist/plugin-web-extension/feature-scripts/steps/add-content-script-wrapper/index.d.ts +2 -0
  163. package/dist/plugin-web-extension/feature-scripts/steps/add-public-path-runtime-module.d.ts +6 -0
  164. package/dist/plugin-web-extension/feature-scripts/steps/classic-traced-globals-loader.d.ts +1 -0
  165. package/dist/plugin-web-extension/feature-scripts/steps/compile-main-world-scripts.d.ts +4 -0
  166. package/dist/plugin-web-extension/feature-scripts/steps/keep-completion-value.d.ts +6 -0
  167. package/dist/plugin-web-extension/feature-scripts/steps/pair-runtime-main-world-bridges.d.ts +12 -0
  168. package/dist/plugin-web-extension/feature-scripts/steps/place-runtime-script-sheets.d.ts +12 -0
  169. package/dist/plugin-web-extension/feature-scripts/steps/prune-main-world-bridges.d.ts +1 -0
  170. package/dist/plugin-web-extension/feature-scripts/steps/root-injected-sheet-urls.d.ts +9 -0
  171. package/dist/plugin-web-extension/feature-scripts/steps/route-main-world-copies.d.ts +10 -0
  172. package/dist/plugin-web-extension/feature-scripts/steps/source-literals.d.ts +24 -0
  173. package/dist/plugin-web-extension/feature-scripts/steps/take-extension-base.d.ts +11 -0
  174. package/dist/plugin-web-extension/feature-scripts/steps/trace-runtime-loaded-files.d.ts +18 -3
  175. package/dist/plugin-web-extension/feature-scripts/steps/warn-main-world-registration-changed.d.ts +12 -0
  176. package/dist/plugin-web-extension/feature-scripts/steps/warn-moved-page-relative-urls.d.ts +30 -0
  177. package/dist/plugin-web-extension/feature-scripts/steps/warn-page-relative-script-path.d.ts +10 -0
  178. package/dist/plugin-web-extension/feature-scripts/steps/warn-unknown-registration-world.d.ts +10 -0
  179. package/dist/plugin-web-extension/feature-web-resources/collect-entry-imports.d.ts +1 -0
  180. package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/messages.d.ts +2 -0
  181. package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/page-requests.d.ts +5 -0
  182. package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/resolve-war.d.ts +1 -0
  183. package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/unreachable-resources.d.ts +1 -0
  184. package/dist/plugin-web-extension/shared/script-graph.d.ts +12 -0
  185. package/dist/preprocessor-passthrough-loader.mjs +1 -1
  186. package/dist/preview.mjs +1 -1
  187. package/dist/public-css-url-loader.mjs +1 -1
  188. package/dist/{331~0.mjs → q~0.mjs} +2 -2
  189. package/dist/rj~0.mjs +125 -0
  190. package/dist/{519~0.mjs → rl~0.mjs} +56 -5
  191. package/dist/rspack-config~0.mjs +3140 -3302
  192. package/dist/{177~0.mjs → r~0.mjs} +2 -2
  193. package/dist/sfc-style-block-loader.mjs +49 -0
  194. package/dist/stats-handler~0.mjs +15 -7
  195. package/dist/tm~0.mjs +71 -0
  196. package/dist/types.d.ts +46 -5
  197. package/dist/{285~0.mjs → t~0.mjs} +41 -26
  198. package/dist/unplaced-style-import-loader.mjs +131 -0
  199. package/dist/x~0.mjs +3 -0
  200. package/dist/y~0.mjs +234 -0
  201. package/dist/zip~0.mjs +5 -4
  202. package/dist/{363~0.mjs → z~0.mjs} +563 -281
  203. package/package.json +6 -6
  204. package/dist/527~0.mjs +0 -3
  205. package/dist/840~0.mjs +0 -5635
  206. /package/dist/{895~0.mjs → 3~0.mjs} +0 -0
  207. /package/dist/{374~0.mjs → 5~0.mjs} +0 -0
  208. /package/dist/{206~0.mjs → 6~0.mjs} +0 -0
  209. /package/dist/{471~0.mjs → g~0.mjs} +0 -0
  210. /package/dist/{117~0.mjs → w~0.mjs} +0 -0
@@ -3,15 +3,18 @@ import node_fs from "node:fs";
3
3
  import node_path from "node:path";
4
4
  import { parse } from "es-module-lexer";
5
5
  import { validate } from "schema-utils";
6
- import { contentScriptWithoutDefaultExport, reservedScriptsFolder } from "./519~0.mjs";
7
- import { filterKeysForThisBrowser } from "./143~0.mjs";
8
- import { stripBom } from "./374~0.mjs";
9
- import { canonicalizeDir, canonicalizeResourcePath } from "./712~0.mjs";
10
- import { findNearestProjectManifestSync } from "./731~0.mjs";
11
- import { getCanonicalContentScriptEntryName, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX, getContentScriptCssProbeMarker } from "./640~0.mjs";
12
- import { EXTENSION_BASE_FROM_STACK } from "./527~0.mjs";
13
- import { humanLine } from "./852~0.mjs";
14
- import { returnWithMap, adjustLoaderSourceMap, inputOrIdentityMap } from "./895~0.mjs";
6
+ import { getCanonicalContentScriptEntryName, getContentScriptCssProbeMarker, MAIN_WORLD_COPY_SUFFIX, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX } from "./bh~0.mjs";
7
+ import { contentScriptWithoutDefaultExport, reservedScriptsFolder } from "./rl~0.mjs";
8
+ import { keepCompletionValue } from "./df~0.mjs";
9
+ import { extensionBaseAttributeFor, extensionBaseGlobalFor } from "./o~0.mjs";
10
+ import { filterKeysForThisBrowser } from "./ey~0.mjs";
11
+ import { stripBom } from "./5~0.mjs";
12
+ import { canonicalizeDir, canonicalizeResourcePath } from "./ka~0.mjs";
13
+ import { findNearestProjectManifestSync } from "./j~0.mjs";
14
+ import { isChromiumBasedBrowser, isGeckoBasedBrowser } from "./q~0.mjs";
15
+ import { extensionSchemeFor, unlessExtensionAddress, closedOnSlash, extensionBaseFromFile } from "./c~0.mjs";
16
+ import { humanLine } from "./k~0.mjs";
17
+ import { returnWithMap, adjustLoaderSourceMap, inputOrIdentityMap } from "./3~0.mjs";
15
18
  const schema = {
16
19
  type: 'object',
17
20
  properties: {
@@ -33,6 +36,15 @@ const schema = {
33
36
  type: 'string'
34
37
  }
35
38
  },
39
+ mainWorldCopies: {
40
+ type: 'array',
41
+ items: {
42
+ type: 'string'
43
+ }
44
+ },
45
+ mainWorldBundle: {
46
+ type: 'boolean'
47
+ },
36
48
  scriptsFolder: {
37
49
  anyOf: [
38
50
  {
@@ -115,6 +127,18 @@ function hasDefaultExport(source, resourcePath, compilationArg) {
115
127
  return fallback;
116
128
  }
117
129
  }
130
+ function importsScriptsFile(source, resourceAbsPath, scriptsDir) {
131
+ try {
132
+ const [imports] = parse(source);
133
+ return imports.some(({ specifier })=>{
134
+ if ('string' != typeof specifier || !specifier.startsWith('.')) return false;
135
+ const relative = node_path.relative(scriptsDir, node_path.resolve(node_path.dirname(resourceAbsPath), specifier));
136
+ return !relative.startsWith('..') && !node_path.isAbsolute(relative);
137
+ });
138
+ } catch {
139
+ return /\bfrom\s*["']\.|\bimport\s*["']\./.test(source);
140
+ }
141
+ }
118
142
  const hintedEntriesWithoutDefaultExport = new Set();
119
143
  const __EXTENSIONJS_manifestParseCache = new Map();
120
144
  function readManifestCached(manifestPath, browser) {
@@ -195,30 +219,40 @@ function contentScriptWrapper(source, inputSourceMap) {
195
219
  return rewrittenSource;
196
220
  }
197
221
  const runAt = declaredEntry?.runAt || 'document_idle';
198
- const isRuntimeMainWorld = (options.mainWorldScripts || []).some((candidate)=>resourceAbsPath === canonicalizeResourcePath(candidate));
199
- const isMainWorld = declaredEntry?.world === 'MAIN' || isRuntimeMainWorld;
222
+ const namedIn = (files)=>(files || []).some((candidate)=>resourceAbsPath === canonicalizeResourcePath(candidate));
223
+ const isMainWorldCopy = true === options.mainWorldBundle && namedIn(options.mainWorldCopies);
224
+ const isRuntimeMainWorld = namedIn(options.mainWorldScripts) || isMainWorldCopy;
225
+ const isMainWorld = declaredEntry?.world === 'MAIN' || isRuntimeMainWorld || true === options.mainWorldBundle;
200
226
  const hostInstrumentationEnabled = !isShippedBundle && !isMainWorld;
201
- const takesBridgeBase = isShippedBundle && declaredEntry?.world === 'MAIN';
202
- const takenBridgeBase = takesBridgeBase ? '__EXTENSIONJS_BRIDGE_BASE || ' : '';
203
- const bundleKey = declaredEntry ? getCanonicalContentScriptEntryName(declaredEntry.index) : `scripts/${String(relToScripts || '').replace(/\\/g, '/')}`;
227
+ const sharesBridgeBase = !declaredEntry && isRuntimeMainWorld && isShippedBundle && isGeckoBasedBrowser(browser);
228
+ const takesBridgeBase = sharesBridgeBase || declaredEntry?.world === 'MAIN' && (isShippedBundle || isChromiumBasedBrowser(browser));
229
+ const takesFromFile = isMainWorld && isGeckoBasedBrowser(browser);
230
+ const holdsBridgeBase = takesBridgeBase || takesFromFile;
231
+ const baseAttribute = JSON.stringify(extensionBaseAttributeFor(manifestPath, browser));
232
+ const baseScheme = extensionSchemeFor(String(browser));
233
+ const asksRuntime = (lines)=>takesFromFile ? '' : lines;
234
+ const takenBridgeBase = holdsBridgeBase ? '__EXTENSIONJS_BRIDGE_BASE || ' : '';
235
+ const dropsBaseGetter = takesFromFile ? `try { delete window.${extensionBaseGlobalFor(manifestPath, browser)}; } catch (error) {} ` : '';
236
+ const scriptKey = `scripts/${String(relToScripts || '').replace(/\\/g, '/')}`;
237
+ const bundleKey = declaredEntry ? getCanonicalContentScriptEntryName(declaredEntry.index) : isMainWorldCopy ? scriptKey.replace(/(\.[^./]+)?$/, `${MAIN_WORLD_COPY_SUFFIX}$1`) : scriptKey;
204
238
  const reinjectKey = declaredEntry ? `${bundleKey}::script-${declaredEntry.scriptIndex}` : bundleKey;
205
239
  const buildToken = createBuildToken(rewrittenSource);
206
240
  const cssProbeMarker = getContentScriptCssProbeMarker(bundleKey);
207
241
  const cssAssetSpecifiers = collectStyleAssetSpecifiers(rewrittenSource);
208
242
  const cssAssetUrlsInline = `var __EXTENSIONJS_BUNDLE_CSS_URLS=[${cssAssetSpecifiers.map((specifier)=>`(function(){ try { return String(new URL(${escapeCodeString(JSON.stringify(specifier))}, import.meta.url)); } catch (error) { return ""; } })()`).join(',')}];\n`;
209
- const bundleCssHydrationBody = `function __EXTENSIONJS_runtimeGetURL(path){\n try {\n if (typeof globalThis === "object" && globalThis && globalThis.browser && globalThis.browser.runtime && typeof globalThis.browser.runtime.getURL === "function") return globalThis.browser.runtime.getURL(path);\n if (typeof globalThis === "object" && globalThis && globalThis.chrome && globalThis.chrome.runtime && typeof globalThis.chrome.runtime.getURL === "function") return globalThis.chrome.runtime.getURL(path);\n } catch (error) {}\n try {\n var base = ${takenBridgeBase}((typeof globalThis === "object" && globalThis && globalThis.__EXTJS_EXTENSION_BASE__) ? String(globalThis.__EXTJS_EXTENSION_BASE__) : "");\n if (!base && typeof document === "object" && document && document.documentElement) base = String(document.documentElement.getAttribute("data-extjs-extension-base") || "");\n if (!base) return "";\n return base.replace(/\\/+\$/, "/") + String(path || "").replace(/^\\/+/, "");\n } catch (error) {}\n return "";\n}\nvar __EXTENSIONJS_BUNDLE_CSS_PROBE=${JSON.stringify(cssProbeMarker)};\nfunction __EXTENSIONJS_bundleCssProbeUrls(){\n try {\n var probe = String(__EXTENSIONJS_BUNDLE_CSS_PROBE || "");\n if (!probe.length) return [];\n if (probe.lastIndexOf("__EXTENSIONJS_CSS_PROBE", 0) === 0) return [];\n var url = __EXTENSIONJS_runtimeGetURL(probe);\n if (typeof url !== "string" || !url.length) return [];\n if (url.charAt(url.length - 1) === "/") return [];\n return [url];\n } catch (error) { return []; }\n}\nfunction __EXTENSIONJS_scheduleBundleCssHydration(){\n try {\n if (String(__EXTENSIONJS_BUNDLE_KEY || "").indexOf(${JSON.stringify(CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX)}) !== 0) return;\n if (typeof document === "undefined" || typeof fetch !== "function") return;\n var cssUrls = Array.from(new Set((Array.isArray(__EXTENSIONJS_BUNDLE_CSS_URLS) ? __EXTENSIONJS_BUNDLE_CSS_URLS : []).concat(__EXTENSIONJS_bundleCssProbeUrls()).filter(function(value){ return typeof value === "string" && value.trim().length > 0; })));\n if (!cssUrls.length) return;\n var cssText = "";\n var cssPromise = null;\n var readCss = function(){\n if (cssPromise) return cssPromise;\n cssPromise = Promise.all(cssUrls.map(function(url){\n return Promise.resolve().then(function(){ return fetch(url); }).then(function(response){\n if (!response || !response.ok) return "";\n return response.text();\n }).catch(function(){\n return "";\n });\n })).then(function(texts){\n var seen = [];\n for (var t = 0; t < texts.length; t++) {\n if (typeof texts[t] !== "string" || !texts[t].trim().length || seen.indexOf(texts[t]) !== -1) continue;\n seen.push(texts[t]);\n }\n return seen.join("\\n");\n }).then(function(text){\n cssText = typeof text === "string" ? text : "";\n var root = __EXTENSIONJS_runtimeGetURL("/");\n if (root) cssText = cssText.replace(/url\\(\\s*(["\']?)\\/(?!\\/)/gi, function(match, quote){ return "url(" + quote + root; });\n try { setTimeout(tick, 0); } catch (error) {}\n return cssText;\n }).catch(function(){ return ""; });\n return cssPromise;\n };\n var tries = 0;\n var wanted = false;\n var tick = function(){\n try {\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var hosts = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n for (var i = 0; i < hosts.length; i++) {\n var host = hosts[i];\n if (!host || !host.shadowRoot || typeof host.getAttribute !== "function") continue;\n` + devOnly(' var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (hostOwner && hostOwner !== __extjsToken) continue;\n if (!hostOwner && __EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (!hostOwner && __EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n if (!hostOwner && String(host.getAttribute("data-extjs-reinject-key") || "") && String(host.getAttribute("data-extjs-reinject-key") || "") !== String(__EXTENSIONJS_BUNDLE_KEY || "")) continue;\n') + (isShippedBundle ? " if (__EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (__EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n" : '') + ' var sr = host.shadowRoot;\n var styles = Array.from(sr.querySelectorAll("style"));\n var hasUserStyle = styles.some(function(styleEl){\n return styleEl && styleEl.getAttribute("data-extjs-bundle-css") !== "true" && String(styleEl.textContent || "").trim().length > 0;\n });\n var injected = null;\n for (var s = 0; s < styles.length; s++) {\n if (!styles[s] || styles[s].getAttribute("data-extjs-bundle-css") !== "true") continue;\n var styleOwner = String(styles[s].getAttribute("data-extjs-style-owner") || "");\n if (!styleOwner || styleOwner === __extjsToken) { injected = styles[s]; break; }\n }\n if (hasUserStyle) {\n if (injected && injected.parentNode) injected.parentNode.removeChild(injected);\n return;\n }\n if (typeof cssText === "string" && cssText.trim()) {\n if (!injected) {\n injected = document.createElement("style");\n injected.setAttribute("data-extjs-bundle-css", "true");\n injected.setAttribute("data-extjs-reinject-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n sr.insertBefore(injected, sr.firstChild || null);\n }\n injected.setAttribute("data-extjs-style-owner", __extjsToken);\n if (String(injected.textContent || "") !== cssText) injected.textContent = cssText;\n return;\n }\n wanted = true;\n }\n } catch (error) {}\n if (tries++ < 20) {\n' + (isShippedBundle ? ' if (wanted && !cssPromise) readCss();\n' : ' if (!cssPromise) readCss();\n') + " setTimeout(tick, 250);\n }\n };\n tick();\n } catch (error) {}\n}\n";
243
+ const bundleCssHydrationBody = 'function __EXTENSIONJS_runtimeGetURL(path){\n' + asksRuntime(' try {\n if (typeof globalThis === "object" && globalThis && globalThis.browser && globalThis.browser.runtime && typeof globalThis.browser.runtime.getURL === "function") return globalThis.browser.runtime.getURL(path);\n if (typeof globalThis === "object" && globalThis && globalThis.chrome && globalThis.chrome.runtime && typeof globalThis.chrome.runtime.getURL === "function") return globalThis.chrome.runtime.getURL(path);\n } catch (error) {}\n') + ' try {\n' + (takesFromFile ? ' var base = __EXTENSIONJS_BRIDGE_BASE;\n' : ` var base = ${takenBridgeBase}"";\n`) + ` if (!base && typeof document === "object" && document && document.documentElement) base = String(document.documentElement.getAttribute(${baseAttribute}) || "");\n` + ` ${unlessExtensionAddress('base', baseScheme)}\n` + ' if (!base) return "";\n' + (takesFromFile ? ` return ${closedOnSlash('base')} + String(path || "").replace(/^\\/+/, "");\n` : ' return base.replace(/\\/+$/, "/") + String(path || "").replace(/^\\/+/, "");\n') + ' } catch (error) {}\n return "";\n}\n' + `var __EXTENSIONJS_BUNDLE_CSS_PROBE=${JSON.stringify(cssProbeMarker)};\n` + 'function __EXTENSIONJS_bundleCssProbeUrls(){\n try {\n var probe = String(__EXTENSIONJS_BUNDLE_CSS_PROBE || "");\n if (!probe.length) return [];\n if (probe.lastIndexOf("__EXTENSIONJS_CSS_PROBE", 0) === 0) return [];\n var url = __EXTENSIONJS_runtimeGetURL(probe);\n if (typeof url !== "string" || !url.length) return [];\n if (url.charAt(url.length - 1) === "/") return [];\n return [url];\n } catch (error) { return []; }\n}\nfunction __EXTENSIONJS_scheduleBundleCssHydration(){\n try {\n' + ` if (String(__EXTENSIONJS_BUNDLE_KEY || "").indexOf(${JSON.stringify(CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX)}) !== 0) return;\n` + ' if (typeof document === "undefined" || typeof fetch !== "function") return;\n var cssUrls = Array.from(new Set((Array.isArray(__EXTENSIONJS_BUNDLE_CSS_URLS) ? __EXTENSIONJS_BUNDLE_CSS_URLS : []).concat(__EXTENSIONJS_bundleCssProbeUrls()).filter(function(value){ return typeof value === "string" && value.trim().length > 0; })));\n if (!cssUrls.length) return;\n var cssText = "";\n var cssPromise = null;\n var readCss = function(){\n if (cssPromise) return cssPromise;\n cssPromise = Promise.all(cssUrls.map(function(url){\n return Promise.resolve().then(function(){ return fetch(url); }).then(function(response){\n if (!response || !response.ok) return "";\n return response.text();\n }).catch(function(){\n return "";\n });\n })).then(function(texts){\n var seen = [];\n for (var t = 0; t < texts.length; t++) {\n if (typeof texts[t] !== "string" || !texts[t].trim().length || seen.indexOf(texts[t]) !== -1) continue;\n seen.push(texts[t]);\n }\n return seen.join("\\n");\n }).then(function(text){\n cssText = typeof text === "string" ? text : "";\n var root = __EXTENSIONJS_runtimeGetURL("/");\n if (root) cssText = cssText.replace(/url\\(\\s*(["\']?)\\/(?!\\/)/gi, function(match, quote){ return "url(" + quote + root; });\n try { setTimeout(tick, 0); } catch (error) {}\n return cssText;\n }).catch(function(){ return ""; });\n return cssPromise;\n };\n var tries = 0;\n var wanted = false;\n var tick = function(){\n try {\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var hosts = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n for (var i = 0; i < hosts.length; i++) {\n var host = hosts[i];\n if (!host || !host.shadowRoot || typeof host.getAttribute !== "function") continue;\n' + devOnly(' var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (hostOwner && hostOwner !== __extjsToken) continue;\n if (!hostOwner && __EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (!hostOwner && __EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n if (!hostOwner && String(host.getAttribute("data-extjs-reinject-key") || "") && String(host.getAttribute("data-extjs-reinject-key") || "") !== String(__EXTENSIONJS_BUNDLE_KEY || "")) continue;\n') + (isShippedBundle ? " if (__EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (__EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n" : '') + ' var sr = host.shadowRoot;\n var styles = Array.from(sr.querySelectorAll("style"));\n var hasUserStyle = styles.some(function(styleEl){\n return styleEl && styleEl.getAttribute("data-extjs-bundle-css") !== "true" && String(styleEl.textContent || "").trim().length > 0;\n });\n var injected = null;\n for (var s = 0; s < styles.length; s++) {\n if (!styles[s] || styles[s].getAttribute("data-extjs-bundle-css") !== "true") continue;\n var styleOwner = String(styles[s].getAttribute("data-extjs-style-owner") || "");\n if (!styleOwner || styleOwner === __extjsToken) { injected = styles[s]; break; }\n }\n if (hasUserStyle) {\n if (injected && injected.parentNode) injected.parentNode.removeChild(injected);\n return;\n }\n if (typeof cssText === "string" && cssText.trim()) {\n if (!injected) {\n injected = document.createElement("style");\n injected.setAttribute("data-extjs-bundle-css", "true");\n injected.setAttribute("data-extjs-reinject-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n sr.insertBefore(injected, sr.firstChild || null);\n }\n injected.setAttribute("data-extjs-style-owner", __extjsToken);\n if (String(injected.textContent || "") !== cssText) injected.textContent = cssText;\n return;\n }\n wanted = true;\n }\n } catch (error) {}\n if (tries++ < 20) {\n' + (isShippedBundle ? ' if (wanted && !cssPromise) readCss();\n' : ' if (!cssPromise) readCss();\n') + " setTimeout(tick, 250);\n }\n };\n tick();\n } catch (error) {}\n}\n";
210
244
  const hasModuleGraph = cssAssetSpecifiers.length > 0 || hasModuleDependency(rewrittenSource);
211
245
  const bundleCssHydrationEnabled = bundleKey.startsWith(CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX) && hasModuleGraph;
212
246
  const bundleCssHydrationInline = bundleCssHydrationEnabled ? bundleCssHydrationBody : 'function __EXTENSIONJS_scheduleBundleCssHydration(){}\n';
213
247
  const isBuiltInCompanion = /extension-js-(?:devtools|theme)/.test(String(packageJsonDir || ''));
214
248
  const hostInstrumentationInline = hostInstrumentationEnabled ? 'function __EXTENSIONJS_debugObserveOwnedRootRemoval(){\n try {\n if (!__EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED) return;\n if (typeof globalThis !== "object" || !globalThis || globalThis.__EXTJS_DEBUG_REMOVAL_OBSERVER__) return;\n if (typeof MutationObserver !== "function" || typeof document === "undefined") return;\n var target = document.documentElement || document.body || document;\n if (!target) return;\n var observer = new MutationObserver(function(records){\n try {\n var ownedKey = __EXTENSIONJS_ownerToken();\n var findOwnedRoot = function(node){\n try {\n if (!node || node.nodeType !== 1) return null;\n if (typeof node.getAttribute === "function" && String(node.getAttribute("data-extjs-reinject-owner") || "") === ownedKey) return node;\n if (typeof node.querySelector === "function") {\n return node.querySelector("[data-extjs-reinject-owner=\\"" + ownedKey.replace(/"/g, "\\\\\\"") + "\\"]");\n }\n } catch (error) {}\n return null;\n };\n for (var r = 0; r < records.length; r++) {\n var removedNodes = Array.from(records[r].removedNodes || []);\n for (var n = 0; n < removedNodes.length; n++) {\n var node = removedNodes[n];\n var ownedRoot = findOwnedRoot(node);\n if (!ownedRoot || typeof ownedRoot.getAttribute !== "function") continue;\n var owner = String(ownedRoot.getAttribute("data-extjs-reinject-owner") || "");\n if (!owner || owner !== ownedKey) continue;\n var pageRoot = document.documentElement;\n if (pageRoot && typeof pageRoot.setAttribute === "function") {\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal")) pageRoot.setAttribute("data-extjs-debug-last-removal", "mutation-observer");\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal-key")) pageRoot.setAttribute("data-extjs-debug-last-removal-key", owner);\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal-source")) pageRoot.setAttribute("data-extjs-debug-last-removal-source", "mutation-observer");\n if (!pageRoot.getAttribute("data-extjs-debug-last-removed-node-tag")) pageRoot.setAttribute("data-extjs-debug-last-removed-node-tag", String(node.tagName || "").toLowerCase());\n if (!pageRoot.getAttribute("data-extjs-debug-last-removed-node-id")) pageRoot.setAttribute("data-extjs-debug-last-removed-node-id", String(node.id || ""));\n if (!pageRoot.getAttribute("data-extjs-debug-last-removed-node-class")) pageRoot.setAttribute("data-extjs-debug-last-removed-node-class", String(node.className || ""));\n if (!pageRoot.getAttribute("data-extjs-debug-last-removed-node-direct")) pageRoot.setAttribute("data-extjs-debug-last-removed-node-direct", String(node === ownedRoot));\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal-ready-state")) pageRoot.setAttribute("data-extjs-debug-last-removal-ready-state", String(document.readyState || ""));\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal-url")) pageRoot.setAttribute("data-extjs-debug-last-removal-url", String(location.href || ""));\n pageRoot.setAttribute("data-extjs-debug-stage", "root-removed-observed");\n }\n return;\n }\n }\n } catch (error) {}\n });\n observer.observe(target, { childList: true, subtree: true });\n globalThis.__EXTJS_DEBUG_REMOVAL_OBSERVER__ = observer;\n } catch (error) {}\n}\nfunction __EXTENSIONJS_patchDomRemovalApis(){\n try {\n if (!__EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED) return;\n if (typeof globalThis !== "object" || !globalThis || globalThis.__EXTJS_DEBUG_DOM_APIS_PATCHED__) return;\n var record = function(source, node, parent){\n try {\n var pageRoot = document.documentElement;\n if (!pageRoot || typeof pageRoot.setAttribute !== "function") return;\n var ownedRoot = null;\n if (node && node.nodeType === 1) {\n if (typeof node.getAttribute === "function" && String(node.getAttribute("data-extjs-reinject-owner") || "") === __EXTENSIONJS_ownerToken()) ownedRoot = node;\n else if (typeof node.querySelector === "function") ownedRoot = node.querySelector("[data-extjs-reinject-owner=\\"" + __EXTENSIONJS_ownerToken().replace(/"/g, "\\\\\\"") + "\\"]");\n }\n if (!ownedRoot) return;\n pageRoot.setAttribute("data-extjs-debug-stage", "dom-api-removal");\n pageRoot.setAttribute("data-extjs-debug-last-removal", source);\n pageRoot.setAttribute("data-extjs-debug-last-removal-source", source);\n pageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-tag", String(node && node.tagName || "").toLowerCase());\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-id", String(node && node.id || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-class", String(node && node.className || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-direct", String(node === ownedRoot));\n pageRoot.setAttribute("data-extjs-debug-last-removal-ready-state", String(document.readyState || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removal-url", String(location.href || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removal-parent-tag", String(parent && parent.tagName || "").toLowerCase());\n } catch (error) {}\n };\n try {\n var originalRemoveChild = Node.prototype.removeChild;\n if (typeof originalRemoveChild === "function") {\n Node.prototype.removeChild = function(child){\n record("Node.removeChild", child, this);\n return originalRemoveChild.call(this, child);\n };\n }\n } catch (error) {}\n try {\n var originalReplaceChildren = Element.prototype.replaceChildren;\n if (typeof originalReplaceChildren === "function") {\n Element.prototype.replaceChildren = function(){\n try {\n var existing = Array.from(this.childNodes || []);\n for (var i = 0; i < existing.length; i++) record("Element.replaceChildren", existing[i], this);\n } catch (error) {}\n return originalReplaceChildren.apply(this, arguments);\n };\n }\n } catch (error) {}\n globalThis.__EXTJS_DEBUG_DOM_APIS_PATCHED__ = true;\n } catch (error) {}\n}\nif (__EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED) {\n try { __EXTENSIONJS_debugObserveOwnedRootRemoval(); } catch (error) {}\n try { __EXTENSIONJS_patchDomRemovalApis(); } catch (error) {}\n}\n' : '';
215
249
  const reinjectMarkerInline = 'function __EXTENSIONJS_setReinjectMarker(key, generation, status){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_ENABLED || typeof document === "undefined") return;\n var root = document.body || document.documentElement;\n if (!root) return;\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var marker = null;\n try {\n var markers = Array.from(document.querySelectorAll("[data-extjs-reinject-marker=\\"true\\"]"));\n for (var i = 0; i < markers.length; i++) {\n var current = markers[i];\n if (!current || typeof current.getAttribute !== "function") continue;\n var currentOwner = String(current.getAttribute("data-extjs-marker-owner") || "");\n if (currentOwner === __extjsToken) { marker = current; break; }\n if (!currentOwner && current.getAttribute("data-extjs-reinject-key") === key) { marker = current; break; }\n }\n } catch (error) {}\n if (!marker && typeof document.createElement === "function") {\n marker = document.createElement("div");\n marker.setAttribute("data-extjs-reinject-marker", "true");\n marker.setAttribute("hidden", "");\n marker.setAttribute("aria-hidden", "true");\n try { marker.style.display = "none"; } catch (error) {}\n root.appendChild(marker);\n }\n if (!marker) return;\n marker.setAttribute("data-extjs-reinject-key", String(__EXTENSIONJS_BUNDLE_KEY || key || ""));\n marker.setAttribute("data-extjs-marker-owner", __extjsToken);\n marker.setAttribute("data-extjs-reinject-generation", String(generation));\n marker.setAttribute("data-extjs-reinject-status", String(status || "mounted"));\n marker.setAttribute("data-extjs-reinject-build", String(__EXTENSIONJS_REINJECT_BUILD_TOKEN || ""));\n try { marker.textContent = String(__EXTENSIONJS_BUNDLE_KEY || key || "") + ":" + String(generation) + ":" + String(status || "mounted"); } catch (error) {}\n try {\n var roots = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n var ownedRootCount = 0;\n for (var j = 0; j < roots.length; j++) {\n var host = roots[j];\n if (!host || typeof host.setAttribute !== "function") continue;\n var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (hostOwner && hostOwner !== __extjsToken) continue;\n if (!hostOwner && __EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (!hostOwner && __EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n ownedRootCount++;\n host.setAttribute("data-extjs-reinject-owner", __extjsToken);\n host.setAttribute("data-extjs-reinject-key", String(__EXTENSIONJS_BUNDLE_KEY || key || ""));\n host.setAttribute("data-extjs-reinject-generation", String(generation));\n host.setAttribute("data-extjs-reinject-status", String(status || "mounted"));\n host.setAttribute("data-extjs-reinject-build", String(__EXTENSIONJS_REINJECT_BUILD_TOKEN || ""));\n try {\n if (!host.__extjsDebugRemovePatched) {\n host.__extjsDebugRemovePatched = true;\n var __extjsOriginalRemove = typeof host.remove === "function" ? host.remove.bind(host) : null;\n if (__extjsOriginalRemove) {\n host.remove = function(){\n try {\n var pageRoot = document.documentElement;\n if (pageRoot && typeof pageRoot.setAttribute === "function") {\n pageRoot.setAttribute("data-extjs-debug-stage", "root-remove-called");\n pageRoot.setAttribute("data-extjs-debug-last-removal", "remove()");\n pageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removal-source", "patched-host-remove");\n }\n } catch (error) {}\n return __extjsOriginalRemove();\n };\n }\n }\n } catch (error) {}\n }\n try {\n marker.setAttribute("data-extjs-debug-stage", String(status || ""));\n marker.setAttribute("data-extjs-debug-root-count", String(roots.length));\n marker.setAttribute("data-extjs-debug-owned-root-count", String(ownedRootCount));\n marker.setAttribute("data-extjs-debug-marker-count", String(markers.length));\n } catch (error) {}\n } catch (error) {}\n try {\n var pageRoot = document.documentElement;\n if (pageRoot && typeof pageRoot.setAttribute === "function") {\n pageRoot.setAttribute("data-extjs-last-reinject-key", String(__EXTENSIONJS_BUNDLE_KEY || key || ""));\n pageRoot.setAttribute("data-extjs-last-reinject-generation", String(generation));\n pageRoot.setAttribute("data-extjs-last-reinject-status", String(status || "mounted"));\n pageRoot.setAttribute("data-extjs-last-reinject-build", String(__EXTENSIONJS_REINJECT_BUILD_TOKEN || ""));\n pageRoot.setAttribute("data-extjs-debug-stage", marker.getAttribute("data-extjs-debug-stage") || String(status || ""));\n pageRoot.setAttribute("data-extjs-debug-root-count", marker.getAttribute("data-extjs-debug-root-count") || "0");\n pageRoot.setAttribute("data-extjs-debug-owned-root-count", marker.getAttribute("data-extjs-debug-owned-root-count") || "0");\n pageRoot.setAttribute("data-extjs-debug-marker-count", marker.getAttribute("data-extjs-debug-marker-count") || "0");\n }\n } catch (error) {}\n } catch (error) {}\n}\nfunction __EXTENSIONJS_cleanupKnownRoots(staleEvenIfSameBuild){\n try {\n if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var roots = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n for (var i = 0; i < roots.length; i++) {\n var host = roots[i];\n if (!host || typeof host.getAttribute !== "function") continue;\n var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (!hostOwner || hostOwner !== __extjsToken) continue;\n // Build-aware: only remove hosts owned by us whose build token does NOT\n // match the current bundle. Fresh roots from the current mount carry\n // the active build token and must be preserved; orphans from a prior\n // build (e.g. the old isolated world after `chrome.runtime.reload`)\n // carry stale tokens and should be cleared so we never end up with two\n // hosts owned by the same key.\n // EXCEPT when this bundle starts in a FRESH world (no registry entry,\n // because the old isolated world was destroyed by `chrome.runtime.reload`):\n // a same-build root then predates this execution and is a stale zombie\n // (its scripts died with the world). Unedited sibling scripts in a\n // multi-script entry keep their build token across recompiles, so the\n // token equality alone must not protect them here.\n var hostBuild = String(host.getAttribute("data-extjs-reinject-build") || "");\n var currentBuild = String(__EXTENSIONJS_REINJECT_BUILD_TOKEN || "");\n if (!staleEvenIfSameBuild && hostBuild && currentBuild && hostBuild === currentBuild) continue;\n try {\n var pageRoot = document.documentElement;\n if (pageRoot && typeof pageRoot.setAttribute === "function") {\n pageRoot.setAttribute("data-extjs-debug-stage", "cleanup-known-roots");\n pageRoot.setAttribute("data-extjs-debug-last-removal", "cleanup-known-roots");\n pageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removal-source", "cleanup-known-roots");\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-tag", String(host.tagName || "").toLowerCase());\n }\n } catch (error) {}\n try { host.remove(); } catch (error) {}\n }\n } catch (error) {}\n}\nfunction __EXTENSIONJS_cleanupOrphanRoots(){\n try {\n // At bundle execution start, before this run has mounted anything, any\n // `data-extension-root` host without `data-extjs-reinject-owner` is an\n // orphan from a prior session that died before `setReinjectMarker`\n // could tag it (typically: the previous isolated world was destroyed\n // by a `chrome.runtime.reload` mid-mount, or its `whenReady`-deferred\n // `apply` never fired). We have not created our own root yet, so any\n // untagged host we touch here is by definition not from THIS run, but\n // it may belong to a DIFFERENT extension mid-mount in the same DOM.\n // Companion extensions never sweep, and everyone else sweeps only when\n // a reinject marker proves a prior generation of THIS script ran here.\n if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;\n if (__EXTENSIONJS_NO_FOREIGN_ADOPT) return;\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var sawPriorGeneration = false;\n try {\n var markers = Array.from(document.querySelectorAll("[data-extjs-reinject-marker=\\"true\\"]"));\n for (var m = 0; m < markers.length; m++) {\n if (markers[m] && typeof markers[m].getAttribute === "function" && String(markers[m].getAttribute("data-extjs-marker-owner") || "") === __extjsToken) { sawPriorGeneration = true; break; }\n }\n } catch (error) {}\n if (!sawPriorGeneration) return;\n var roots = Array.from(document.querySelectorAll("[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n for (var i = 0; i < roots.length; i++) {\n var host = roots[i];\n if (!host || typeof host.getAttribute !== "function") continue;\n var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (hostOwner) continue;\n try { host.remove(); } catch (error) {}\n }\n } catch (error) {}\n}\n';
216
- const bootstrap = `var __EXTENSIONJS_BUNDLE_KEY=${JSON.stringify(bundleKey)};\nvar __EXTENSIONJS_REINJECT_KEY=${JSON.stringify(reinjectKey)};\n` + (takesBridgeBase ? `var __EXTENSIONJS_BRIDGE_BASE = ${EXTENSION_BASE_FROM_STACK};\ntry {\n var __EXTENSIONJS_html = document.documentElement;\n if (!__EXTENSIONJS_BRIDGE_BASE) __EXTENSIONJS_BRIDGE_BASE = String(__EXTENSIONJS_html.getAttribute("data-extjs-extension-base") || "");\n if (__EXTENSIONJS_html.hasAttribute("data-extjs-extension-base")) __EXTENSIONJS_html.removeAttribute("data-extjs-extension-base");\n if (__EXTENSIONJS_BRIDGE_BASE && typeof __webpack_require__ === "function") __webpack_require__.extjsBase = __EXTENSIONJS_BRIDGE_BASE;\n} catch (error) {}\n` : '') + devOnly(`var __EXTENSIONJS_REINJECT_BUILD_TOKEN=${JSON.stringify(buildToken)};\n`) + `var __EXTENSIONJS_NO_FOREIGN_ADOPT=${JSON.stringify(isBuiltInCompanion)};\n` + 'function __EXTENSIONJS_ownerToken(){\n var extId = "";\n try {\n var rt = (typeof globalThis === "object" && globalThis && ((globalThis.browser && globalThis.browser.runtime) || (globalThis.chrome && globalThis.chrome.runtime))) || null;\n if (rt && rt.id) extId = String(rt.id);\n } catch (error) {}\n return String(__EXTENSIONJS_REINJECT_KEY || "") + (extId ? "@" + extId : "");\n}\n' + devOnly(`var __EXTENSIONJS_DEV_MARKERS_ENABLED=${JSON.stringify(!isShippedBundle)};\nvar __EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED=${JSON.stringify(hostInstrumentationEnabled)};\n`) + (!isShippedBundle || bundleCssHydrationEnabled ? 'var __EXTENSIONJS_PRE_MOUNT_ROOTS = [];\nfunction __EXTENSIONJS_snapshotPreMountRoots(){\n try {\n if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;\n __EXTENSIONJS_PRE_MOUNT_ROOTS = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]"));\n } catch (error) { __EXTENSIONJS_PRE_MOUNT_ROOTS = []; }\n}\n__EXTENSIONJS_snapshotPreMountRoots();\n' : 'function __EXTENSIONJS_snapshotPreMountRoots(){}\n') + `${cssAssetUrlsInline}` + devOnly('var __EXTENSIONJS_REINJECT_REGISTRY=(typeof globalThis==="object" && globalThis ? (globalThis.__EXTENSIONJS_DEV_REINJECT__ || (globalThis.__EXTENSIONJS_DEV_REINJECT__={})) : {});\n') + 'var __EXTENSIONJS_REGISTERED_CLEANUPS=[];\n' + devOnly('function __EXTENSIONJS_readReinjectGeneration(entry){\n try {\n if (!entry) return 0;\n if (typeof entry === "function" && typeof entry.__extjsGeneration === "number") return entry.__extjsGeneration;\n if (typeof entry === "object") {\n if (typeof entry.__extjsGeneration === "number") return entry.__extjsGeneration;\n if (typeof entry.generation === "number") return entry.generation;\n if (typeof entry.cleanup === "function" && typeof entry.cleanup.__extjsGeneration === "number") return entry.cleanup.__extjsGeneration;\n }\n } catch (error) {}\n return 0;\n}\n') + 'function __EXTENSIONJS_runCleanups(list){\n try {\n if (!Array.isArray(list)) return;\n for (var i = list.length - 1; i >= 0; i--) {\n try { if (typeof list[i] === "function") list[i](); } catch (error) {}\n }\n } catch (error) {}\n}\nfunction __EXTENSIONJS_registerCleanup(fn){\n if (typeof fn === "function") __EXTENSIONJS_REGISTERED_CLEANUPS.push(fn);\n return fn;\n}\n' + devOnly(reinjectMarkerInline) + 'function __EXTENSIONJS_composeCleanup(primaryCleanup){\n return function(){\n try { if (typeof primaryCleanup === "function") primaryCleanup(); } catch (error) {}\n try { __EXTENSIONJS_runCleanups(__EXTENSIONJS_REGISTERED_CLEANUPS); } catch (error) {}\n' + devOnly(' try { __EXTENSIONJS_cleanupKnownRoots(); } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "cleaned"); } catch (error) {}\n') + " };\n}\n" + devOnly('function __EXTENSIONJS_recordExecutionSnapshot(stage){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_ENABLED) return;\n if (typeof document === "undefined") return;\n var pageRoot = document.documentElement;\n if (!pageRoot || typeof pageRoot.getAttribute !== "function" || typeof pageRoot.setAttribute !== "function") return;\n var currentCount = Number(pageRoot.getAttribute("data-extjs-debug-execution-count") || "0");\n var nextCount = Number.isFinite(currentCount) ? currentCount + 1 : 1;\n var roots = [];\n try { roots = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])")); } catch (error) {}\n pageRoot.setAttribute("data-extjs-debug-execution-count", String(nextCount));\n pageRoot.setAttribute("data-extjs-debug-last-execution-stage", String(stage || ""));\n pageRoot.setAttribute("data-extjs-debug-last-execution-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-existing-root-count-before-cleanup", String(roots.length));\n } catch (error) {}\n}\n') + (isShippedBundle && isMainWorld ? '' : 'try {\n if (typeof globalThis === "object" && globalThis) {\n globalThis.__EXTENSIONJS_registerCleanup = __EXTENSIONJS_registerCleanup;\n }\n} catch (error) {}\n') + hostInstrumentationInline + devOnly('if (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try { __EXTENSIONJS_recordExecutionSnapshot("bootstrap"); } catch (error) {}\n}\nvar __EXTENSIONJS_previousEntry=__EXTENSIONJS_REINJECT_REGISTRY[__EXTENSIONJS_REINJECT_KEY];\nvar __EXTENSIONJS_REINJECT_GENERATION=__EXTENSIONJS_readReinjectGeneration(__EXTENSIONJS_previousEntry);\n// Sweep untagged orphans (prior-session roots that died before tagging)\n// before any further cleanup runs. Safe here because our mount has not\n// produced any roots yet, any untagged host is by definition not ours.\ntry { __EXTENSIONJS_cleanupOrphanRoots(); } catch (error) {}\ntry {\n var __EXTENSIONJS_previousCleanup=typeof __EXTENSIONJS_previousEntry === "function" ? __EXTENSIONJS_previousEntry : (__EXTENSIONJS_previousEntry && typeof __EXTENSIONJS_previousEntry.cleanup === "function" ? __EXTENSIONJS_previousEntry.cleanup : null);\n if (typeof __EXTENSIONJS_previousCleanup === "function") {\n if (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try {\n var __extjsPageRoot = document.documentElement;\n if (__extjsPageRoot && typeof __extjsPageRoot.setAttribute === "function") {\n __extjsPageRoot.setAttribute("data-extjs-debug-stage", "previous-cleanup");\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal", "previous-cleanup");\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal-source", "previous-cleanup");\n }\n } catch (error) {}\n }\n __EXTENSIONJS_previousCleanup();\n }\n} catch (error) {}\ntry { __EXTENSIONJS_cleanupKnownRoots(!__EXTENSIONJS_previousEntry); } catch (error) {}\n') + (!isShippedBundle || hasModuleGraph ? 'function __EXTENSIONJS_syncAssetBase(){\n try {\n var base = "";\n try {\n if (typeof globalThis === "object" && globalThis && globalThis.browser && globalThis.browser.runtime && typeof globalThis.browser.runtime.getURL === "function") base = String(globalThis.browser.runtime.getURL("/"));\n else if (typeof globalThis === "object" && globalThis && globalThis.chrome && globalThis.chrome.runtime && typeof globalThis.chrome.runtime.getURL === "function") base = String(globalThis.chrome.runtime.getURL("/"));\n } catch (error) {}\n' + (takesBridgeBase ? ' if (!base) base = __EXTENSIONJS_BRIDGE_BASE;\n' : '') + ' if (!base) {\n try {\n if (typeof document === "object" && document && document.documentElement) base = String(document.documentElement.getAttribute("data-extjs-extension-base") || "");\n } catch (error) {}\n }\n if (!base) return false;\n if (base.charAt(base.length - 1) !== "/") base += "/";\n if (typeof __webpack_require__ === "function" || typeof __webpack_require__ === "object") {\n try { __webpack_require__.p = base; } catch (error) {}\n try { __webpack_require__.b = base; } catch (error) {}\n }\n return true;\n } catch (error) {}\n return false;\n}\ntry {\n if (!__EXTENSIONJS_syncAssetBase()) {\n var __EXTENSIONJS_assetBaseRetries = 0;\n var __EXTENSIONJS_retryAssetBase = function(){\n try {\n if (__EXTENSIONJS_syncAssetBase()) return;\n } catch (error) {}\n if (__EXTENSIONJS_assetBaseRetries++ < 50) setTimeout(__EXTENSIONJS_retryAssetBase, 100);\n };\n __EXTENSIONJS_retryAssetBase();\n }\n} catch (error) {}\n' : '');
250
+ const bootstrap = `var __EXTENSIONJS_BUNDLE_KEY=${JSON.stringify(bundleKey)};\nvar __EXTENSIONJS_REINJECT_KEY=${JSON.stringify(reinjectKey)};\n` + (holdsBridgeBase ? `var __EXTENSIONJS_BRIDGE_BASE = ${extensionBaseFromFile(takesFromFile)};\ntry {\n var __EXTENSIONJS_html = document.documentElement;\n if (!__EXTENSIONJS_BRIDGE_BASE) __EXTENSIONJS_BRIDGE_BASE = String(__EXTENSIONJS_html.getAttribute(${baseAttribute}) || "");\n ${unlessExtensionAddress('__EXTENSIONJS_BRIDGE_BASE', baseScheme)}\n` + (takesBridgeBase ? sharesBridgeBase ? ` var __EXTENSIONJS_clearBase = function(){ ${dropsBaseGetter}try { if (__EXTENSIONJS_html.hasAttribute(${baseAttribute})) __EXTENSIONJS_html.removeAttribute(${baseAttribute}); } catch (error) {} };\n try { Promise.resolve().then(__EXTENSIONJS_clearBase); } catch (error) { __EXTENSIONJS_clearBase(); }\n` : ` ${dropsBaseGetter}if (__EXTENSIONJS_html.hasAttribute(${baseAttribute})) __EXTENSIONJS_html.removeAttribute(${baseAttribute});\n` : '') + ' if (__EXTENSIONJS_BRIDGE_BASE && typeof __webpack_require__ === "function") __webpack_require__.extjsBase = __EXTENSIONJS_BRIDGE_BASE;\n} catch (error) {}\n' : '') + devOnly(`var __EXTENSIONJS_REINJECT_BUILD_TOKEN=${JSON.stringify(buildToken)};\n`) + `var __EXTENSIONJS_NO_FOREIGN_ADOPT=${JSON.stringify(isBuiltInCompanion)};\n` + 'function __EXTENSIONJS_ownerToken(){\n var extId = "";\n try {\n var rt = (typeof globalThis === "object" && globalThis && ((globalThis.browser && globalThis.browser.runtime) || (globalThis.chrome && globalThis.chrome.runtime))) || null;\n if (rt && rt.id) extId = String(rt.id);\n } catch (error) {}\n return String(__EXTENSIONJS_REINJECT_KEY || "") + (extId ? "@" + extId : "");\n}\n' + devOnly(`var __EXTENSIONJS_DEV_MARKERS_ENABLED=${JSON.stringify(!isShippedBundle)};\nvar __EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED=${JSON.stringify(hostInstrumentationEnabled)};\n`) + (!isShippedBundle || bundleCssHydrationEnabled ? 'var __EXTENSIONJS_PRE_MOUNT_ROOTS = [];\nfunction __EXTENSIONJS_snapshotPreMountRoots(){\n try {\n if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;\n __EXTENSIONJS_PRE_MOUNT_ROOTS = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]"));\n } catch (error) { __EXTENSIONJS_PRE_MOUNT_ROOTS = []; }\n}\n__EXTENSIONJS_snapshotPreMountRoots();\n' : 'function __EXTENSIONJS_snapshotPreMountRoots(){}\n') + `${cssAssetUrlsInline}` + devOnly('var __EXTENSIONJS_REINJECT_REGISTRY=(typeof globalThis==="object" && globalThis ? (globalThis.__EXTENSIONJS_DEV_REINJECT__ || (globalThis.__EXTENSIONJS_DEV_REINJECT__={})) : {});\n') + 'var __EXTENSIONJS_REGISTERED_CLEANUPS=[];\n' + devOnly('function __EXTENSIONJS_readReinjectGeneration(entry){\n try {\n if (!entry) return 0;\n if (typeof entry === "function" && typeof entry.__extjsGeneration === "number") return entry.__extjsGeneration;\n if (typeof entry === "object") {\n if (typeof entry.__extjsGeneration === "number") return entry.__extjsGeneration;\n if (typeof entry.generation === "number") return entry.generation;\n if (typeof entry.cleanup === "function" && typeof entry.cleanup.__extjsGeneration === "number") return entry.cleanup.__extjsGeneration;\n }\n } catch (error) {}\n return 0;\n}\n') + 'function __EXTENSIONJS_runCleanups(list){\n try {\n if (!Array.isArray(list)) return;\n for (var i = list.length - 1; i >= 0; i--) {\n try { if (typeof list[i] === "function") list[i](); } catch (error) {}\n }\n } catch (error) {}\n}\nfunction __EXTENSIONJS_registerCleanup(fn){\n if (typeof fn === "function") __EXTENSIONJS_REGISTERED_CLEANUPS.push(fn);\n return fn;\n}\n' + devOnly(reinjectMarkerInline) + 'function __EXTENSIONJS_composeCleanup(primaryCleanup){\n return function(){\n try { if (typeof primaryCleanup === "function") primaryCleanup(); } catch (error) {}\n try { __EXTENSIONJS_runCleanups(__EXTENSIONJS_REGISTERED_CLEANUPS); } catch (error) {}\n' + devOnly(' try { __EXTENSIONJS_cleanupKnownRoots(); } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "cleaned"); } catch (error) {}\n') + " };\n}\n" + devOnly('function __EXTENSIONJS_recordExecutionSnapshot(stage){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_ENABLED) return;\n if (typeof document === "undefined") return;\n var pageRoot = document.documentElement;\n if (!pageRoot || typeof pageRoot.getAttribute !== "function" || typeof pageRoot.setAttribute !== "function") return;\n var currentCount = Number(pageRoot.getAttribute("data-extjs-debug-execution-count") || "0");\n var nextCount = Number.isFinite(currentCount) ? currentCount + 1 : 1;\n var roots = [];\n try { roots = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])")); } catch (error) {}\n pageRoot.setAttribute("data-extjs-debug-execution-count", String(nextCount));\n pageRoot.setAttribute("data-extjs-debug-last-execution-stage", String(stage || ""));\n pageRoot.setAttribute("data-extjs-debug-last-execution-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-existing-root-count-before-cleanup", String(roots.length));\n } catch (error) {}\n}\n') + (isShippedBundle && isMainWorld ? '' : 'try {\n if (typeof globalThis === "object" && globalThis) {\n globalThis.__EXTENSIONJS_registerCleanup = __EXTENSIONJS_registerCleanup;\n }\n} catch (error) {}\n') + hostInstrumentationInline + devOnly('if (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try { __EXTENSIONJS_recordExecutionSnapshot("bootstrap"); } catch (error) {}\n}\nvar __EXTENSIONJS_previousEntry=__EXTENSIONJS_REINJECT_REGISTRY[__EXTENSIONJS_REINJECT_KEY];\nvar __EXTENSIONJS_REINJECT_GENERATION=__EXTENSIONJS_readReinjectGeneration(__EXTENSIONJS_previousEntry);\n// Sweep untagged orphans (prior-session roots that died before tagging)\n// before any further cleanup runs. Safe here because our mount has not\n// produced any roots yet, any untagged host is by definition not ours.\ntry { __EXTENSIONJS_cleanupOrphanRoots(); } catch (error) {}\ntry {\n var __EXTENSIONJS_previousCleanup=typeof __EXTENSIONJS_previousEntry === "function" ? __EXTENSIONJS_previousEntry : (__EXTENSIONJS_previousEntry && typeof __EXTENSIONJS_previousEntry.cleanup === "function" ? __EXTENSIONJS_previousEntry.cleanup : null);\n if (typeof __EXTENSIONJS_previousCleanup === "function") {\n if (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try {\n var __extjsPageRoot = document.documentElement;\n if (__extjsPageRoot && typeof __extjsPageRoot.setAttribute === "function") {\n __extjsPageRoot.setAttribute("data-extjs-debug-stage", "previous-cleanup");\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal", "previous-cleanup");\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal-source", "previous-cleanup");\n }\n } catch (error) {}\n }\n __EXTENSIONJS_previousCleanup();\n }\n} catch (error) {}\ntry { __EXTENSIONJS_cleanupKnownRoots(!__EXTENSIONJS_previousEntry); } catch (error) {}\n') + (!isShippedBundle || hasModuleGraph ? 'function __EXTENSIONJS_syncAssetBase(){\n try {\n var base = "";\n' + asksRuntime(' try {\n if (typeof globalThis === "object" && globalThis && globalThis.browser && globalThis.browser.runtime && typeof globalThis.browser.runtime.getURL === "function") base = String(globalThis.browser.runtime.getURL("/"));\n else if (typeof globalThis === "object" && globalThis && globalThis.chrome && globalThis.chrome.runtime && typeof globalThis.chrome.runtime.getURL === "function") base = String(globalThis.chrome.runtime.getURL("/"));\n } catch (error) {}\n') + (holdsBridgeBase ? ' if (!base) base = __EXTENSIONJS_BRIDGE_BASE;\n' : '') + " if (!base) {\n try {\n" + ` if (typeof document === "object" && document && document.documentElement) base = String(document.documentElement.getAttribute(${baseAttribute}) || "");\n` + " } catch (error) {}\n }\n" + ` ${unlessExtensionAddress('base', baseScheme)}\n` + ' if (!base) return false;\n' + (takesFromFile ? ' if (base[base.length - 1] !== "/") base += "/";\n' : ' if (base.charAt(base.length - 1) !== "/") base += "/";\n') + ' if (typeof __webpack_require__ === "function" || typeof __webpack_require__ === "object") {\n try { __webpack_require__.p = base; } catch (error) {}\n try { __webpack_require__.b = base; } catch (error) {}\n }\n return true;\n } catch (error) {}\n return false;\n}\ntry {\n if (!__EXTENSIONJS_syncAssetBase()) {\n var __EXTENSIONJS_assetBaseRetries = 0;\n var __EXTENSIONJS_retryAssetBase = function(){\n try {\n if (__EXTENSIONJS_syncAssetBase()) return;\n } catch (error) {}\n if (__EXTENSIONJS_assetBaseRetries++ < 50) setTimeout(__EXTENSIONJS_retryAssetBase, 100);\n };\n __EXTENSIONJS_retryAssetBase();\n }\n} catch (error) {}\n' : '');
217
251
  const runtimeInline = `function __EXTENSIONJS_whenReady(runAt, cb){\n try {\n if (typeof document === 'undefined') { cb(); return function(){} }\n if (runAt === 'document_start') { cb(); return function(){} }\n var isDone = false;\n function isReady(){\n if (runAt === 'document_end') return document.readyState === 'interactive' || document.readyState === 'complete';\n if (runAt === 'document_idle') return document.readyState === 'complete';\n return document.readyState === 'complete';\n }\n if (isReady()) { cb(); return function(){} }\n var onReady = function(){\n try {\n if (isDone) return;\n if (isReady()) { isDone = true; document.removeEventListener('readystatechange', onReady); cb(); }\n } catch (error) {}\n };\n document.addEventListener('readystatechange', onReady);\n return function(){ try { if (!isDone) document.removeEventListener('readystatechange', onReady); } catch (error) {} };\n } catch (error) { try { cb(); } catch (ignored) {} return function(){} }\n}\n${bundleCssHydrationInline}function __EXTENSIONJS_mount(mount, runAt){\n var cleanup = function(){};\n var cancelReady = function(){};\n if (typeof mount !== "function") {\n` + devOnly(' try { __EXTENSIONJS_REINJECT_GENERATION = (Number(__EXTENSIONJS_REINJECT_GENERATION) || 0) + 1; } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "executed"); } catch (error) {}\n') + " try { __EXTENSIONJS_scheduleBundleCssHydration(); } catch (error) {}\n return __EXTENSIONJS_composeCleanup(null);\n }\n function apply(){\n try {\n __EXTENSIONJS_snapshotPreMountRoots();\n var nextCleanup = mount();\n cleanup = __EXTENSIONJS_composeCleanup(nextCleanup);\n" + devOnly(' __EXTENSIONJS_REINJECT_GENERATION = (Number(__EXTENSIONJS_REINJECT_GENERATION) || 0) + 1;\n try { unmount.__extjsGeneration = __EXTENSIONJS_REINJECT_GENERATION; unmount.__extjsKey = __EXTENSIONJS_REINJECT_KEY; } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, __EXTENSIONJS_REINJECT_GENERATION, "mounted"); } catch (error) {}\n') + ' try { __EXTENSIONJS_scheduleBundleCssHydration(); } catch (error) {}\n } catch (error) {\n try { console.warn("Extension.js: the content script default export failed to run.", error); } catch (ignored) {}\n' + devOnly(' try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "mount-error"); } catch (ignored) {}\n') + " }\n }\n function unmount(){ try { cancelReady && cancelReady(); } catch (error) {} try { if (typeof cleanup === 'function') cleanup(); } catch (error) {} }\n cancelReady = __EXTENSIONJS_whenReady(runAt, apply);\n return unmount;\n}\n";
218
252
  if (!hasDefaultExport(rewrittenSource, this.resourcePath, compilation)) {
219
253
  if (!isShippedBundle && declaredEntry && !hintedEntriesWithoutDefaultExport.has(resourceAbsPath)) {
220
254
  hintedEntriesWithoutDefaultExport.add(resourceAbsPath);
221
- humanLine(contentScriptWithoutDefaultExport(node_path.relative(packageJsonDir, resourceAbsPath).split(node_path.sep).join('/') || resourceAbsPath));
255
+ humanLine(contentScriptWithoutDefaultExport(node_path.relative(packageJsonDir, resourceAbsPath).split(node_path.sep).join('/') || resourceAbsPath, isChromiumBasedBrowser(browser)));
222
256
  }
223
257
  const prefix = `var __EXTJS_WRAPPER_KIND="FS3_INLINE";\n${bootstrap}${runtimeInline}`;
224
258
  const suffix = devOnly(`try { __EXTENSIONJS_REINJECT_GENERATION = (Number(__EXTENSIONJS_REINJECT_GENERATION) || 0) + 1; } catch (error) {
@@ -230,7 +264,11 @@ function contentScriptWrapper(source, inputSourceMap) {
230
264
  }\n` + devOnly(`try { __EXTENSIONJS_REINJECT_REGISTRY[__EXTENSIONJS_REINJECT_KEY] = { cleanup: __EXTENSIONJS_composeCleanup(null), generation: Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, build: __EXTENSIONJS_REINJECT_BUILD_TOKEN }; } catch (error) {
231
265
  // Ignore
232
266
  }\n`);
233
- const wrapped = `${prefix}${rewrittenSource}\n${suffix}`;
267
+ const endsOnItsValue = Boolean(isScriptsFolderScript) && !declaredEntry && (true !== options.mainWorldBundle || isRuntimeMainWorld);
268
+ const body = endsOnItsValue ? keepCompletionValue(rewrittenSource, this.resourcePath, {
269
+ importsAnotherScript: importsScriptsFile(rewrittenSource, resourceAbsPath, String(scriptsDir))
270
+ }) : rewrittenSource;
271
+ const wrapped = `${prefix}${body}\n${suffix}`;
234
272
  return returnWithMap(this, wrapped, adjustLoaderSourceMap(inputOrIdentityMap(inputSourceMap, this.resourcePath, rewrittenSource), {
235
273
  prefix,
236
274
  before: rewrittenSource,
@@ -3,15 +3,18 @@ import node_fs from "node:fs";
3
3
  import node_path from "node:path";
4
4
  import { parse } from "es-module-lexer";
5
5
  import { validate } from "schema-utils";
6
- import { contentScriptWithoutDefaultExport, reservedScriptsFolder } from "./519~0.mjs";
7
- import { filterKeysForThisBrowser } from "./143~0.mjs";
8
- import { stripBom } from "./374~0.mjs";
9
- import { canonicalizeDir, canonicalizeResourcePath } from "./712~0.mjs";
10
- import { findNearestProjectManifestSync } from "./731~0.mjs";
11
- import { getCanonicalContentScriptEntryName, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX, getContentScriptCssProbeMarker } from "./640~0.mjs";
12
- import { EXTENSION_BASE_FROM_STACK } from "./527~0.mjs";
13
- import { humanLine } from "./852~0.mjs";
14
- import { returnWithMap, adjustLoaderSourceMap, inputOrIdentityMap } from "./895~0.mjs";
6
+ import { getCanonicalContentScriptEntryName, getContentScriptCssProbeMarker, MAIN_WORLD_COPY_SUFFIX, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX } from "./bh~0.mjs";
7
+ import { contentScriptWithoutDefaultExport, reservedScriptsFolder } from "./rl~0.mjs";
8
+ import { keepCompletionValue } from "./df~0.mjs";
9
+ import { extensionBaseAttributeFor, extensionBaseGlobalFor } from "./o~0.mjs";
10
+ import { filterKeysForThisBrowser } from "./ey~0.mjs";
11
+ import { stripBom } from "./5~0.mjs";
12
+ import { canonicalizeDir, canonicalizeResourcePath } from "./ka~0.mjs";
13
+ import { findNearestProjectManifestSync } from "./j~0.mjs";
14
+ import { isChromiumBasedBrowser, isGeckoBasedBrowser } from "./q~0.mjs";
15
+ import { extensionSchemeFor, unlessExtensionAddress, closedOnSlash, extensionBaseFromFile } from "./c~0.mjs";
16
+ import { humanLine } from "./k~0.mjs";
17
+ import { returnWithMap, adjustLoaderSourceMap, inputOrIdentityMap } from "./3~0.mjs";
15
18
  const schema = {
16
19
  type: 'object',
17
20
  properties: {
@@ -33,6 +36,15 @@ const schema = {
33
36
  type: 'string'
34
37
  }
35
38
  },
39
+ mainWorldCopies: {
40
+ type: 'array',
41
+ items: {
42
+ type: 'string'
43
+ }
44
+ },
45
+ mainWorldBundle: {
46
+ type: 'boolean'
47
+ },
36
48
  scriptsFolder: {
37
49
  anyOf: [
38
50
  {
@@ -115,6 +127,18 @@ function hasDefaultExport(source, resourcePath, compilationArg) {
115
127
  return fallback;
116
128
  }
117
129
  }
130
+ function importsScriptsFile(source, resourceAbsPath, scriptsDir) {
131
+ try {
132
+ const [imports] = parse(source);
133
+ return imports.some(({ specifier })=>{
134
+ if ('string' != typeof specifier || !specifier.startsWith('.')) return false;
135
+ const relative = node_path.relative(scriptsDir, node_path.resolve(node_path.dirname(resourceAbsPath), specifier));
136
+ return !relative.startsWith('..') && !node_path.isAbsolute(relative);
137
+ });
138
+ } catch {
139
+ return /\bfrom\s*["']\.|\bimport\s*["']\./.test(source);
140
+ }
141
+ }
118
142
  const hintedEntriesWithoutDefaultExport = new Set();
119
143
  const __EXTENSIONJS_manifestParseCache = new Map();
120
144
  function readManifestCached(manifestPath, browser) {
@@ -195,30 +219,40 @@ function contentScriptWrapper(source, inputSourceMap) {
195
219
  return rewrittenSource;
196
220
  }
197
221
  const runAt = declaredEntry?.runAt || 'document_idle';
198
- const isRuntimeMainWorld = (options.mainWorldScripts || []).some((candidate)=>resourceAbsPath === canonicalizeResourcePath(candidate));
199
- const isMainWorld = declaredEntry?.world === 'MAIN' || isRuntimeMainWorld;
222
+ const namedIn = (files)=>(files || []).some((candidate)=>resourceAbsPath === canonicalizeResourcePath(candidate));
223
+ const isMainWorldCopy = true === options.mainWorldBundle && namedIn(options.mainWorldCopies);
224
+ const isRuntimeMainWorld = namedIn(options.mainWorldScripts) || isMainWorldCopy;
225
+ const isMainWorld = declaredEntry?.world === 'MAIN' || isRuntimeMainWorld || true === options.mainWorldBundle;
200
226
  const hostInstrumentationEnabled = !isShippedBundle && !isMainWorld;
201
- const takesBridgeBase = isShippedBundle && declaredEntry?.world === 'MAIN';
202
- const takenBridgeBase = takesBridgeBase ? '__EXTENSIONJS_BRIDGE_BASE || ' : '';
203
- const bundleKey = declaredEntry ? getCanonicalContentScriptEntryName(declaredEntry.index) : `scripts/${String(relToScripts || '').replace(/\\/g, '/')}`;
227
+ const sharesBridgeBase = !declaredEntry && isRuntimeMainWorld && isShippedBundle && isGeckoBasedBrowser(browser);
228
+ const takesBridgeBase = sharesBridgeBase || declaredEntry?.world === 'MAIN' && (isShippedBundle || isChromiumBasedBrowser(browser));
229
+ const takesFromFile = isMainWorld && isGeckoBasedBrowser(browser);
230
+ const holdsBridgeBase = takesBridgeBase || takesFromFile;
231
+ const baseAttribute = JSON.stringify(extensionBaseAttributeFor(manifestPath, browser));
232
+ const baseScheme = extensionSchemeFor(String(browser));
233
+ const asksRuntime = (lines)=>takesFromFile ? '' : lines;
234
+ const takenBridgeBase = holdsBridgeBase ? '__EXTENSIONJS_BRIDGE_BASE || ' : '';
235
+ const dropsBaseGetter = takesFromFile ? `try { delete window.${extensionBaseGlobalFor(manifestPath, browser)}; } catch (error) {} ` : '';
236
+ const scriptKey = `scripts/${String(relToScripts || '').replace(/\\/g, '/')}`;
237
+ const bundleKey = declaredEntry ? getCanonicalContentScriptEntryName(declaredEntry.index) : isMainWorldCopy ? scriptKey.replace(/(\.[^./]+)?$/, `${MAIN_WORLD_COPY_SUFFIX}$1`) : scriptKey;
204
238
  const reinjectKey = declaredEntry ? `${bundleKey}::script-${declaredEntry.scriptIndex}` : bundleKey;
205
239
  const buildToken = createBuildToken(rewrittenSource);
206
240
  const cssProbeMarker = getContentScriptCssProbeMarker(bundleKey);
207
241
  const cssAssetSpecifiers = collectStyleAssetSpecifiers(rewrittenSource);
208
242
  const cssAssetUrlsInline = `var __EXTENSIONJS_BUNDLE_CSS_URLS=[${cssAssetSpecifiers.map((specifier)=>`(function(){ try { return String(new URL(${escapeCodeString(JSON.stringify(specifier))}, import.meta.url)); } catch (error) { return ""; } })()`).join(',')}];\n`;
209
- const bundleCssHydrationBody = `function __EXTENSIONJS_runtimeGetURL(path){\n try {\n if (typeof globalThis === "object" && globalThis && globalThis.browser && globalThis.browser.runtime && typeof globalThis.browser.runtime.getURL === "function") return globalThis.browser.runtime.getURL(path);\n if (typeof globalThis === "object" && globalThis && globalThis.chrome && globalThis.chrome.runtime && typeof globalThis.chrome.runtime.getURL === "function") return globalThis.chrome.runtime.getURL(path);\n } catch (error) {}\n try {\n var base = ${takenBridgeBase}((typeof globalThis === "object" && globalThis && globalThis.__EXTJS_EXTENSION_BASE__) ? String(globalThis.__EXTJS_EXTENSION_BASE__) : "");\n if (!base && typeof document === "object" && document && document.documentElement) base = String(document.documentElement.getAttribute("data-extjs-extension-base") || "");\n if (!base) return "";\n return base.replace(/\\/+\$/, "/") + String(path || "").replace(/^\\/+/, "");\n } catch (error) {}\n return "";\n}\nvar __EXTENSIONJS_BUNDLE_CSS_PROBE=${JSON.stringify(cssProbeMarker)};\nfunction __EXTENSIONJS_bundleCssProbeUrls(){\n try {\n var probe = String(__EXTENSIONJS_BUNDLE_CSS_PROBE || "");\n if (!probe.length) return [];\n if (probe.lastIndexOf("__EXTENSIONJS_CSS_PROBE", 0) === 0) return [];\n var url = __EXTENSIONJS_runtimeGetURL(probe);\n if (typeof url !== "string" || !url.length) return [];\n if (url.charAt(url.length - 1) === "/") return [];\n return [url];\n } catch (error) { return []; }\n}\nfunction __EXTENSIONJS_scheduleBundleCssHydration(){\n try {\n if (String(__EXTENSIONJS_BUNDLE_KEY || "").indexOf(${JSON.stringify(CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX)}) !== 0) return;\n if (typeof document === "undefined" || typeof fetch !== "function") return;\n var cssUrls = Array.from(new Set((Array.isArray(__EXTENSIONJS_BUNDLE_CSS_URLS) ? __EXTENSIONJS_BUNDLE_CSS_URLS : []).concat(__EXTENSIONJS_bundleCssProbeUrls()).filter(function(value){ return typeof value === "string" && value.trim().length > 0; })));\n if (!cssUrls.length) return;\n var cssText = "";\n var cssPromise = null;\n var readCss = function(){\n if (cssPromise) return cssPromise;\n cssPromise = Promise.all(cssUrls.map(function(url){\n return Promise.resolve().then(function(){ return fetch(url); }).then(function(response){\n if (!response || !response.ok) return "";\n return response.text();\n }).catch(function(){\n return "";\n });\n })).then(function(texts){\n var seen = [];\n for (var t = 0; t < texts.length; t++) {\n if (typeof texts[t] !== "string" || !texts[t].trim().length || seen.indexOf(texts[t]) !== -1) continue;\n seen.push(texts[t]);\n }\n return seen.join("\\n");\n }).then(function(text){\n cssText = typeof text === "string" ? text : "";\n var root = __EXTENSIONJS_runtimeGetURL("/");\n if (root) cssText = cssText.replace(/url\\(\\s*(["\']?)\\/(?!\\/)/gi, function(match, quote){ return "url(" + quote + root; });\n try { setTimeout(tick, 0); } catch (error) {}\n return cssText;\n }).catch(function(){ return ""; });\n return cssPromise;\n };\n var tries = 0;\n var wanted = false;\n var tick = function(){\n try {\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var hosts = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n for (var i = 0; i < hosts.length; i++) {\n var host = hosts[i];\n if (!host || !host.shadowRoot || typeof host.getAttribute !== "function") continue;\n` + devOnly(' var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (hostOwner && hostOwner !== __extjsToken) continue;\n if (!hostOwner && __EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (!hostOwner && __EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n if (!hostOwner && String(host.getAttribute("data-extjs-reinject-key") || "") && String(host.getAttribute("data-extjs-reinject-key") || "") !== String(__EXTENSIONJS_BUNDLE_KEY || "")) continue;\n') + (isShippedBundle ? " if (__EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (__EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n" : '') + ' var sr = host.shadowRoot;\n var styles = Array.from(sr.querySelectorAll("style"));\n var hasUserStyle = styles.some(function(styleEl){\n return styleEl && styleEl.getAttribute("data-extjs-bundle-css") !== "true" && String(styleEl.textContent || "").trim().length > 0;\n });\n var injected = null;\n for (var s = 0; s < styles.length; s++) {\n if (!styles[s] || styles[s].getAttribute("data-extjs-bundle-css") !== "true") continue;\n var styleOwner = String(styles[s].getAttribute("data-extjs-style-owner") || "");\n if (!styleOwner || styleOwner === __extjsToken) { injected = styles[s]; break; }\n }\n if (hasUserStyle) {\n if (injected && injected.parentNode) injected.parentNode.removeChild(injected);\n return;\n }\n if (typeof cssText === "string" && cssText.trim()) {\n if (!injected) {\n injected = document.createElement("style");\n injected.setAttribute("data-extjs-bundle-css", "true");\n injected.setAttribute("data-extjs-reinject-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n sr.insertBefore(injected, sr.firstChild || null);\n }\n injected.setAttribute("data-extjs-style-owner", __extjsToken);\n if (String(injected.textContent || "") !== cssText) injected.textContent = cssText;\n return;\n }\n wanted = true;\n }\n } catch (error) {}\n if (tries++ < 20) {\n' + (isShippedBundle ? ' if (wanted && !cssPromise) readCss();\n' : ' if (!cssPromise) readCss();\n') + " setTimeout(tick, 250);\n }\n };\n tick();\n } catch (error) {}\n}\n";
243
+ const bundleCssHydrationBody = 'function __EXTENSIONJS_runtimeGetURL(path){\n' + asksRuntime(' try {\n if (typeof globalThis === "object" && globalThis && globalThis.browser && globalThis.browser.runtime && typeof globalThis.browser.runtime.getURL === "function") return globalThis.browser.runtime.getURL(path);\n if (typeof globalThis === "object" && globalThis && globalThis.chrome && globalThis.chrome.runtime && typeof globalThis.chrome.runtime.getURL === "function") return globalThis.chrome.runtime.getURL(path);\n } catch (error) {}\n') + ' try {\n' + (takesFromFile ? ' var base = __EXTENSIONJS_BRIDGE_BASE;\n' : ` var base = ${takenBridgeBase}"";\n`) + ` if (!base && typeof document === "object" && document && document.documentElement) base = String(document.documentElement.getAttribute(${baseAttribute}) || "");\n` + ` ${unlessExtensionAddress('base', baseScheme)}\n` + ' if (!base) return "";\n' + (takesFromFile ? ` return ${closedOnSlash('base')} + String(path || "").replace(/^\\/+/, "");\n` : ' return base.replace(/\\/+$/, "/") + String(path || "").replace(/^\\/+/, "");\n') + ' } catch (error) {}\n return "";\n}\n' + `var __EXTENSIONJS_BUNDLE_CSS_PROBE=${JSON.stringify(cssProbeMarker)};\n` + 'function __EXTENSIONJS_bundleCssProbeUrls(){\n try {\n var probe = String(__EXTENSIONJS_BUNDLE_CSS_PROBE || "");\n if (!probe.length) return [];\n if (probe.lastIndexOf("__EXTENSIONJS_CSS_PROBE", 0) === 0) return [];\n var url = __EXTENSIONJS_runtimeGetURL(probe);\n if (typeof url !== "string" || !url.length) return [];\n if (url.charAt(url.length - 1) === "/") return [];\n return [url];\n } catch (error) { return []; }\n}\nfunction __EXTENSIONJS_scheduleBundleCssHydration(){\n try {\n' + ` if (String(__EXTENSIONJS_BUNDLE_KEY || "").indexOf(${JSON.stringify(CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX)}) !== 0) return;\n` + ' if (typeof document === "undefined" || typeof fetch !== "function") return;\n var cssUrls = Array.from(new Set((Array.isArray(__EXTENSIONJS_BUNDLE_CSS_URLS) ? __EXTENSIONJS_BUNDLE_CSS_URLS : []).concat(__EXTENSIONJS_bundleCssProbeUrls()).filter(function(value){ return typeof value === "string" && value.trim().length > 0; })));\n if (!cssUrls.length) return;\n var cssText = "";\n var cssPromise = null;\n var readCss = function(){\n if (cssPromise) return cssPromise;\n cssPromise = Promise.all(cssUrls.map(function(url){\n return Promise.resolve().then(function(){ return fetch(url); }).then(function(response){\n if (!response || !response.ok) return "";\n return response.text();\n }).catch(function(){\n return "";\n });\n })).then(function(texts){\n var seen = [];\n for (var t = 0; t < texts.length; t++) {\n if (typeof texts[t] !== "string" || !texts[t].trim().length || seen.indexOf(texts[t]) !== -1) continue;\n seen.push(texts[t]);\n }\n return seen.join("\\n");\n }).then(function(text){\n cssText = typeof text === "string" ? text : "";\n var root = __EXTENSIONJS_runtimeGetURL("/");\n if (root) cssText = cssText.replace(/url\\(\\s*(["\']?)\\/(?!\\/)/gi, function(match, quote){ return "url(" + quote + root; });\n try { setTimeout(tick, 0); } catch (error) {}\n return cssText;\n }).catch(function(){ return ""; });\n return cssPromise;\n };\n var tries = 0;\n var wanted = false;\n var tick = function(){\n try {\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var hosts = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n for (var i = 0; i < hosts.length; i++) {\n var host = hosts[i];\n if (!host || !host.shadowRoot || typeof host.getAttribute !== "function") continue;\n' + devOnly(' var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (hostOwner && hostOwner !== __extjsToken) continue;\n if (!hostOwner && __EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (!hostOwner && __EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n if (!hostOwner && String(host.getAttribute("data-extjs-reinject-key") || "") && String(host.getAttribute("data-extjs-reinject-key") || "") !== String(__EXTENSIONJS_BUNDLE_KEY || "")) continue;\n') + (isShippedBundle ? " if (__EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (__EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n" : '') + ' var sr = host.shadowRoot;\n var styles = Array.from(sr.querySelectorAll("style"));\n var hasUserStyle = styles.some(function(styleEl){\n return styleEl && styleEl.getAttribute("data-extjs-bundle-css") !== "true" && String(styleEl.textContent || "").trim().length > 0;\n });\n var injected = null;\n for (var s = 0; s < styles.length; s++) {\n if (!styles[s] || styles[s].getAttribute("data-extjs-bundle-css") !== "true") continue;\n var styleOwner = String(styles[s].getAttribute("data-extjs-style-owner") || "");\n if (!styleOwner || styleOwner === __extjsToken) { injected = styles[s]; break; }\n }\n if (hasUserStyle) {\n if (injected && injected.parentNode) injected.parentNode.removeChild(injected);\n return;\n }\n if (typeof cssText === "string" && cssText.trim()) {\n if (!injected) {\n injected = document.createElement("style");\n injected.setAttribute("data-extjs-bundle-css", "true");\n injected.setAttribute("data-extjs-reinject-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n sr.insertBefore(injected, sr.firstChild || null);\n }\n injected.setAttribute("data-extjs-style-owner", __extjsToken);\n if (String(injected.textContent || "") !== cssText) injected.textContent = cssText;\n return;\n }\n wanted = true;\n }\n } catch (error) {}\n if (tries++ < 20) {\n' + (isShippedBundle ? ' if (wanted && !cssPromise) readCss();\n' : ' if (!cssPromise) readCss();\n') + " setTimeout(tick, 250);\n }\n };\n tick();\n } catch (error) {}\n}\n";
210
244
  const hasModuleGraph = cssAssetSpecifiers.length > 0 || hasModuleDependency(rewrittenSource);
211
245
  const bundleCssHydrationEnabled = bundleKey.startsWith(CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX) && hasModuleGraph;
212
246
  const bundleCssHydrationInline = bundleCssHydrationEnabled ? bundleCssHydrationBody : 'function __EXTENSIONJS_scheduleBundleCssHydration(){}\n';
213
247
  const isBuiltInCompanion = /extension-js-(?:devtools|theme)/.test(String(packageJsonDir || ''));
214
248
  const hostInstrumentationInline = hostInstrumentationEnabled ? 'function __EXTENSIONJS_debugObserveOwnedRootRemoval(){\n try {\n if (!__EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED) return;\n if (typeof globalThis !== "object" || !globalThis || globalThis.__EXTJS_DEBUG_REMOVAL_OBSERVER__) return;\n if (typeof MutationObserver !== "function" || typeof document === "undefined") return;\n var target = document.documentElement || document.body || document;\n if (!target) return;\n var observer = new MutationObserver(function(records){\n try {\n var ownedKey = __EXTENSIONJS_ownerToken();\n var findOwnedRoot = function(node){\n try {\n if (!node || node.nodeType !== 1) return null;\n if (typeof node.getAttribute === "function" && String(node.getAttribute("data-extjs-reinject-owner") || "") === ownedKey) return node;\n if (typeof node.querySelector === "function") {\n return node.querySelector("[data-extjs-reinject-owner=\\"" + ownedKey.replace(/"/g, "\\\\\\"") + "\\"]");\n }\n } catch (error) {}\n return null;\n };\n for (var r = 0; r < records.length; r++) {\n var removedNodes = Array.from(records[r].removedNodes || []);\n for (var n = 0; n < removedNodes.length; n++) {\n var node = removedNodes[n];\n var ownedRoot = findOwnedRoot(node);\n if (!ownedRoot || typeof ownedRoot.getAttribute !== "function") continue;\n var owner = String(ownedRoot.getAttribute("data-extjs-reinject-owner") || "");\n if (!owner || owner !== ownedKey) continue;\n var pageRoot = document.documentElement;\n if (pageRoot && typeof pageRoot.setAttribute === "function") {\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal")) pageRoot.setAttribute("data-extjs-debug-last-removal", "mutation-observer");\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal-key")) pageRoot.setAttribute("data-extjs-debug-last-removal-key", owner);\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal-source")) pageRoot.setAttribute("data-extjs-debug-last-removal-source", "mutation-observer");\n if (!pageRoot.getAttribute("data-extjs-debug-last-removed-node-tag")) pageRoot.setAttribute("data-extjs-debug-last-removed-node-tag", String(node.tagName || "").toLowerCase());\n if (!pageRoot.getAttribute("data-extjs-debug-last-removed-node-id")) pageRoot.setAttribute("data-extjs-debug-last-removed-node-id", String(node.id || ""));\n if (!pageRoot.getAttribute("data-extjs-debug-last-removed-node-class")) pageRoot.setAttribute("data-extjs-debug-last-removed-node-class", String(node.className || ""));\n if (!pageRoot.getAttribute("data-extjs-debug-last-removed-node-direct")) pageRoot.setAttribute("data-extjs-debug-last-removed-node-direct", String(node === ownedRoot));\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal-ready-state")) pageRoot.setAttribute("data-extjs-debug-last-removal-ready-state", String(document.readyState || ""));\n if (!pageRoot.getAttribute("data-extjs-debug-last-removal-url")) pageRoot.setAttribute("data-extjs-debug-last-removal-url", String(location.href || ""));\n pageRoot.setAttribute("data-extjs-debug-stage", "root-removed-observed");\n }\n return;\n }\n }\n } catch (error) {}\n });\n observer.observe(target, { childList: true, subtree: true });\n globalThis.__EXTJS_DEBUG_REMOVAL_OBSERVER__ = observer;\n } catch (error) {}\n}\nfunction __EXTENSIONJS_patchDomRemovalApis(){\n try {\n if (!__EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED) return;\n if (typeof globalThis !== "object" || !globalThis || globalThis.__EXTJS_DEBUG_DOM_APIS_PATCHED__) return;\n var record = function(source, node, parent){\n try {\n var pageRoot = document.documentElement;\n if (!pageRoot || typeof pageRoot.setAttribute !== "function") return;\n var ownedRoot = null;\n if (node && node.nodeType === 1) {\n if (typeof node.getAttribute === "function" && String(node.getAttribute("data-extjs-reinject-owner") || "") === __EXTENSIONJS_ownerToken()) ownedRoot = node;\n else if (typeof node.querySelector === "function") ownedRoot = node.querySelector("[data-extjs-reinject-owner=\\"" + __EXTENSIONJS_ownerToken().replace(/"/g, "\\\\\\"") + "\\"]");\n }\n if (!ownedRoot) return;\n pageRoot.setAttribute("data-extjs-debug-stage", "dom-api-removal");\n pageRoot.setAttribute("data-extjs-debug-last-removal", source);\n pageRoot.setAttribute("data-extjs-debug-last-removal-source", source);\n pageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-tag", String(node && node.tagName || "").toLowerCase());\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-id", String(node && node.id || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-class", String(node && node.className || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-direct", String(node === ownedRoot));\n pageRoot.setAttribute("data-extjs-debug-last-removal-ready-state", String(document.readyState || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removal-url", String(location.href || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removal-parent-tag", String(parent && parent.tagName || "").toLowerCase());\n } catch (error) {}\n };\n try {\n var originalRemoveChild = Node.prototype.removeChild;\n if (typeof originalRemoveChild === "function") {\n Node.prototype.removeChild = function(child){\n record("Node.removeChild", child, this);\n return originalRemoveChild.call(this, child);\n };\n }\n } catch (error) {}\n try {\n var originalReplaceChildren = Element.prototype.replaceChildren;\n if (typeof originalReplaceChildren === "function") {\n Element.prototype.replaceChildren = function(){\n try {\n var existing = Array.from(this.childNodes || []);\n for (var i = 0; i < existing.length; i++) record("Element.replaceChildren", existing[i], this);\n } catch (error) {}\n return originalReplaceChildren.apply(this, arguments);\n };\n }\n } catch (error) {}\n globalThis.__EXTJS_DEBUG_DOM_APIS_PATCHED__ = true;\n } catch (error) {}\n}\nif (__EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED) {\n try { __EXTENSIONJS_debugObserveOwnedRootRemoval(); } catch (error) {}\n try { __EXTENSIONJS_patchDomRemovalApis(); } catch (error) {}\n}\n' : '';
215
249
  const reinjectMarkerInline = 'function __EXTENSIONJS_setReinjectMarker(key, generation, status){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_ENABLED || typeof document === "undefined") return;\n var root = document.body || document.documentElement;\n if (!root) return;\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var marker = null;\n try {\n var markers = Array.from(document.querySelectorAll("[data-extjs-reinject-marker=\\"true\\"]"));\n for (var i = 0; i < markers.length; i++) {\n var current = markers[i];\n if (!current || typeof current.getAttribute !== "function") continue;\n var currentOwner = String(current.getAttribute("data-extjs-marker-owner") || "");\n if (currentOwner === __extjsToken) { marker = current; break; }\n if (!currentOwner && current.getAttribute("data-extjs-reinject-key") === key) { marker = current; break; }\n }\n } catch (error) {}\n if (!marker && typeof document.createElement === "function") {\n marker = document.createElement("div");\n marker.setAttribute("data-extjs-reinject-marker", "true");\n marker.setAttribute("hidden", "");\n marker.setAttribute("aria-hidden", "true");\n try { marker.style.display = "none"; } catch (error) {}\n root.appendChild(marker);\n }\n if (!marker) return;\n marker.setAttribute("data-extjs-reinject-key", String(__EXTENSIONJS_BUNDLE_KEY || key || ""));\n marker.setAttribute("data-extjs-marker-owner", __extjsToken);\n marker.setAttribute("data-extjs-reinject-generation", String(generation));\n marker.setAttribute("data-extjs-reinject-status", String(status || "mounted"));\n marker.setAttribute("data-extjs-reinject-build", String(__EXTENSIONJS_REINJECT_BUILD_TOKEN || ""));\n try { marker.textContent = String(__EXTENSIONJS_BUNDLE_KEY || key || "") + ":" + String(generation) + ":" + String(status || "mounted"); } catch (error) {}\n try {\n var roots = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n var ownedRootCount = 0;\n for (var j = 0; j < roots.length; j++) {\n var host = roots[j];\n if (!host || typeof host.setAttribute !== "function") continue;\n var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (hostOwner && hostOwner !== __extjsToken) continue;\n if (!hostOwner && __EXTENSIONJS_NO_FOREIGN_ADOPT) continue;\n if (!hostOwner && __EXTENSIONJS_PRE_MOUNT_ROOTS.indexOf(host) !== -1) continue;\n ownedRootCount++;\n host.setAttribute("data-extjs-reinject-owner", __extjsToken);\n host.setAttribute("data-extjs-reinject-key", String(__EXTENSIONJS_BUNDLE_KEY || key || ""));\n host.setAttribute("data-extjs-reinject-generation", String(generation));\n host.setAttribute("data-extjs-reinject-status", String(status || "mounted"));\n host.setAttribute("data-extjs-reinject-build", String(__EXTENSIONJS_REINJECT_BUILD_TOKEN || ""));\n try {\n if (!host.__extjsDebugRemovePatched) {\n host.__extjsDebugRemovePatched = true;\n var __extjsOriginalRemove = typeof host.remove === "function" ? host.remove.bind(host) : null;\n if (__extjsOriginalRemove) {\n host.remove = function(){\n try {\n var pageRoot = document.documentElement;\n if (pageRoot && typeof pageRoot.setAttribute === "function") {\n pageRoot.setAttribute("data-extjs-debug-stage", "root-remove-called");\n pageRoot.setAttribute("data-extjs-debug-last-removal", "remove()");\n pageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removal-source", "patched-host-remove");\n }\n } catch (error) {}\n return __extjsOriginalRemove();\n };\n }\n }\n } catch (error) {}\n }\n try {\n marker.setAttribute("data-extjs-debug-stage", String(status || ""));\n marker.setAttribute("data-extjs-debug-root-count", String(roots.length));\n marker.setAttribute("data-extjs-debug-owned-root-count", String(ownedRootCount));\n marker.setAttribute("data-extjs-debug-marker-count", String(markers.length));\n } catch (error) {}\n } catch (error) {}\n try {\n var pageRoot = document.documentElement;\n if (pageRoot && typeof pageRoot.setAttribute === "function") {\n pageRoot.setAttribute("data-extjs-last-reinject-key", String(__EXTENSIONJS_BUNDLE_KEY || key || ""));\n pageRoot.setAttribute("data-extjs-last-reinject-generation", String(generation));\n pageRoot.setAttribute("data-extjs-last-reinject-status", String(status || "mounted"));\n pageRoot.setAttribute("data-extjs-last-reinject-build", String(__EXTENSIONJS_REINJECT_BUILD_TOKEN || ""));\n pageRoot.setAttribute("data-extjs-debug-stage", marker.getAttribute("data-extjs-debug-stage") || String(status || ""));\n pageRoot.setAttribute("data-extjs-debug-root-count", marker.getAttribute("data-extjs-debug-root-count") || "0");\n pageRoot.setAttribute("data-extjs-debug-owned-root-count", marker.getAttribute("data-extjs-debug-owned-root-count") || "0");\n pageRoot.setAttribute("data-extjs-debug-marker-count", marker.getAttribute("data-extjs-debug-marker-count") || "0");\n }\n } catch (error) {}\n } catch (error) {}\n}\nfunction __EXTENSIONJS_cleanupKnownRoots(staleEvenIfSameBuild){\n try {\n if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var roots = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n for (var i = 0; i < roots.length; i++) {\n var host = roots[i];\n if (!host || typeof host.getAttribute !== "function") continue;\n var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (!hostOwner || hostOwner !== __extjsToken) continue;\n // Build-aware: only remove hosts owned by us whose build token does NOT\n // match the current bundle. Fresh roots from the current mount carry\n // the active build token and must be preserved; orphans from a prior\n // build (e.g. the old isolated world after `chrome.runtime.reload`)\n // carry stale tokens and should be cleared so we never end up with two\n // hosts owned by the same key.\n // EXCEPT when this bundle starts in a FRESH world (no registry entry,\n // because the old isolated world was destroyed by `chrome.runtime.reload`):\n // a same-build root then predates this execution and is a stale zombie\n // (its scripts died with the world). Unedited sibling scripts in a\n // multi-script entry keep their build token across recompiles, so the\n // token equality alone must not protect them here.\n var hostBuild = String(host.getAttribute("data-extjs-reinject-build") || "");\n var currentBuild = String(__EXTENSIONJS_REINJECT_BUILD_TOKEN || "");\n if (!staleEvenIfSameBuild && hostBuild && currentBuild && hostBuild === currentBuild) continue;\n try {\n var pageRoot = document.documentElement;\n if (pageRoot && typeof pageRoot.setAttribute === "function") {\n pageRoot.setAttribute("data-extjs-debug-stage", "cleanup-known-roots");\n pageRoot.setAttribute("data-extjs-debug-last-removal", "cleanup-known-roots");\n pageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-last-removal-source", "cleanup-known-roots");\n pageRoot.setAttribute("data-extjs-debug-last-removed-node-tag", String(host.tagName || "").toLowerCase());\n }\n } catch (error) {}\n try { host.remove(); } catch (error) {}\n }\n } catch (error) {}\n}\nfunction __EXTENSIONJS_cleanupOrphanRoots(){\n try {\n // At bundle execution start, before this run has mounted anything, any\n // `data-extension-root` host without `data-extjs-reinject-owner` is an\n // orphan from a prior session that died before `setReinjectMarker`\n // could tag it (typically: the previous isolated world was destroyed\n // by a `chrome.runtime.reload` mid-mount, or its `whenReady`-deferred\n // `apply` never fired). We have not created our own root yet, so any\n // untagged host we touch here is by definition not from THIS run, but\n // it may belong to a DIFFERENT extension mid-mount in the same DOM.\n // Companion extensions never sweep, and everyone else sweeps only when\n // a reinject marker proves a prior generation of THIS script ran here.\n if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;\n if (__EXTENSIONJS_NO_FOREIGN_ADOPT) return;\n var __extjsToken = __EXTENSIONJS_ownerToken();\n var sawPriorGeneration = false;\n try {\n var markers = Array.from(document.querySelectorAll("[data-extjs-reinject-marker=\\"true\\"]"));\n for (var m = 0; m < markers.length; m++) {\n if (markers[m] && typeof markers[m].getAttribute === "function" && String(markers[m].getAttribute("data-extjs-marker-owner") || "") === __extjsToken) { sawPriorGeneration = true; break; }\n }\n } catch (error) {}\n if (!sawPriorGeneration) return;\n var roots = Array.from(document.querySelectorAll("[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])"));\n for (var i = 0; i < roots.length; i++) {\n var host = roots[i];\n if (!host || typeof host.getAttribute !== "function") continue;\n var hostOwner = String(host.getAttribute("data-extjs-reinject-owner") || "");\n if (hostOwner) continue;\n try { host.remove(); } catch (error) {}\n }\n } catch (error) {}\n}\n';
216
- const bootstrap = `var __EXTENSIONJS_BUNDLE_KEY=${JSON.stringify(bundleKey)};\nvar __EXTENSIONJS_REINJECT_KEY=${JSON.stringify(reinjectKey)};\n` + (takesBridgeBase ? `var __EXTENSIONJS_BRIDGE_BASE = ${EXTENSION_BASE_FROM_STACK};\ntry {\n var __EXTENSIONJS_html = document.documentElement;\n if (!__EXTENSIONJS_BRIDGE_BASE) __EXTENSIONJS_BRIDGE_BASE = String(__EXTENSIONJS_html.getAttribute("data-extjs-extension-base") || "");\n if (__EXTENSIONJS_html.hasAttribute("data-extjs-extension-base")) __EXTENSIONJS_html.removeAttribute("data-extjs-extension-base");\n if (__EXTENSIONJS_BRIDGE_BASE && typeof __webpack_require__ === "function") __webpack_require__.extjsBase = __EXTENSIONJS_BRIDGE_BASE;\n} catch (error) {}\n` : '') + devOnly(`var __EXTENSIONJS_REINJECT_BUILD_TOKEN=${JSON.stringify(buildToken)};\n`) + `var __EXTENSIONJS_NO_FOREIGN_ADOPT=${JSON.stringify(isBuiltInCompanion)};\n` + 'function __EXTENSIONJS_ownerToken(){\n var extId = "";\n try {\n var rt = (typeof globalThis === "object" && globalThis && ((globalThis.browser && globalThis.browser.runtime) || (globalThis.chrome && globalThis.chrome.runtime))) || null;\n if (rt && rt.id) extId = String(rt.id);\n } catch (error) {}\n return String(__EXTENSIONJS_REINJECT_KEY || "") + (extId ? "@" + extId : "");\n}\n' + devOnly(`var __EXTENSIONJS_DEV_MARKERS_ENABLED=${JSON.stringify(!isShippedBundle)};\nvar __EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED=${JSON.stringify(hostInstrumentationEnabled)};\n`) + (!isShippedBundle || bundleCssHydrationEnabled ? 'var __EXTENSIONJS_PRE_MOUNT_ROOTS = [];\nfunction __EXTENSIONJS_snapshotPreMountRoots(){\n try {\n if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;\n __EXTENSIONJS_PRE_MOUNT_ROOTS = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]"));\n } catch (error) { __EXTENSIONJS_PRE_MOUNT_ROOTS = []; }\n}\n__EXTENSIONJS_snapshotPreMountRoots();\n' : 'function __EXTENSIONJS_snapshotPreMountRoots(){}\n') + `${cssAssetUrlsInline}` + devOnly('var __EXTENSIONJS_REINJECT_REGISTRY=(typeof globalThis==="object" && globalThis ? (globalThis.__EXTENSIONJS_DEV_REINJECT__ || (globalThis.__EXTENSIONJS_DEV_REINJECT__={})) : {});\n') + 'var __EXTENSIONJS_REGISTERED_CLEANUPS=[];\n' + devOnly('function __EXTENSIONJS_readReinjectGeneration(entry){\n try {\n if (!entry) return 0;\n if (typeof entry === "function" && typeof entry.__extjsGeneration === "number") return entry.__extjsGeneration;\n if (typeof entry === "object") {\n if (typeof entry.__extjsGeneration === "number") return entry.__extjsGeneration;\n if (typeof entry.generation === "number") return entry.generation;\n if (typeof entry.cleanup === "function" && typeof entry.cleanup.__extjsGeneration === "number") return entry.cleanup.__extjsGeneration;\n }\n } catch (error) {}\n return 0;\n}\n') + 'function __EXTENSIONJS_runCleanups(list){\n try {\n if (!Array.isArray(list)) return;\n for (var i = list.length - 1; i >= 0; i--) {\n try { if (typeof list[i] === "function") list[i](); } catch (error) {}\n }\n } catch (error) {}\n}\nfunction __EXTENSIONJS_registerCleanup(fn){\n if (typeof fn === "function") __EXTENSIONJS_REGISTERED_CLEANUPS.push(fn);\n return fn;\n}\n' + devOnly(reinjectMarkerInline) + 'function __EXTENSIONJS_composeCleanup(primaryCleanup){\n return function(){\n try { if (typeof primaryCleanup === "function") primaryCleanup(); } catch (error) {}\n try { __EXTENSIONJS_runCleanups(__EXTENSIONJS_REGISTERED_CLEANUPS); } catch (error) {}\n' + devOnly(' try { __EXTENSIONJS_cleanupKnownRoots(); } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "cleaned"); } catch (error) {}\n') + " };\n}\n" + devOnly('function __EXTENSIONJS_recordExecutionSnapshot(stage){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_ENABLED) return;\n if (typeof document === "undefined") return;\n var pageRoot = document.documentElement;\n if (!pageRoot || typeof pageRoot.getAttribute !== "function" || typeof pageRoot.setAttribute !== "function") return;\n var currentCount = Number(pageRoot.getAttribute("data-extjs-debug-execution-count") || "0");\n var nextCount = Number.isFinite(currentCount) ? currentCount + 1 : 1;\n var roots = [];\n try { roots = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])")); } catch (error) {}\n pageRoot.setAttribute("data-extjs-debug-execution-count", String(nextCount));\n pageRoot.setAttribute("data-extjs-debug-last-execution-stage", String(stage || ""));\n pageRoot.setAttribute("data-extjs-debug-last-execution-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-existing-root-count-before-cleanup", String(roots.length));\n } catch (error) {}\n}\n') + (isShippedBundle && isMainWorld ? '' : 'try {\n if (typeof globalThis === "object" && globalThis) {\n globalThis.__EXTENSIONJS_registerCleanup = __EXTENSIONJS_registerCleanup;\n }\n} catch (error) {}\n') + hostInstrumentationInline + devOnly('if (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try { __EXTENSIONJS_recordExecutionSnapshot("bootstrap"); } catch (error) {}\n}\nvar __EXTENSIONJS_previousEntry=__EXTENSIONJS_REINJECT_REGISTRY[__EXTENSIONJS_REINJECT_KEY];\nvar __EXTENSIONJS_REINJECT_GENERATION=__EXTENSIONJS_readReinjectGeneration(__EXTENSIONJS_previousEntry);\n// Sweep untagged orphans (prior-session roots that died before tagging)\n// before any further cleanup runs. Safe here because our mount has not\n// produced any roots yet, any untagged host is by definition not ours.\ntry { __EXTENSIONJS_cleanupOrphanRoots(); } catch (error) {}\ntry {\n var __EXTENSIONJS_previousCleanup=typeof __EXTENSIONJS_previousEntry === "function" ? __EXTENSIONJS_previousEntry : (__EXTENSIONJS_previousEntry && typeof __EXTENSIONJS_previousEntry.cleanup === "function" ? __EXTENSIONJS_previousEntry.cleanup : null);\n if (typeof __EXTENSIONJS_previousCleanup === "function") {\n if (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try {\n var __extjsPageRoot = document.documentElement;\n if (__extjsPageRoot && typeof __extjsPageRoot.setAttribute === "function") {\n __extjsPageRoot.setAttribute("data-extjs-debug-stage", "previous-cleanup");\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal", "previous-cleanup");\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal-source", "previous-cleanup");\n }\n } catch (error) {}\n }\n __EXTENSIONJS_previousCleanup();\n }\n} catch (error) {}\ntry { __EXTENSIONJS_cleanupKnownRoots(!__EXTENSIONJS_previousEntry); } catch (error) {}\n') + (!isShippedBundle || hasModuleGraph ? 'function __EXTENSIONJS_syncAssetBase(){\n try {\n var base = "";\n try {\n if (typeof globalThis === "object" && globalThis && globalThis.browser && globalThis.browser.runtime && typeof globalThis.browser.runtime.getURL === "function") base = String(globalThis.browser.runtime.getURL("/"));\n else if (typeof globalThis === "object" && globalThis && globalThis.chrome && globalThis.chrome.runtime && typeof globalThis.chrome.runtime.getURL === "function") base = String(globalThis.chrome.runtime.getURL("/"));\n } catch (error) {}\n' + (takesBridgeBase ? ' if (!base) base = __EXTENSIONJS_BRIDGE_BASE;\n' : '') + ' if (!base) {\n try {\n if (typeof document === "object" && document && document.documentElement) base = String(document.documentElement.getAttribute("data-extjs-extension-base") || "");\n } catch (error) {}\n }\n if (!base) return false;\n if (base.charAt(base.length - 1) !== "/") base += "/";\n if (typeof __webpack_require__ === "function" || typeof __webpack_require__ === "object") {\n try { __webpack_require__.p = base; } catch (error) {}\n try { __webpack_require__.b = base; } catch (error) {}\n }\n return true;\n } catch (error) {}\n return false;\n}\ntry {\n if (!__EXTENSIONJS_syncAssetBase()) {\n var __EXTENSIONJS_assetBaseRetries = 0;\n var __EXTENSIONJS_retryAssetBase = function(){\n try {\n if (__EXTENSIONJS_syncAssetBase()) return;\n } catch (error) {}\n if (__EXTENSIONJS_assetBaseRetries++ < 50) setTimeout(__EXTENSIONJS_retryAssetBase, 100);\n };\n __EXTENSIONJS_retryAssetBase();\n }\n} catch (error) {}\n' : '');
250
+ const bootstrap = `var __EXTENSIONJS_BUNDLE_KEY=${JSON.stringify(bundleKey)};\nvar __EXTENSIONJS_REINJECT_KEY=${JSON.stringify(reinjectKey)};\n` + (holdsBridgeBase ? `var __EXTENSIONJS_BRIDGE_BASE = ${extensionBaseFromFile(takesFromFile)};\ntry {\n var __EXTENSIONJS_html = document.documentElement;\n if (!__EXTENSIONJS_BRIDGE_BASE) __EXTENSIONJS_BRIDGE_BASE = String(__EXTENSIONJS_html.getAttribute(${baseAttribute}) || "");\n ${unlessExtensionAddress('__EXTENSIONJS_BRIDGE_BASE', baseScheme)}\n` + (takesBridgeBase ? sharesBridgeBase ? ` var __EXTENSIONJS_clearBase = function(){ ${dropsBaseGetter}try { if (__EXTENSIONJS_html.hasAttribute(${baseAttribute})) __EXTENSIONJS_html.removeAttribute(${baseAttribute}); } catch (error) {} };\n try { Promise.resolve().then(__EXTENSIONJS_clearBase); } catch (error) { __EXTENSIONJS_clearBase(); }\n` : ` ${dropsBaseGetter}if (__EXTENSIONJS_html.hasAttribute(${baseAttribute})) __EXTENSIONJS_html.removeAttribute(${baseAttribute});\n` : '') + ' if (__EXTENSIONJS_BRIDGE_BASE && typeof __webpack_require__ === "function") __webpack_require__.extjsBase = __EXTENSIONJS_BRIDGE_BASE;\n} catch (error) {}\n' : '') + devOnly(`var __EXTENSIONJS_REINJECT_BUILD_TOKEN=${JSON.stringify(buildToken)};\n`) + `var __EXTENSIONJS_NO_FOREIGN_ADOPT=${JSON.stringify(isBuiltInCompanion)};\n` + 'function __EXTENSIONJS_ownerToken(){\n var extId = "";\n try {\n var rt = (typeof globalThis === "object" && globalThis && ((globalThis.browser && globalThis.browser.runtime) || (globalThis.chrome && globalThis.chrome.runtime))) || null;\n if (rt && rt.id) extId = String(rt.id);\n } catch (error) {}\n return String(__EXTENSIONJS_REINJECT_KEY || "") + (extId ? "@" + extId : "");\n}\n' + devOnly(`var __EXTENSIONJS_DEV_MARKERS_ENABLED=${JSON.stringify(!isShippedBundle)};\nvar __EXTENSIONJS_HOST_INSTRUMENTATION_ENABLED=${JSON.stringify(hostInstrumentationEnabled)};\n`) + (!isShippedBundle || bundleCssHydrationEnabled ? 'var __EXTENSIONJS_PRE_MOUNT_ROOTS = [];\nfunction __EXTENSIONJS_snapshotPreMountRoots(){\n try {\n if (typeof document === "undefined" || typeof document.querySelectorAll !== "function") return;\n __EXTENSIONJS_PRE_MOUNT_ROOTS = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]"));\n } catch (error) { __EXTENSIONJS_PRE_MOUNT_ROOTS = []; }\n}\n__EXTENSIONJS_snapshotPreMountRoots();\n' : 'function __EXTENSIONJS_snapshotPreMountRoots(){}\n') + `${cssAssetUrlsInline}` + devOnly('var __EXTENSIONJS_REINJECT_REGISTRY=(typeof globalThis==="object" && globalThis ? (globalThis.__EXTENSIONJS_DEV_REINJECT__ || (globalThis.__EXTENSIONJS_DEV_REINJECT__={})) : {});\n') + 'var __EXTENSIONJS_REGISTERED_CLEANUPS=[];\n' + devOnly('function __EXTENSIONJS_readReinjectGeneration(entry){\n try {\n if (!entry) return 0;\n if (typeof entry === "function" && typeof entry.__extjsGeneration === "number") return entry.__extjsGeneration;\n if (typeof entry === "object") {\n if (typeof entry.__extjsGeneration === "number") return entry.__extjsGeneration;\n if (typeof entry.generation === "number") return entry.generation;\n if (typeof entry.cleanup === "function" && typeof entry.cleanup.__extjsGeneration === "number") return entry.cleanup.__extjsGeneration;\n }\n } catch (error) {}\n return 0;\n}\n') + 'function __EXTENSIONJS_runCleanups(list){\n try {\n if (!Array.isArray(list)) return;\n for (var i = list.length - 1; i >= 0; i--) {\n try { if (typeof list[i] === "function") list[i](); } catch (error) {}\n }\n } catch (error) {}\n}\nfunction __EXTENSIONJS_registerCleanup(fn){\n if (typeof fn === "function") __EXTENSIONJS_REGISTERED_CLEANUPS.push(fn);\n return fn;\n}\n' + devOnly(reinjectMarkerInline) + 'function __EXTENSIONJS_composeCleanup(primaryCleanup){\n return function(){\n try { if (typeof primaryCleanup === "function") primaryCleanup(); } catch (error) {}\n try { __EXTENSIONJS_runCleanups(__EXTENSIONJS_REGISTERED_CLEANUPS); } catch (error) {}\n' + devOnly(' try { __EXTENSIONJS_cleanupKnownRoots(); } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "cleaned"); } catch (error) {}\n') + " };\n}\n" + devOnly('function __EXTENSIONJS_recordExecutionSnapshot(stage){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_ENABLED) return;\n if (typeof document === "undefined") return;\n var pageRoot = document.documentElement;\n if (!pageRoot || typeof pageRoot.getAttribute !== "function" || typeof pageRoot.setAttribute !== "function") return;\n var currentCount = Number(pageRoot.getAttribute("data-extjs-debug-execution-count") || "0");\n var nextCount = Number.isFinite(currentCount) ? currentCount + 1 : 1;\n var roots = [];\n try { roots = Array.from(document.querySelectorAll("#extension-root,[data-extension-root]:not([data-extension-root=\\"extension-js-devtools\\"])")); } catch (error) {}\n pageRoot.setAttribute("data-extjs-debug-execution-count", String(nextCount));\n pageRoot.setAttribute("data-extjs-debug-last-execution-stage", String(stage || ""));\n pageRoot.setAttribute("data-extjs-debug-last-execution-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n pageRoot.setAttribute("data-extjs-debug-existing-root-count-before-cleanup", String(roots.length));\n } catch (error) {}\n}\n') + (isShippedBundle && isMainWorld ? '' : 'try {\n if (typeof globalThis === "object" && globalThis) {\n globalThis.__EXTENSIONJS_registerCleanup = __EXTENSIONJS_registerCleanup;\n }\n} catch (error) {}\n') + hostInstrumentationInline + devOnly('if (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try { __EXTENSIONJS_recordExecutionSnapshot("bootstrap"); } catch (error) {}\n}\nvar __EXTENSIONJS_previousEntry=__EXTENSIONJS_REINJECT_REGISTRY[__EXTENSIONJS_REINJECT_KEY];\nvar __EXTENSIONJS_REINJECT_GENERATION=__EXTENSIONJS_readReinjectGeneration(__EXTENSIONJS_previousEntry);\n// Sweep untagged orphans (prior-session roots that died before tagging)\n// before any further cleanup runs. Safe here because our mount has not\n// produced any roots yet, any untagged host is by definition not ours.\ntry { __EXTENSIONJS_cleanupOrphanRoots(); } catch (error) {}\ntry {\n var __EXTENSIONJS_previousCleanup=typeof __EXTENSIONJS_previousEntry === "function" ? __EXTENSIONJS_previousEntry : (__EXTENSIONJS_previousEntry && typeof __EXTENSIONJS_previousEntry.cleanup === "function" ? __EXTENSIONJS_previousEntry.cleanup : null);\n if (typeof __EXTENSIONJS_previousCleanup === "function") {\n if (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try {\n var __extjsPageRoot = document.documentElement;\n if (__extjsPageRoot && typeof __extjsPageRoot.setAttribute === "function") {\n __extjsPageRoot.setAttribute("data-extjs-debug-stage", "previous-cleanup");\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal", "previous-cleanup");\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal-key", String(__EXTENSIONJS_REINJECT_KEY || ""));\n __extjsPageRoot.setAttribute("data-extjs-debug-last-removal-source", "previous-cleanup");\n }\n } catch (error) {}\n }\n __EXTENSIONJS_previousCleanup();\n }\n} catch (error) {}\ntry { __EXTENSIONJS_cleanupKnownRoots(!__EXTENSIONJS_previousEntry); } catch (error) {}\n') + (!isShippedBundle || hasModuleGraph ? 'function __EXTENSIONJS_syncAssetBase(){\n try {\n var base = "";\n' + asksRuntime(' try {\n if (typeof globalThis === "object" && globalThis && globalThis.browser && globalThis.browser.runtime && typeof globalThis.browser.runtime.getURL === "function") base = String(globalThis.browser.runtime.getURL("/"));\n else if (typeof globalThis === "object" && globalThis && globalThis.chrome && globalThis.chrome.runtime && typeof globalThis.chrome.runtime.getURL === "function") base = String(globalThis.chrome.runtime.getURL("/"));\n } catch (error) {}\n') + (holdsBridgeBase ? ' if (!base) base = __EXTENSIONJS_BRIDGE_BASE;\n' : '') + " if (!base) {\n try {\n" + ` if (typeof document === "object" && document && document.documentElement) base = String(document.documentElement.getAttribute(${baseAttribute}) || "");\n` + " } catch (error) {}\n }\n" + ` ${unlessExtensionAddress('base', baseScheme)}\n` + ' if (!base) return false;\n' + (takesFromFile ? ' if (base[base.length - 1] !== "/") base += "/";\n' : ' if (base.charAt(base.length - 1) !== "/") base += "/";\n') + ' if (typeof __webpack_require__ === "function" || typeof __webpack_require__ === "object") {\n try { __webpack_require__.p = base; } catch (error) {}\n try { __webpack_require__.b = base; } catch (error) {}\n }\n return true;\n } catch (error) {}\n return false;\n}\ntry {\n if (!__EXTENSIONJS_syncAssetBase()) {\n var __EXTENSIONJS_assetBaseRetries = 0;\n var __EXTENSIONJS_retryAssetBase = function(){\n try {\n if (__EXTENSIONJS_syncAssetBase()) return;\n } catch (error) {}\n if (__EXTENSIONJS_assetBaseRetries++ < 50) setTimeout(__EXTENSIONJS_retryAssetBase, 100);\n };\n __EXTENSIONJS_retryAssetBase();\n }\n} catch (error) {}\n' : '');
217
251
  const runtimeInline = `function __EXTENSIONJS_whenReady(runAt, cb){\n try {\n if (typeof document === 'undefined') { cb(); return function(){} }\n if (runAt === 'document_start') { cb(); return function(){} }\n var isDone = false;\n function isReady(){\n if (runAt === 'document_end') return document.readyState === 'interactive' || document.readyState === 'complete';\n if (runAt === 'document_idle') return document.readyState === 'complete';\n return document.readyState === 'complete';\n }\n if (isReady()) { cb(); return function(){} }\n var onReady = function(){\n try {\n if (isDone) return;\n if (isReady()) { isDone = true; document.removeEventListener('readystatechange', onReady); cb(); }\n } catch (error) {}\n };\n document.addEventListener('readystatechange', onReady);\n return function(){ try { if (!isDone) document.removeEventListener('readystatechange', onReady); } catch (error) {} };\n } catch (error) { try { cb(); } catch (ignored) {} return function(){} }\n}\n${bundleCssHydrationInline}function __EXTENSIONJS_mount(mount, runAt){\n var cleanup = function(){};\n var cancelReady = function(){};\n if (typeof mount !== "function") {\n` + devOnly(' try { __EXTENSIONJS_REINJECT_GENERATION = (Number(__EXTENSIONJS_REINJECT_GENERATION) || 0) + 1; } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "executed"); } catch (error) {}\n') + " try { __EXTENSIONJS_scheduleBundleCssHydration(); } catch (error) {}\n return __EXTENSIONJS_composeCleanup(null);\n }\n function apply(){\n try {\n __EXTENSIONJS_snapshotPreMountRoots();\n var nextCleanup = mount();\n cleanup = __EXTENSIONJS_composeCleanup(nextCleanup);\n" + devOnly(' __EXTENSIONJS_REINJECT_GENERATION = (Number(__EXTENSIONJS_REINJECT_GENERATION) || 0) + 1;\n try { unmount.__extjsGeneration = __EXTENSIONJS_REINJECT_GENERATION; unmount.__extjsKey = __EXTENSIONJS_REINJECT_KEY; } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, __EXTENSIONJS_REINJECT_GENERATION, "mounted"); } catch (error) {}\n') + ' try { __EXTENSIONJS_scheduleBundleCssHydration(); } catch (error) {}\n } catch (error) {\n try { console.warn("Extension.js: the content script default export failed to run.", error); } catch (ignored) {}\n' + devOnly(' try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "mount-error"); } catch (ignored) {}\n') + " }\n }\n function unmount(){ try { cancelReady && cancelReady(); } catch (error) {} try { if (typeof cleanup === 'function') cleanup(); } catch (error) {} }\n cancelReady = __EXTENSIONJS_whenReady(runAt, apply);\n return unmount;\n}\n";
218
252
  if (!hasDefaultExport(rewrittenSource, this.resourcePath, compilation)) {
219
253
  if (!isShippedBundle && declaredEntry && !hintedEntriesWithoutDefaultExport.has(resourceAbsPath)) {
220
254
  hintedEntriesWithoutDefaultExport.add(resourceAbsPath);
221
- humanLine(contentScriptWithoutDefaultExport(node_path.relative(packageJsonDir, resourceAbsPath).split(node_path.sep).join('/') || resourceAbsPath));
255
+ humanLine(contentScriptWithoutDefaultExport(node_path.relative(packageJsonDir, resourceAbsPath).split(node_path.sep).join('/') || resourceAbsPath, isChromiumBasedBrowser(browser)));
222
256
  }
223
257
  const prefix = `var __EXTJS_WRAPPER_KIND="FS3_INLINE";\n${bootstrap}${runtimeInline}`;
224
258
  const suffix = devOnly(`try { __EXTENSIONJS_REINJECT_GENERATION = (Number(__EXTENSIONJS_REINJECT_GENERATION) || 0) + 1; } catch (error) {
@@ -230,7 +264,11 @@ function contentScriptWrapper(source, inputSourceMap) {
230
264
  }\n` + devOnly(`try { __EXTENSIONJS_REINJECT_REGISTRY[__EXTENSIONJS_REINJECT_KEY] = { cleanup: __EXTENSIONJS_composeCleanup(null), generation: Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, build: __EXTENSIONJS_REINJECT_BUILD_TOKEN }; } catch (error) {
231
265
  // Ignore
232
266
  }\n`);
233
- const wrapped = `${prefix}${rewrittenSource}\n${suffix}`;
267
+ const endsOnItsValue = Boolean(isScriptsFolderScript) && !declaredEntry && (true !== options.mainWorldBundle || isRuntimeMainWorld);
268
+ const body = endsOnItsValue ? keepCompletionValue(rewrittenSource, this.resourcePath, {
269
+ importsAnotherScript: importsScriptsFile(rewrittenSource, resourceAbsPath, String(scriptsDir))
270
+ }) : rewrittenSource;
271
+ const wrapped = `${prefix}${body}\n${suffix}`;
234
272
  return returnWithMap(this, wrapped, adjustLoaderSourceMap(inputOrIdentityMap(inputSourceMap, this.resourcePath, rewrittenSource), {
235
273
  prefix,
236
274
  before: rewrittenSource,
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
2
- import { inputOrIdentityMap } from "./895~0.mjs";
2
+ import { inputOrIdentityMap } from "./3~0.mjs";
3
3
  const GETURL_ARG = /\bruntime\s*\.\s*getURL\s*\(/;
4
4
  const BARE_IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
5
5
  const MEMBER_PATH = /^[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)+$/;
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
2
- import { publicFolderSetting } from "./471~0.mjs";
2
+ import { publicFolderSetting } from "./g~0.mjs";
3
3
  import * as __rspack_external_node_fs_1b05aee1 from "node:fs";
4
4
  import * as __rspack_external_node_path_806ed179 from "node:path";
5
5
  function isUsableDir(candidate) {
@@ -89,10 +89,18 @@ function cssSelectorTokens(text) {
89
89
  }
90
90
  return tokens;
91
91
  }
92
+ function withoutEmptyCssRules(text) {
93
+ let current = text.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/url\([^)]*\)/g, ' ').replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, ' ');
94
+ for(;;){
95
+ const next = current.replace(/[^{};]*\{[\s;]*\}/g, ' ');
96
+ if (next === current) return current;
97
+ current = next;
98
+ }
99
+ }
92
100
  function minifierDroppedTokens(before, after) {
93
101
  const kept = cssSelectorTokens(after);
94
102
  return [
95
- ...cssSelectorTokens(before)
103
+ ...cssSelectorTokens(withoutEmptyCssRules(before))
96
104
  ].filter((token)=>!kept.has(token));
97
105
  }
98
106
  export { minifierDroppedTokens, registerVerbatimCss, restoreVerbatimCssAssets, verbatimCssModulePlaceholder, verbatimCssPlaceholder };
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
2
- import { stripBom } from "./374~0.mjs";
2
+ import { stripBom } from "./5~0.mjs";
3
3
  import * as __rspack_external_node_fs_1b05aee1 from "node:fs";
4
4
  import * as __rspack_external_node_path_806ed179 from "node:path";
5
5
  const PROJECT_MANIFEST_FILENAMES = [
@@ -201,4 +201,4 @@ function validateDenoConfig(denoConfigPath) {
201
201
  return false;
202
202
  }
203
203
  }
204
- export { PROJECT_MANIFEST_FILENAMES, findNearestDenoConfigSync, findNearestProjectManifestDirSync, findNearestProjectManifestSync, hasProjectDependency, readProjectDependencies, validateDenoConfig };
204
+ export { PROJECT_MANIFEST_FILENAMES, findNearestDenoConfigSync, findNearestProjectManifestDirSync, findNearestProjectManifestSync, hasProjectDependency, parseJsoncSafe, readProjectDependencies, validateDenoConfig };
@@ -12,10 +12,26 @@ function canonicalizeDir(dir) {
12
12
  }
13
13
  }
14
14
  }
15
+ const resolvedModuleFolders = new Map();
16
+ function forgetResolvedModuleFolders() {
17
+ resolvedModuleFolders.clear();
18
+ }
19
+ function canonicalizeModuleFolder(dir) {
20
+ const known = resolvedModuleFolders.get(dir);
21
+ if (void 0 !== known) return known;
22
+ let resolved;
23
+ try {
24
+ resolved = __rspack_external_node_fs_1b05aee1.realpathSync.native(dir);
25
+ } catch {
26
+ return canonicalizeDir(dir);
27
+ }
28
+ resolvedModuleFolders.set(dir, resolved);
29
+ return resolved;
30
+ }
15
31
  function canonicalizeResourcePath(resourcePath) {
16
32
  if ('string' != typeof resourcePath || 0 === resourcePath.length) return resourcePath;
17
33
  try {
18
- return __rspack_external_node_path_806ed179.normalize(__rspack_external_node_path_806ed179.join(canonicalizeDir(__rspack_external_node_path_806ed179.dirname(resourcePath)), __rspack_external_node_path_806ed179.basename(resourcePath)));
34
+ return __rspack_external_node_path_806ed179.normalize(__rspack_external_node_path_806ed179.join(canonicalizeModuleFolder(__rspack_external_node_path_806ed179.dirname(resourcePath)), __rspack_external_node_path_806ed179.basename(resourcePath)));
19
35
  } catch {
20
36
  return __rspack_external_node_path_806ed179.normalize(resourcePath);
21
37
  }
@@ -35,4 +51,4 @@ function isResourceUnderDirs(resource, dirs) {
35
51
  return rel.length > 0 && !rel.startsWith('..') && !__rspack_external_node_path_806ed179.isAbsolute(rel);
36
52
  });
37
53
  }
38
- export { canonicalizeDir, canonicalizeResourcePath, isResourceUnderDirs, toResourceKey };
54
+ export { canonicalizeDir, canonicalizeResourcePath, forgetResolvedModuleFolders, isResourceUnderDirs, toResourceKey };