FIX: Find noscript element with crawler content (#10834)

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.

diff --git a/vendor/assets/javascripts/browser-update.js.erb b/vendor/assets/javascripts/browser-update.js.erb
index be54f3b..ea8c06f 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') + "'" %>;
 

GitHub sha: 340d9793

This commit appears in #10834 which was approved by ZogStriP. It was merged by udan11.