Created
June 24, 2022 05:22
-
-
Save KamaMakh/ce96a23c6cf5526da4a0827d92485833 to your computer and use it in GitHub Desktop.
Detect Browser, Engine, OS, CPU, and Device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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