diff --git a/acrobat/blocks/dc-converter-widget/dc-converter-widget.js b/acrobat/blocks/dc-converter-widget/dc-converter-widget.js index bd763a6d..9b765d36 100644 --- a/acrobat/blocks/dc-converter-widget/dc-converter-widget.js +++ b/acrobat/blocks/dc-converter-widget/dc-converter-widget.js @@ -184,6 +184,15 @@ export default async function init(element) { REDIRECT_URL_DIV.remove(); } + // Feature checking for old browsers + const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html'; + if (window?.browser?.name === 'Internet Explorer' || + window?.browser?.name === 'Microsoft Edge' && window?.browser?.version.split('.')[0] < 86 || + window?.browser?.name === 'Microsoft Edge' && !window?.browser?.version || + window?.browser?.name === 'Safari' && window?.browser?.version.split('.')[0] < 14 || + window?.browser?.name === 'Safari' && !window?.browser?.version ) { + window.location.assign(EOLBrowserPage); + } // Generate cache url const GENERATE_CACHE_URL_DIV = widget.querySelectorAll('div')[4]; diff --git a/acrobat/scripts/scripts.js b/acrobat/scripts/scripts.js index 66b79f23..3e63e24c 100644 --- a/acrobat/scripts/scripts.js +++ b/acrobat/scripts/scripts.js @@ -45,28 +45,60 @@ const getLocale = (locales, pathname = window.location.pathname) => { return locale; } -const getBrowserData = () => { - let browser = {} - if (navigator.userAgentData) { - const data = navigator.userAgentData; - let name = ''; - for (const item of data.brands) { - if(['Chromium', 'Google Chrome'].includes(item.brand)){ - name = 'Chrome'; - } +const getBrowserData = function (userAgent) { + if (!userAgent) { + return {}; + } + const browser = { + ua: userAgent, + isMobile: userAgent.includes('Mobile'), + }; + + const regex = [ + { + browserReg: /edg([ae]|ios)?/i, + versionReg: /edg([ae]|ios)?[\s/](\d+(\.?\d+)+)/i, + name: 'Microsoft Edge', + }, + { + browserReg: /chrome|crios|crmo/i, + versionReg: /(?:chrome|crios|crmo)\/(\d+(\.?\d+)+)/i, + name: 'Chrome', + }, + { + browserReg: /firefox|fxios|iceweasel/i, + versionReg: /(?:firefox|fxios|iceweasel)[\s/](\d+(\.?\d+)+)/i, + name: 'Firefox', + }, + { + browserReg: /msie|trident/i, + versionReg: /(?:msie |rv:)(\d+(\.?\d+)+)/i, + name: 'Internet Explorer', + }, + { + browserReg: /safari|applewebkit/i, + versionReg: /(?:version)\/(\d+(\.?\d+)+)/i, + name: 'Safari', + }, + ]; - if (item.brand === 'Microsoft Edge') { - name = 'Microsoft Edge'; - break; + for (const reg of regex) { + if (reg.browserReg.test(userAgent)) { + browser.name = reg.name; + const version = userAgent.match(reg.versionReg); + if (version) { + browser.version = reg.name === 'Microsoft Edge' ? version[2] : version[1]; } + + return browser; } - browser.name = name; - browser.isMobile = data.mobile; } return browser; }; +//Get browser data +window.browser = getBrowserData(window.navigator.userAgent); function loadStyles(paths) { paths.forEach((path) => { @@ -209,19 +241,6 @@ const CONFIG = { }; -// Feature checking for old browsers -const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html'; -try { - const testNode = document.createElement('div'); - testNode.replaceChildren(); -} catch (e) { - //EOL Redirect - window.location.assign(EOLBrowserPage); -} - -//Get browser data -window.browser = getBrowserData(); - // Default to loading the first image as eager. (async function loadLCPImage() { const lcpImg = document.querySelector('img');