diff --git a/src/content/deps/amd.ts b/src/content/deps/amd.ts index 759f4d5..1ced3ee 100644 --- a/src/content/deps/amd.ts +++ b/src/content/deps/amd.ts @@ -2,6 +2,11 @@ import { amdLite } from "amd-lite"; const originalDefine = amdLite.define; +/** + * Set of already defined modules. Used for deduplication. + */ +const definedModules = new Set(); + /** * Throttle timer to make sure only one attempt at loading modules will run for a batch of loaded scripts. */ @@ -19,6 +24,15 @@ function scheduleModulesAutoRun() { } 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); + originalDefine(name, dependencies, function () { const callbackResult = originalCallback(...arguments);