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.
This commit is contained in:
Dan Ungureanu 2020-10-06 19:12:12 +03:00 committed by GitHub
parent e175c467cc
commit 340d979357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -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') + "'" %>;