From 340d97935760875db4dc85240e121ebdeda5ae80 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Tue, 6 Oct 2020 19:12:12 +0300 Subject: [PATCH] FIX: Find noscript element with crawler content (#10834) There can be more than one noscript element on a page (from various plugins), but only the one with data-path attribute as set in application.html.erb contains the crawler content. --- vendor/assets/javascripts/browser-update.js.erb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vendor/assets/javascripts/browser-update.js.erb b/vendor/assets/javascripts/browser-update.js.erb index be54f3bc0f8..ea8c06f4c85 100644 --- a/vendor/assets/javascripts/browser-update.js.erb +++ b/vendor/assets/javascripts/browser-update.js.erb @@ -21,10 +21,14 @@ var $buo = function() { document.getElementsByTagName('body')[0].classList.add("crawler"); var mainElement = document.getElementById("main"); var noscriptElements = document.getElementsByTagName("noscript"); - // noscriptElements[0].innerHTML contains encoded HTML - var innerHTML = noscriptElements[0].childNodes[0].nodeValue; - mainElement.innerHTML = innerHTML; - + // find the element with the "data-path" attribute set + for (var i = 0; i < noscriptElements.length; ++i) { + if (noscriptElements[i].dataset["path"]) { + // noscriptElements[i].innerHTML contains encoded HTML + mainElement.innerHTML = noscriptElements[i].childNodes[0].nodeValue; + break; + } + } // retrieve localized browser upgrade text var t = <%= "'" + I18n.t('js.browser_update') + "'" %>;