Skip to content

Instantly share code, notes, and snippets.

@BorisChumichev
Last active September 10, 2023 04:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BorisChumichev/7c0ea033daf33da73306a396ffa174d1 to your computer and use it in GitHub Desktop.
Save BorisChumichev/7c0ea033daf33da73306a396ffa174d1 to your computer and use it in GitHub Desktop.
iOS Webview detection with Javascript
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