From e0fb524382dacf42c9f14459855632f15d2b98b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Stamatovi=C4=87?= Date: Thu, 15 Sep 2022 07:08:03 +0200 Subject: [PATCH] navigator.platform is deprecated (#2530) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I'm submitting a little update for browser detection: 1. `navigator.platform` is deprecated - it's prefered to use `navigator.userAgent` https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform 2. No need for the brackets in the RegEx - you can test this on https://regex101.com And that's about it. Maybe I missed the point, do let me know! ❤️ --- src/js/utils/browser.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/js/utils/browser.js b/src/js/utils/browser.js index 6b5e768a..1d485413 100644 --- a/src/js/utils/browser.js +++ b/src/js/utils/browser.js @@ -5,12 +5,11 @@ const browser = { isIE: Boolean(window.document.documentMode), - isEdge: window.navigator.userAgent.includes('Edge'), - isWebkit: 'WebkitAppearance' in document.documentElement.style && !/Edge/.test(navigator.userAgent), - isIPhone: /(iPhone|iPod)/gi.test(navigator.platform), + isEdge: /Edge/g.test(navigator.userAgent), + isWebkit: 'WebkitAppearance' in document.documentElement.style && !/Edge/g.test(navigator.userAgent), + isIPhone: /iPhone|iPod/gi.test(navigator.userAgent) && navigator.maxTouchPoints > 1, isIos: - (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1) || - /(iPad|iPhone|iPod)/gi.test(navigator.platform), + /iPad|iPhone|iPod/gi.test(navigator.userAgent) && navigator.maxTouchPoints > 1 }; export default browser;