Skip to content

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

FEATURE: Introduce warning banner for Safari 15 deprecation (#31928)

David Taylor38872b5b9b0a
diff --git a/app/assets/javascripts/discourse/app/instance-initializers/safari-15-deprecation.js b/app/assets/javascripts/discourse/app/instance-initializers/safari-15-deprecation.js
new file mode 100644
index 00000000000..5b8fd1f3764
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/instance-initializers/safari-15-deprecation.js
@@ -0,0 +1,35 @@
+import { apiInitializer } from "discourse/lib/api";
+import { i18n } from "discourse-i18n";
+
+function supportsLookbehind() {
+ try {
+ return new RegExp("(?<=a)b").test("ab");
+ } catch {
+ return false;
+ }
+}
+
+// We're expecting to catch Safari < 16 here, but using feature detection
+// instead of user-agent parsing, so that we also warn any other browsers missing
+// these features.
+const checks = {
+ relativeColor: CSS.supports("(color: hsl(from white h s l))"),
+ subgrid: CSS.supports("(grid-template-rows: subgrid)"),
+ lookbehindRegex: supportsLookbehind(),
+};
+
+export default apiInitializer((api) => {
+ if (!Object.values(checks).every(Boolean)) {
+ // eslint-disable-next-line no-console
+ console.error("Feature detection result", checks);
+ api.addGlobalNotice(
+ i18n("safari_15_warning", { url: "https://meta.discourse.org/t/358131" }),
+ "browser-deprecation-warning",
+ {
+ dismissable: true,
+ level: "warn",
+ dismissDuration: moment.duration(1, "week"),
+ }
+ );
+ }
+});
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 6ef653c5dfa..e2ec69ec174 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -5160,6 +5160,7 @@ en:
paste: "Paste..."
save: "Save as..."
powered_by_discourse: "Powered by Discourse"
+ safari_15_warning: "Your browser will soon be incompatible with this community. To keep participating here, please upgrade your browser or <a href='%{url}'>learn more</a>."
# This section is exported to the javascript for i18n in the admin section
admin_js: