Skip to content

Instantly share code, notes, and snippets.

@KamaMakh
Created June 24, 2022 05:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KamaMakh/ce96a23c6cf5526da4a0827d92485833 to your computer and use it in GitHub Desktop.
Save KamaMakh/ce96a23c6cf5526da4a0827d92485833 to your computer and use it in GitHub Desktop.
Detect Browser, Engine, OS, CPU, and Device
export const isSafari = () => {
const ua = window.navigator.userAgent.toLowerCase();
return (
ua.includes('safari') &&
!ua.includes('crios') &&
!ua.includes('fxios') &&
!ua.includes('android')
);
};
export const isAndroid = () => {
const ua = window.navigator.userAgent.toLowerCase();
return (
ua.includes('android') &&
!ua.includes('safari') &&
!ua.includes('ipad') &&
!ua.includes('iphone')
);
};
export const isIOs = () => {
const ua = window.navigator.userAgent.toLowerCase();
return (
(ua.includes('iphone') || ua.includes('ipad')) && !ua.includes('android')
);
};
export const getIOSVersion = () => {
if (/iP(hone|od|ad)/.test(navigator.platform)) {
const v = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
}
return 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment