From 89141ae58572e3143e1d7e508ed6edb19fcb5c2b Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Tue, 28 Jan 2025 12:16:36 +0100 Subject: [PATCH] fix(core feature-detection): Fix loading of modernizr script. In some situations loading of the modernizr.min.js script failed because the base url could be incorrect. That is fixed with a non-IE compatible method of getting the current's script URL, which is safe to use. The problem surfaced in Plone while loading the Patternslib library and in between the protect.js script was loaded. The base url was calculated for the protect.js script and the modernizr script could not be loaded. --- src/core/feature-detection.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/feature-detection.js b/src/core/feature-detection.js index 664c316dd..6cc5e945c 100644 --- a/src/core/feature-detection.js +++ b/src/core/feature-detection.js @@ -18,15 +18,13 @@ } // Get the current script tag's URL. - // See: https://stackoverflow.com/a/984656/1337474 - const scripts = document.getElementsByTagName("script"); - const script = scripts[scripts.length - 1]; - let script_url = script.src; + const script_url = document.currentScript.src; // Get the base URL of the current script tag's URL. - script_url = script_url.substring(0, script_url.lastIndexOf("/")) + "/"; + let base_url = script_url.substring(0, script_url.lastIndexOf("/")) + "/"; + base_url = base_url.replace("chunks/", ""); // Inject a new one with the modernizr bundle. const script_tag = document.createElement("script"); - script_tag.src = script_url + "modernizr.min.js"; + script_tag.src = base_url + "modernizr.min.js"; document.getElementsByTagName("head")[0].appendChild(script_tag); })();