Last active
September 10, 2023 04:47
-
-
Save BorisChumichev/7c0ea033daf33da73306a396ffa174d1 to your computer and use it in GitHub Desktop.
iOS Webview detection with Javascript
This file contains 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
const hasValidDocumentElementRatio = | |
[ 320 / 454 // 5, SE | |
, 375 / 553 // 6, 7, 8 | |
, 414 / 622 // 6, 7, 8 Plus | |
, 375 / 812 // X | |
, 414 / 896 // Xs, Xr | |
].some(ratio => | |
ratio === document.documentElement.clientWidth / | |
document.documentElement.clientHeight | |
) | |
const hasSafariInUA = /Safari/.test(navigator.userAgent) | |
const isiOSSafari = hasSafariInUA && hasValidDocumentElementRatio // <- this one is set to false for webviews |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment