Merge pull request #22320 from mvdbeek/fix_webhook_script_redeclaration

[26.0] Wrap webhook scripts in IIFE to prevent redeclaration errors
This commit is contained in:
Marius van den Beek
2026-04-06 14:42:32 +02:00
committed by GitHub
+4 -2
View File
@@ -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(){\n${data.script}\n})();`;
document.head.appendChild(tag);
}
// create a style tag inside head tag