export declare const SCRIPTS_REPLAY_SHIM_SOURCE = ";(function () {\n try {\n if (typeof globalThis !== \"object\" || !globalThis) return;\n var injects = function (root) {\n return !!root && !!root.scripting && typeof root.scripting.executeScript === \"function\";\n };\n var chromeRef = injects(globalThis.chrome) ? globalThis.chrome : injects(globalThis.browser) ? globalThis.browser : null;\n if (!chromeRef) return;\n // The author may inject through either namespace, and one of them can\n // answer a callback only. The replay asks the one that hands a promise back.\n var replayRef = injects(globalThis.browser) ? globalThis.browser : chromeRef;\n if (globalThis.__extjsScriptsReplayInstalled) return;\n globalThis.__extjsScriptsReplayInstalled = true;\n\n var MAX_TABS = 50;\n var MAX_ENTRIES_PER_TAB = 50;\n var registry = new Map();\n var originalExecuteScript = replayRef.scripting.executeScript.bind(replayRef.scripting);\n var tabsApi = replayRef.tabs && typeof replayRef.tabs.get === \"function\" ? replayRef.tabs : null;\n\n var serialize = function (entry) {\n try {\n return JSON.stringify({\n files: entry && Array.isArray(entry.files) ? entry.files : [],\n world: entry && entry.world ? String(entry.world) : \"\"\n });\n } catch (error) {\n // Arguments that cannot be serialized are not kept for a replay\n return \"\";\n }\n };\n\n var pageKey = function (url) {\n if (typeof url !== \"string\" || !url) return \"\";\n try {\n var parsed = new URL(url);\n return parsed.origin + parsed.pathname;\n } catch (error) {\n // A URL that does not parse is compared as written\n return url;\n }\n };\n\n // Resolves to the page the tab shows now, \"\" when the url is not visible\n // to the extension, and null once the tab is gone.\n var currentPage = function (tabId) {\n if (!tabsApi) return Promise.resolve(\"\");\n try {\n var lookup = tabsApi.get(tabId);\n if (!lookup || typeof lookup.then !== \"function\") return Promise.resolve(\"\");\n return lookup.then(\n function (tab) { return tab ? pageKey(tab.url) : null; },\n function () { return null; }\n );\n } catch (error) {\n return Promise.resolve(\"\");\n }\n };\n\n var remember = function (tabId, entry) {\n var entries = (registry.get(tabId) || []).filter(function (e) { return e.sig !== entry.sig; });\n entries.push(entry);\n registry.delete(tabId);\n registry.set(tabId, entries.slice(-MAX_ENTRIES_PER_TAB));\n while (registry.size > MAX_TABS) {\n registry.delete(registry.keys().next().value);\n }\n };\n\n var track = function (injection) {\n try {\n var tabId = injection && injection.target && injection.target.tabId;\n var files =\n injection && Array.isArray(injection.files) ? injection.files.slice() : null;\n if (typeof tabId !== \"number\") return;\n if (!files || !files.length) return;\n var world = injection.world ? String(injection.world) : undefined;\n var entry = { files: files, world: world, sig: serialize({ files: files, world: world }), page: \"\" };\n remember(tabId, entry);\n currentPage(tabId).then(function (page) {\n entry.page = page || \"\";\n }, function () {});\n } catch (error) {\n // An injection the tracker cannot read is sent and not replayed\n }\n };\n\n var tracked = [];\n var trackCalls = function (root) {\n if (!injects(root) || tracked.indexOf(root.scripting) !== -1) return;\n var scripting = root.scripting;\n var native = scripting.executeScript.bind(scripting);\n scripting.executeScript = function (injection) {\n track(injection);\n return native.apply(null, arguments);\n };\n tracked.push(scripting);\n };\n trackCalls(globalThis.chrome);\n trackCalls(globalThis.browser);\n\n try {\n if (chromeRef.tabs && chromeRef.tabs.onRemoved && typeof chromeRef.tabs.onRemoved.addListener === \"function\") {\n chromeRef.tabs.onRemoved.addListener(function (tabId) {\n registry.delete(tabId);\n });\n }\n } catch (error) {\n // With no tabs.onRemoved a closed tab is pruned on its next read\n }\n\n var normalizeFile = function (value) {\n return String(value || \"\").replace(/^[/\\\\]+/, \"\");\n };\n\n var fileMatches = function (entryFile, changedNormalized) {\n var fn = normalizeFile(entryFile);\n for (var i = 0; i < changedNormalized.length; i++) {\n var c = changedNormalized[i];\n if (!c) continue;\n if (fn === c) return true;\n if (fn.length > c.length && fn.slice(fn.length - c.length - 1) === \"/\" + c) return true;\n if (c.length > fn.length && c.slice(c.length - fn.length - 1) === \"/\" + fn) return true;\n }\n return false;\n };\n\n var entryMatches = function (entry, changedNormalized) {\n for (var i = 0; i < entry.files.length; i++) {\n if (fileMatches(entry.files[i], changedNormalized)) return true;\n }\n return false;\n };\n\n var replayEntry = function (tabId, entry) {\n try {\n return Promise.resolve(\n originalExecuteScript({\n target: { tabId: tabId },\n files: entry.files,\n world: entry.world\n })\n ).then(\n function () { return { ok: true, tabId: tabId, files: entry.files }; },\n function (error) {\n return {\n ok: false,\n tabId: tabId,\n files: entry.files,\n error: String((error && error.message) || error)\n };\n }\n );\n } catch (error) {\n return Promise.resolve(null);\n }\n };\n\n var replayTab = function (tabId, changedNormalized) {\n return currentPage(tabId).then(function (page) {\n if (page === null) {\n registry.delete(tabId);\n return [];\n }\n // An entry recorded on another page belongs to a document this tab\n // no longer shows, so it is dropped instead of injected into the new one.\n var live = (registry.get(tabId) || []).filter(function (entry) {\n return !(page && entry.page && entry.page !== page);\n });\n if (!live.length) {\n registry.delete(tabId);\n return [];\n }\n registry.set(tabId, live);\n return Promise.all(\n live\n .filter(function (entry) { return entryMatches(entry, changedNormalized); })\n .map(function (entry) { return replayEntry(tabId, entry); })\n );\n }, function () { return []; });\n };\n\n globalThis.__extjsScriptsReplay = function (changedFiles) {\n var changedNormalized = (Array.isArray(changedFiles) ? changedFiles : []).map(normalizeFile);\n var tabReplays = [];\n registry.forEach(function (entries, tabId) {\n if (!entries.some(function (entry) { return entryMatches(entry, changedNormalized); })) return;\n tabReplays.push(replayTab(tabId, changedNormalized));\n });\n return Promise.all(tabReplays).then(function (perTab) {\n var outcomes = [];\n perTab.forEach(function (results) {\n results.forEach(function (result) {\n if (result) outcomes.push(result);\n });\n });\n return outcomes;\n });\n };\n } catch (error) {\n // A shim that fails to install leaves chrome.scripting as it was\n }\n})();\n";