nuxt-supported-browsers
Version:
Prevet to load Nuxt.js app in unsupported old browsers
23 lines (22 loc) • 760 B
JavaScript
export function useDetectBrowser(ua) {
let temp;
const agent = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) ?? [];
if (/trident/i.test(agent[1])) {
temp = /\brv[ :]+(\d+)/g.exec(ua) ?? [];
return { name: "Internet Explorer", version: +temp[1] || 0 };
}
if (agent[1] === "Chrome") {
temp = ua.match(/\b(OPR|Edge|Edg)\/(\d+)/);
if (temp != null) {
if (temp[1] === "Edg")
return { name: "Edge", version: +temp[2] };
if (temp[1] === "OPR")
return { name: "Opera", version: +temp[2] };
}
}
agent[2] = agent[2] || navigator.userAgent || "-?";
if ((temp = ua.match(/version\/(\d+)/i)) != null) {
agent[2] = temp[1];
}
return { name: agent[1], version: +agent[2] };
}