Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

When the script is loaded in <head> 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. (#1054)

Vianney MORAIN9013c1287163
diff --git a/frontend/public/widget.js b/frontend/public/widget.js
index decc511d2..cb545aec3 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);