Skip to content

A platform for community discussion. Free, open, simple.

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

Dan Ungureanu73d71e3feed0
diff --git a/app/assets/javascripts/browser-detect.js b/app/assets/javascripts/browser-detect.js
new file mode 100644
index 00000000000..bdbbc27b3ef
--- /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 10fb7dd407d..eea5c756400 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 7340c45a467..22a29e19e43 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 cf820c39dc6..bad76c94f69 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 6e1292efeb4..03100823db4 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 6c998e402a1..168731d5ffb 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 7309e8fdcf8..b32410b8e6d 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') + "'" %>;