From cf28d2d131146fc9180323bc6140578923e3a828 Mon Sep 17 00:00:00 2001 From: KoloMl Date: Wed, 13 Aug 2025 15:27:25 +0400 Subject: [PATCH] AMD Loader: Ignore duplicated module definitions This fixes an error appearing when chunk is mention multiple times for different entry content scripts. --- src/content/deps/amd.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/content/deps/amd.ts b/src/content/deps/amd.ts index 9f4f525..5c408fd 100644 --- a/src/content/deps/amd.ts +++ b/src/content/deps/amd.ts @@ -2,7 +2,21 @@ import { amdLite } from "amd-lite"; const originalDefine = amdLite.define; +/** + * Set of already defined modules. Used for deduplication. + */ +const definedModules = new Set(); + amdLite.define = (name, dependencies, originalCallback) => { + // Chrome doesn't run the same content script multiple times, while Firefox does. Since each content script and their + // chunks are intended to be run only once, we should just ignore any attempts of running the same module more than + // once. Names of the modules are assumed to be unique. + if (definedModules.has(name)) { + return; + } + + definedModules.add(name); + return originalDefine(name, dependencies, function () { const callbackResult = originalCallback(...arguments);