From ce9488b63fa100150bcfde811212ea88b78b1002 Mon Sep 17 00:00:00 2001 From: vianm Date: Wed, 25 Feb 2026 19:05:15 +0100 Subject: [PATCH] When the script is loaded in without async, it registers a DOMContentLoaded listener. By the time the listener fires, document.currentScript is null, causing a crash. Capturing the reference at IIFE invocation time fixes the issue regardless of script placement or loading strategy. --- frontend/public/widget.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/public/widget.js b/frontend/public/widget.js index decc511d28..cb545aec3b 100644 --- a/frontend/public/widget.js +++ b/frontend/public/widget.js @@ -1,5 +1,5 @@ /* eslint-disable lingui/no-unlocalized-strings */ -(function () { +(function (scriptElement) { const isScriptLoaded = () => !!window.hiEventWidgetLoaded; const loadWidget = () => { @@ -7,7 +7,7 @@ let scriptOrigin; try { - const scriptURL = document.currentScript.src; + const scriptURL = scriptElement.src; scriptOrigin = new URL(scriptURL).origin; } catch (e) { console.error('HiEvent widget error: Invalid script URL'); @@ -86,4 +86,4 @@ loadWidget(); } } -})(); +})(document.currentScript);