From 8a68f49adb3bb15d8249ebf0363b26542e61ff91 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 12 Jul 2022 10:50:06 +0100 Subject: [PATCH] FIX: Detect firefox < 89 as an unsupported browser (#17443) Prior to v89, Firefox has bugs with document.execCommand("insertText"): https://bugzil.la/1220696 This commit introduces some variables to browser-detect, and therefore wraps the entire logic in an IIFE to avoid state leaking. (`let`/`const` are not supported on older browsers) --- .../discourse/scripts/browser-detect.js | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/scripts/browser-detect.js b/app/assets/javascripts/discourse/scripts/browser-detect.js index 3b93c144997..86cce506a88 100644 --- a/app/assets/javascripts/discourse/scripts/browser-detect.js +++ b/app/assets/javascripts/discourse/scripts/browser-detect.js @@ -1,12 +1,24 @@ -if (!window.WeakMap || !window.Promise || typeof globalThis === "undefined") { - window.unsupportedBrowser = true; -} else { - // Some implementations of `WeakMap.prototype.has` do not accept false - // values and Ember's `isClassicDecorator` sometimes does that (it only - // checks for `null` and `undefined`). - try { - new WeakMap().has(0); - } catch (err) { +/* eslint-disable no-var */ // `let` is not supported in very old browsers + +(function () { + if (!window.WeakMap || !window.Promise || typeof globalThis === "undefined") { window.unsupportedBrowser = true; + } else { + // Some implementations of `WeakMap.prototype.has` do not accept false + // values and Ember's `isClassicDecorator` sometimes does that (it only + // checks for `null` and `undefined`). + try { + new WeakMap().has(0); + } catch (err) { + window.unsupportedBrowser = true; + } + + var match = window.navigator.userAgent.match(/Firefox\/([0-9]+)\./); + var firefoxVersion = match ? parseInt(match[1], 10) : null; + if (firefoxVersion && firefoxVersion < 89) { + // prior to v89, Firefox has bugs with document.execCommand("insertText") + // https://bugzil.la/1220696 + window.unsupportedBrowser = true; + } } -} +})();