From a64ea631b8a29f8cad0e572a8b3c6eb23ae25e2c Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Tue, 31 Mar 2026 14:24:55 +0200 Subject: [PATCH 1/2] Wrap webhook scripts in IIFE to prevent redeclaration errors Fixes SyntaxError: redeclaration of let tries in Firefox when webhook scripts are injected more than once via appendScriptStyle. Fixes https://sentry.galaxyproject.org/organizations/galaxy/issues/293105/ --- client/src/utils/utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/src/utils/utils.ts b/client/src/utils/utils.ts index 3a02cd41a47..717208ffe4d 100644 --- a/client/src/utils/utils.ts +++ b/client/src/utils/utils.ts @@ -269,11 +269,13 @@ export function time(): string { * @param data object containing script and style strings */ export function appendScriptStyle(data: Readonly<{ script?: string; styles?: string }>) { - // create a script tag inside head tag + // create a script tag inside head tag, wrapped in an IIFE to avoid + // "redeclaration of let" errors when the same webhook script is injected + // more than once (Firefox enforces this strictly in the global scope) if (data.script && data.script !== "") { const tag = document.createElement("script"); tag.type = "text/javascript"; - tag.textContent = data.script; + tag.textContent = `(function(){${data.script}})();`; document.head.appendChild(tag); } // create a style tag inside head tag From 4ff5a57de3c9438258d80a2e2fe33c89e9b3ffbf Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Wed, 1 Apr 2026 11:30:34 -0400 Subject: [PATCH 2/2] Add newlines around IIFE-wrapped script content Without the newlines, a webhook script ending in a line comment (// ...) would swallow the closing })(); and produce a SyntaxError. --- client/src/utils/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/utils/utils.ts b/client/src/utils/utils.ts index 717208ffe4d..d176c148a27 100644 --- a/client/src/utils/utils.ts +++ b/client/src/utils/utils.ts @@ -275,7 +275,7 @@ export function appendScriptStyle(data: Readonly<{ script?: string; styles?: str if (data.script && data.script !== "") { const tag = document.createElement("script"); tag.type = "text/javascript"; - tag.textContent = `(function(){${data.script}})();`; + tag.textContent = `(function(){\n${data.script}\n})();`; document.head.appendChild(tag); } // create a style tag inside head tag