FEATURE: Show noscript view to unsupported browsers (#9373)

FEATURE: Show noscript view to unsupported browsers (#9373)

diff --git a/app/assets/javascripts/browser-detect.js b/app/assets/javascripts/browser-detect.js
new file mode 100644
index 0000000..bdbbc27
--- /dev/null
+++ b/app/assets/javascripts/browser-detect.js
@@ -0,0 +1,3 @@
+if (!window.WeakMap || !window.Promise) {
+  window.unsupportedBrowser = true;
+}
diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js
index 10fb7dd..eea5c75 100644
--- a/app/assets/javascripts/discourse.js
+++ b/app/assets/javascripts/discourse.js
@@ -6,6 +6,10 @@ import discourseComputed, { observes } from "discourse-common/utils/decorators";
 import FocusEvent from "discourse-common/mixins/focus-event";
 import deprecated from "discourse-common/lib/deprecated";
 
+if (window.unsupportedBrowser) {
+  throw "Unsupported browser detected";
+}
+
 const _pluginCallbacks = [];
 
 const Discourse = Application.extend(FocusEvent, {
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 7340c45..22a29e1 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -19,6 +19,8 @@
 
     <%= build_plugin_html 'server:before-script-load' %>
 
+    <%= preload_script 'browser-detect' %>
+
     <%= preload_script "locales/#{I18n.locale}" %>
     <%- if ExtraLocalesController.client_overrides_exist? %>
       <%= preload_script_url ExtraLocalesController.url('overrides') %>
diff --git a/config/application.rb b/config/application.rb
index cf820c3..bad76c9 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -135,6 +135,7 @@ module Discourse
       vendor.js
       admin.js
       preload-store.js
+      browser-detect.js
       browser-update.js
       break_string.js
       ember_jquery.js
diff --git a/plugins/discourse-internet-explorer/config/locales/server.en.yml b/plugins/discourse-internet-explorer/config/locales/server.en.yml
index 6e1292e..0310082 100644
--- a/plugins/discourse-internet-explorer/config/locales/server.en.yml
+++ b/plugins/discourse-internet-explorer/config/locales/server.en.yml
@@ -1,4 +1,4 @@
 en:
   site_settings:
-    discourse_internet_explorer_enabled: "Internet Explorer support"
+    discourse_internet_explorer_enabled: "Enable temporary Internet Explorer support. This plugin is an effort to maintain compatibility with older browsers and will be completely removed in the near future."
     discourse_internet_explorer_deprecation_warning: "Show an Internet Explorer deprecation warning"
diff --git a/plugins/discourse-internet-explorer/public/js/ie.js b/plugins/discourse-internet-explorer/public/js/ie.js
index 6c998e4..168731d 100644
--- a/plugins/discourse-internet-explorer/public/js/ie.js
+++ b/plugins/discourse-internet-explorer/public/js/ie.js
@@ -972,6 +972,9 @@ if (!String.prototype.startsWith) {
 /* eslint-enable */
 
 // Polyfill Promise - used by popper.js
+if (!window.Promise) {
+  window.Promise = true;
+}
 window.addEventListener(
   "load",
   function() {
diff --git a/vendor/assets/javascripts/browser-update.js.erb b/vendor/assets/javascripts/browser-update.js.erb
index 7309e8f..b32410b 100644
--- a/vendor/assets/javascripts/browser-update.js.erb
+++ b/vendor/assets/javascripts/browser-update.js.erb
@@ -4,25 +4,26 @@
 (function() {
 
 var $buo = function() {
-
-  var badAndroid = false, ua = null;
-
   // Sometimes we have to resort to parsing the user agent string. :(
   if (navigator && navigator.userAgent) {
-    ua = navigator.userAgent;
-  }
+    var ua = navigator.userAgent;
 
-  // sam: we require WeakMap, this allows us to easily feature detect IE10 that does not support it
-  // This also catches ancient android phones that never had that feature (2.2 and below)
-  if (window.WeakMap) {
-    return;
+    // we don't ask Googlebot to update their browser
+    if (ua.indexOf('Googlebot') >= 0 || ua.indexOf('Mediapartners') >= 0 || ua.indexOf('AdsBot') >= 0) {
+      return;
+    }
   }
 
-  // we don't ask Googlebot to update their browser
-  if (ua.indexOf('Googlebot') >= 0 || ua.indexOf('Mediapartners') >= 0 || ua.indexOf('AdsBot') >= 0) {
+  if (!window.unsupportedBrowser) {
     return;
   }
 
+  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;
+
   // retrieve localized browser upgrade text
   var t = <%= "'" + I18n.t('js.browser_update') + "'" %>;
 

GitHub sha: 73d71e3f

This commit appears in #9373 which was approved by davidtaylorhq. It was merged by udan11.