Skip to content

Instantly share code, notes, and snippets.

@SonyStone
Created February 28, 2024 11:22
Show Gist options
  • Save SonyStone/73d131095f024dac78df71cee60c4461 to your computer and use it in GitHub Desktop.
Save SonyStone/73d131095f024dac78df71cee60c4461 to your computer and use it in GitHub Desktop.
export function isWebview() {
const navigator = window.navigator;
const userAgent = navigator.userAgent;
const normalizedUserAgent = userAgent.toLowerCase();
const standalone = (navigator as any).standalone;
const isIos =
/ip(ad|hone|od)/.test(normalizedUserAgent) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
const isAndroid = /android/.test(normalizedUserAgent);
const isSafari = /safari/.test(normalizedUserAgent);
const isWebview =
(isAndroid && /; wv\)/.test(normalizedUserAgent)) ||
(isIos && !standalone && !isSafari);
return isWebview;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment