Skip to content

Instantly share code, notes, and snippets.

@ignaciolg
Last active August 13, 2019 21:39
Show Gist options
  • Save ignaciolg/c63003460cfecec2137c57e10169ba3a to your computer and use it in GitHub Desktop.
Save ignaciolg/c63003460cfecec2137c57e10169ba3a to your computer and use it in GitHub Desktop.
Check from the server side the user agent of the client and determine what browser is
// only google chrome
const isChrome = (userAgent) => /^.(?!.*samsungbrowser).*chrome(?!.*opr|.*edg|.*Puffin|.*SamsungBrowser|.*YaBrowser|.*miui).*$/i.test(userAgent)
// only safari browser
const isSafari = (userAgent) => /^((?!chrome|android|opios|fxios).)*safari/i.test(userAgent);
// only edge based on chrome
const isEdge = (userAgent) =>/^.*edge?\//i.test(userAgent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment