Skip to content

Instantly share code, notes, and snippets.

@shhider
Created January 11, 2018 05:46
Show Gist options
  • Save shhider/59a5b4709dafe2b7a35072f5e2919d91 to your computer and use it in GitHub Desktop.
Save shhider/59a5b4709dafe2b7a35072f5e2919d91 to your computer and use it in GitHub Desktop.
Browser environment sniffing
// source: https://github.com/vuejs/vue/blob/dev/src/core/util/env.js
export const inBrowser = typeof window !== 'undefined'
export const inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform
export const weexPlatform = inWeex && WXEnvironment.platform.toLowerCase()
export const UA = inBrowser && window.navigator.userAgent.toLowerCase()
export const isIE = UA && /msie|trident/.test(UA)
export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
export const isEdge = UA && UA.indexOf('edge/') > 0
export const isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android')
export const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios')
export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment