最全面的判断非 Chrome 浏览器方法

220 阅读1分钟

前言

  • 这里点名批评国内厂商,用谷歌开源的浏览器做的产品,还不加上自己的 UserAgent 识别信息
  • 着重批评下 360,只有他自己的网站才会在 user-agent 里面加上识别信息,其他网站屏蔽

判断方法

const isSupportBrowser = () => {
  const agent = navigator.userAgent.toLocaleLowerCase()
  const mimeType = _.map(navigator.mimeTypes, item => item.type).join(',').toLowerCase()
  // 能识别到这个的,都是非 Chrome 官方浏览器
  if (mimeType.includes('360soft') || mimeType.includes('tecent')) {
    return false
  }
  // 360 公司旗下软件
  if (agent.includes('qihu')) {
    return false
  }
  // 360 安全浏览器
  if (agent.includes('360se')) {
    return false
  }
  // 360 游戏浏览器
  if (agent.includes('360gt')) {
    return false
  }
  // QQ浏览器
  if (agent.includes('qqbrowser')) {
    return false
  }
  // 腾讯TT
  if (agent.includes('tencent')) {
    return false
  }
  // 火狐浏览器
  if (agent.includes('firefox')) {
    return false
  }
  // 遨游浏览器
  if (agent.includes('maxthon')) {
    return false
  }
  // 淘宝浏览器
  if (agent.includes('taobrowser')) {
    return false
  }
  // 搜狗浏览器
  if (agent.includes('metasr')) {
    return false
  }
  // UC浏览器
  if (agent.includes('ubrowser')) {
    return false
  }

  return true
}