extension-develop 4.1.8 → 4.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/0~rspack-config.mjs +109 -39
- package/dist/101.mjs +1 -1
- package/dist/291.mjs +8 -1
- package/dist/839.mjs +3 -2
- package/dist/extension-js-devtools/chrome/background/service_worker.js +1 -1
- package/dist/extension-js-devtools/chrome/content_scripts/content-0.js +2 -2
- package/dist/extension-js-devtools/chrome/manifest.json +4 -0
- package/dist/extension-js-devtools/chrome/options/index.css +2 -0
- package/dist/extension-js-devtools/chrome/options/index.html +11 -0
- package/dist/extension-js-devtools/chrome/options/index.js +1 -0
- package/dist/extension-js-devtools/chrome/pages/centralized-logger.css +1 -1
- package/dist/extension-js-devtools/chrome/pages/welcome.css +1 -1
- package/dist/extension-js-devtools/chrome/scripts/logger-client.js +1 -1
- package/dist/extension-js-devtools/chromium/background/service_worker.js +1 -1
- package/dist/extension-js-devtools/chromium/content_scripts/content-0.js +2 -2
- package/dist/extension-js-devtools/chromium/manifest.json +4 -0
- package/dist/extension-js-devtools/chromium/options/index.css +2 -0
- package/dist/extension-js-devtools/chromium/options/index.html +11 -0
- package/dist/extension-js-devtools/chromium/options/index.js +1 -0
- package/dist/extension-js-devtools/chromium/pages/centralized-logger.css +1 -1
- package/dist/extension-js-devtools/chromium/pages/welcome.css +1 -1
- package/dist/extension-js-devtools/chromium/scripts/logger-client.js +1 -1
- package/dist/extension-js-devtools/edge/background/service_worker.js +1 -1
- package/dist/extension-js-devtools/edge/content_scripts/content-0.js +2 -2
- package/dist/extension-js-devtools/edge/manifest.json +4 -0
- package/dist/extension-js-devtools/edge/options/index.css +2 -0
- package/dist/extension-js-devtools/edge/options/index.html +11 -0
- package/dist/extension-js-devtools/edge/options/index.js +1 -0
- package/dist/extension-js-devtools/edge/pages/centralized-logger.css +1 -1
- package/dist/extension-js-devtools/edge/pages/welcome.css +1 -1
- package/dist/extension-js-devtools/edge/scripts/logger-client.js +1 -1
- package/dist/extension-js-devtools/firefox/background/scripts.js +1 -1
- package/dist/extension-js-devtools/firefox/content_scripts/content-0.js +2 -2
- package/dist/extension-js-devtools/firefox/manifest.json +4 -0
- package/dist/extension-js-devtools/firefox/options/index.css +2 -0
- package/dist/extension-js-devtools/firefox/options/index.html +11 -0
- package/dist/extension-js-devtools/firefox/options/index.js +1 -0
- package/dist/extension-js-devtools/firefox/pages/centralized-logger.css +1 -1
- package/dist/extension-js-devtools/firefox/pages/welcome.css +1 -1
- package/dist/extension-js-devtools/firefox/scripts/logger-client.js +1 -1
- package/dist/feature-scripts-content-script-wrapper.js +3 -2
- package/dist/feature-scripts-content-script-wrapper.mjs +3 -2
- package/dist/minimum-script-file.js +4 -4
- package/dist/minimum-script-file.mjs +4 -4
- package/dist/plugin-reload/steps/setup-reload-strategy/index.d.ts +6 -8
- package/dist/plugin-web-extension/feature-scripts/contracts.d.ts +3 -0
- package/dist/plugin-web-extension/feature-scripts/scripts-lib/utils.d.ts +9 -0
- package/dist/plugin-web-extension/feature-scripts/steps/add-content-script-wrapper/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import { reservedScriptsFolder } from "./266.mjs";
|
|
|
7
7
|
import { stripBom } from "./23.mjs";
|
|
8
8
|
import { canonicalizeDir, canonicalizeResourcePath } from "./93.mjs";
|
|
9
9
|
import { findNearestProjectManifestSync } from "./80.mjs";
|
|
10
|
-
import { getCanonicalContentScriptEntryName, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX } from "./291.mjs";
|
|
10
|
+
import { getCanonicalContentScriptEntryName, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX, getContentScriptCssProbeMarker } from "./291.mjs";
|
|
11
11
|
initSync();
|
|
12
12
|
const schema = {
|
|
13
13
|
type: 'object',
|
|
@@ -172,9 +172,10 @@ function contentScriptWrapper(source, inputSourceMap) {
|
|
|
172
172
|
const bundleKey = declaredEntry ? getCanonicalContentScriptEntryName(declaredEntry.index) : `scripts/${String(relToScripts || '').replace(/\\/g, '/')}`;
|
|
173
173
|
const reinjectKey = declaredEntry ? `${bundleKey}::script-${declaredEntry.scriptIndex}` : bundleKey;
|
|
174
174
|
const buildToken = createBuildToken(rewrittenSource);
|
|
175
|
+
const cssProbeMarker = getContentScriptCssProbeMarker(bundleKey);
|
|
175
176
|
const cssAssetSpecifiers = collectStyleAssetSpecifiers(rewrittenSource);
|
|
176
177
|
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`;
|
|
177
|
-
const bundleCssHydrationInline = `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 = (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}\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(
|
|
178
|
+
const bundleCssHydrationInline = `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 = (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 = (function fetchCandidate(index){\n if (index >= cssUrls.length) return Promise.resolve("");\n return fetch(cssUrls[index]).then(function(response){\n if (!response || !response.ok) return "";\n return response.text();\n }).catch(function(){\n return "";\n }).then(function(text){\n if (typeof text === "string" && text.trim().length > 0) return text;\n return fetchCandidate(index + 1);\n });\n })(0).then(function(text){\n cssText = typeof text === "string" ? text : "";\n try { setTimeout(tick, 0); } catch (error) {}\n return cssText;\n }).catch(function(){ return ""; });\n return cssPromise;\n };\n var tries = 0;\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 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 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 }\n } catch (error) {}\n if (tries++ < 20) {\n if (!cssPromise) readCss();\n setTimeout(tick, 250);\n }\n };\n tick();\n } catch (error) {}\n}\n`;
|
|
178
179
|
const isBuiltInCompanion = /extension-js-(?:devtools|theme)/.test(String(packageJsonDir || ''));
|
|
179
180
|
const bootstrap = `var __EXTENSIONJS_BUNDLE_KEY=${JSON.stringify(bundleKey)};\nvar __EXTENSIONJS_REINJECT_KEY=${JSON.stringify(reinjectKey)};\nvar __EXTENSIONJS_REINJECT_BUILD_TOKEN=${JSON.stringify(buildToken)};\nvar __EXTENSIONJS_NO_FOREIGN_ADOPT=${JSON.stringify(isBuiltInCompanion)};\nfunction __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}\nvar __EXTENSIONJS_DEV_MARKERS_ENABLED=${JSON.stringify(!isProd)};\nvar __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${cssAssetUrlsInline}var __EXTENSIONJS_REINJECT_REGISTRY=(typeof globalThis==="object" && globalThis ? (globalThis.__EXTENSIONJS_DEV_REINJECT__ || (globalThis.__EXTENSIONJS_DEV_REINJECT__={})) : {});\nvar __EXTENSIONJS_REGISTERED_CLEANUPS=[];\nfunction __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}\nfunction __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}\nfunction __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_debugObserveOwnedRootRemoval(){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_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_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}\nfunction __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 try { __EXTENSIONJS_cleanupKnownRoots(); } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "cleaned"); } catch (error) {}\n };\n}\nfunction __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}\nfunction __EXTENSIONJS_patchDomRemovalApis(){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_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}\ntry {\n if (typeof globalThis === "object" && globalThis) {\n globalThis.__EXTENSIONJS_registerCleanup = __EXTENSIONJS_registerCleanup;\n globalThis.registerCleanup = __EXTENSIONJS_registerCleanup;\n }\n} catch (error) {}\n// Dev-only DOM instrumentation. Gated so production content scripts never\n// install a whole-document MutationObserver, monkey-patch Node.prototype\n// removal APIs, or write data-extjs-debug-* attributes onto the host page.\nif (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try { __EXTENSIONJS_debugObserveOwnedRootRemoval(); } catch (error) {}\n try { __EXTENSIONJS_patchDomRemovalApis(); } catch (error) {}\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) {}\nfunction __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 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`;
|
|
180
181
|
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 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 __EXTENSIONJS_REINJECT_GENERATION = (Number(__EXTENSIONJS_REINJECT_GENERATION) || 0) + 1;\n try { cleanup.__extjsGeneration = __EXTENSIONJS_REINJECT_GENERATION; cleanup.__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] content script default export failed to run", error); } catch (ignored) {}\n 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`;
|
|
@@ -7,7 +7,7 @@ import { reservedScriptsFolder } from "./266.mjs";
|
|
|
7
7
|
import { stripBom } from "./23.mjs";
|
|
8
8
|
import { canonicalizeDir, canonicalizeResourcePath } from "./93.mjs";
|
|
9
9
|
import { findNearestProjectManifestSync } from "./80.mjs";
|
|
10
|
-
import { getCanonicalContentScriptEntryName, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX } from "./291.mjs";
|
|
10
|
+
import { getCanonicalContentScriptEntryName, CANONICAL_CONTENT_SCRIPT_ENTRY_PREFIX, getContentScriptCssProbeMarker } from "./291.mjs";
|
|
11
11
|
initSync();
|
|
12
12
|
const schema = {
|
|
13
13
|
type: 'object',
|
|
@@ -172,9 +172,10 @@ function contentScriptWrapper(source, inputSourceMap) {
|
|
|
172
172
|
const bundleKey = declaredEntry ? getCanonicalContentScriptEntryName(declaredEntry.index) : `scripts/${String(relToScripts || '').replace(/\\/g, '/')}`;
|
|
173
173
|
const reinjectKey = declaredEntry ? `${bundleKey}::script-${declaredEntry.scriptIndex}` : bundleKey;
|
|
174
174
|
const buildToken = createBuildToken(rewrittenSource);
|
|
175
|
+
const cssProbeMarker = getContentScriptCssProbeMarker(bundleKey);
|
|
175
176
|
const cssAssetSpecifiers = collectStyleAssetSpecifiers(rewrittenSource);
|
|
176
177
|
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`;
|
|
177
|
-
const bundleCssHydrationInline = `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 = (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}\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(
|
|
178
|
+
const bundleCssHydrationInline = `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 = (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 = (function fetchCandidate(index){\n if (index >= cssUrls.length) return Promise.resolve("");\n return fetch(cssUrls[index]).then(function(response){\n if (!response || !response.ok) return "";\n return response.text();\n }).catch(function(){\n return "";\n }).then(function(text){\n if (typeof text === "string" && text.trim().length > 0) return text;\n return fetchCandidate(index + 1);\n });\n })(0).then(function(text){\n cssText = typeof text === "string" ? text : "";\n try { setTimeout(tick, 0); } catch (error) {}\n return cssText;\n }).catch(function(){ return ""; });\n return cssPromise;\n };\n var tries = 0;\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 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 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 }\n } catch (error) {}\n if (tries++ < 20) {\n if (!cssPromise) readCss();\n setTimeout(tick, 250);\n }\n };\n tick();\n } catch (error) {}\n}\n`;
|
|
178
179
|
const isBuiltInCompanion = /extension-js-(?:devtools|theme)/.test(String(packageJsonDir || ''));
|
|
179
180
|
const bootstrap = `var __EXTENSIONJS_BUNDLE_KEY=${JSON.stringify(bundleKey)};\nvar __EXTENSIONJS_REINJECT_KEY=${JSON.stringify(reinjectKey)};\nvar __EXTENSIONJS_REINJECT_BUILD_TOKEN=${JSON.stringify(buildToken)};\nvar __EXTENSIONJS_NO_FOREIGN_ADOPT=${JSON.stringify(isBuiltInCompanion)};\nfunction __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}\nvar __EXTENSIONJS_DEV_MARKERS_ENABLED=${JSON.stringify(!isProd)};\nvar __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${cssAssetUrlsInline}var __EXTENSIONJS_REINJECT_REGISTRY=(typeof globalThis==="object" && globalThis ? (globalThis.__EXTENSIONJS_DEV_REINJECT__ || (globalThis.__EXTENSIONJS_DEV_REINJECT__={})) : {});\nvar __EXTENSIONJS_REGISTERED_CLEANUPS=[];\nfunction __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}\nfunction __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}\nfunction __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_debugObserveOwnedRootRemoval(){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_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_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}\nfunction __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 try { __EXTENSIONJS_cleanupKnownRoots(); } catch (error) {}\n try { __EXTENSIONJS_setReinjectMarker(__EXTENSIONJS_REINJECT_KEY, Number(__EXTENSIONJS_REINJECT_GENERATION) || 0, "cleaned"); } catch (error) {}\n };\n}\nfunction __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}\nfunction __EXTENSIONJS_patchDomRemovalApis(){\n try {\n if (!__EXTENSIONJS_DEV_MARKERS_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}\ntry {\n if (typeof globalThis === "object" && globalThis) {\n globalThis.__EXTENSIONJS_registerCleanup = __EXTENSIONJS_registerCleanup;\n globalThis.registerCleanup = __EXTENSIONJS_registerCleanup;\n }\n} catch (error) {}\n// Dev-only DOM instrumentation. Gated so production content scripts never\n// install a whole-document MutationObserver, monkey-patch Node.prototype\n// removal APIs, or write data-extjs-debug-* attributes onto the host page.\nif (__EXTENSIONJS_DEV_MARKERS_ENABLED) {\n try { __EXTENSIONJS_debugObserveOwnedRootRemoval(); } catch (error) {}\n try { __EXTENSIONJS_patchDomRemovalApis(); } catch (error) {}\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) {}\nfunction __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 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`;
|
|
180
181
|
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 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 __EXTENSIONJS_REINJECT_GENERATION = (Number(__EXTENSIONJS_REINJECT_GENERATION) || 0) + 1;\n try { cleanup.__extjsGeneration = __EXTENSIONJS_REINJECT_GENERATION; cleanup.__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] content script default export failed to run", error); } catch (ignored) {}\n 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`;
|
|
@@ -3,11 +3,11 @@ const safeHistory = "u" > typeof globalThis ? globalThis.history : void 0;
|
|
|
3
3
|
try {
|
|
4
4
|
if ('object' == typeof safeLocation && safeLocation && String(safeLocation.protocol || '').includes('-extension:')) {
|
|
5
5
|
const q = String(safeLocation.search || '').toLowerCase();
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
6
|
+
const hasStaleGuards = q.includes('rspack-dev-server-hot=false') || q.includes('webpack-dev-server-hot=false');
|
|
7
|
+
if (hasStaleGuards && 'function' == typeof URL && 'object' == typeof safeHistory && safeHistory && 'function' == typeof safeHistory.replaceState) {
|
|
8
8
|
const u = new URL(String(safeLocation.href));
|
|
9
|
-
u.searchParams.
|
|
10
|
-
u.searchParams.
|
|
9
|
+
u.searchParams.delete('rspack-dev-server-hot');
|
|
10
|
+
u.searchParams.delete('webpack-dev-server-hot');
|
|
11
11
|
safeHistory.replaceState(null, '', u.toString());
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -3,11 +3,11 @@ const safeHistory = "u" > typeof globalThis ? globalThis.history : void 0;
|
|
|
3
3
|
try {
|
|
4
4
|
if ('object' == typeof safeLocation && safeLocation && String(safeLocation.protocol || '').includes('-extension:')) {
|
|
5
5
|
const q = String(safeLocation.search || '').toLowerCase();
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
6
|
+
const hasStaleGuards = q.includes('rspack-dev-server-hot=false') || q.includes('webpack-dev-server-hot=false');
|
|
7
|
+
if (hasStaleGuards && 'function' == typeof URL && 'object' == typeof safeHistory && safeHistory && 'function' == typeof safeHistory.replaceState) {
|
|
8
8
|
const u = new URL(String(safeLocation.href));
|
|
9
|
-
u.searchParams.
|
|
10
|
-
u.searchParams.
|
|
9
|
+
u.searchParams.delete('rspack-dev-server-hot');
|
|
10
|
+
u.searchParams.delete('webpack-dev-server-hot');
|
|
11
11
|
safeHistory.replaceState(null, '', u.toString());
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { Compiler } from '@rspack/core';
|
|
2
2
|
import type { DevOptions, Manifest, PluginInterface } from '../../../types';
|
|
3
|
-
export declare function getBackgroundEntryName(manifest: Manifest, browser: DevOptions['browser']
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
pageEntry?: undefined;
|
|
10
|
-
serviceWorkerEntry: string;
|
|
3
|
+
export declare function getBackgroundEntryName(manifest: Manifest, browser: DevOptions['browser'], context: {
|
|
4
|
+
manifestDir: string;
|
|
5
|
+
projectPath?: string;
|
|
6
|
+
}): {
|
|
7
|
+
pageEntry?: string;
|
|
8
|
+
serviceWorkerEntry?: string;
|
|
11
9
|
tryCatchWrapper: boolean;
|
|
12
10
|
eagerChunkLoading: boolean;
|
|
13
11
|
};
|
|
@@ -10,3 +10,6 @@ export declare function parseCanonicalContentScriptAsset(assetName: string): {
|
|
|
10
10
|
extension: 'js' | 'css';
|
|
11
11
|
} | undefined;
|
|
12
12
|
export declare function isCanonicalContentScriptAsset(assetName: string): boolean;
|
|
13
|
+
export declare const CONTENT_SCRIPT_CSS_PROBE_MARKER_PREFIX = "__EXTENSIONJS_CSS_PROBE__";
|
|
14
|
+
export declare function getContentScriptCssProbeMarker(entryName: string): string;
|
|
15
|
+
export declare function createContentScriptCssProbeMarkerPattern(): RegExp;
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
import type { DevOptions, Manifest } from '../../../types';
|
|
2
|
+
export declare const isRemoteUrl: (entry: string) => boolean;
|
|
3
|
+
export declare function resolveScriptEntryPath(entry: string, manifestDir: string, projectPath: string): string;
|
|
4
|
+
export declare function getBackgroundWorkerEntryName(options: {
|
|
5
|
+
manifest: Manifest;
|
|
6
|
+
browser: DevOptions['browser'];
|
|
7
|
+
manifestDir: string;
|
|
8
|
+
projectPath?: string;
|
|
9
|
+
}): 'background/service_worker' | 'background/scripts' | undefined;
|
|
1
10
|
export declare function getScriptEntries(scriptPath: string | string[] | undefined): string[];
|
|
2
11
|
export declare function getCssEntries(scriptPath: string | string[] | undefined): string[];
|
package/dist/plugin-web-extension/feature-scripts/steps/add-content-script-wrapper/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Compiler } from '@rspack/core';
|
|
2
2
|
import type { DevOptions, FilepathList, PluginInterface } from '../../../../types';
|
|
3
|
+
export declare function resolveBundleCssProbeMarker(cssPath: string, hasAsset: (name: string) => boolean, assetNames: () => string[]): string;
|
|
3
4
|
export declare class AddContentScriptWrapper {
|
|
4
5
|
static getBridgeScripts(manifestPath: string, browser?: DevOptions['browser']): FilepathList;
|
|
5
6
|
private readonly manifestPath;
|