Skip to content

Commit

Permalink
MWPW-127443
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaine Gunn committed Sep 1, 2023
1 parent d5861af commit 7b6b73d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
9 changes: 9 additions & 0 deletions acrobat/blocks/dc-converter-widget/dc-converter-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
73 changes: 46 additions & 27 deletions acrobat/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 7b6b73d

Please sign in to comment.