1

How can I detect if user is accessing my website in Webview or on browser?

My websites backend is PHP and Frontend is Vue.

Misael
  • 93
  • 1
  • 8

1 Answers1

1

I have found this function in this site: https://codepen.io/jackmu95/pen/NLzqJR

It worked well for me.

function isWebview() {
  const navigator = window.navigator
  const userAgent = navigator.userAgent
  const normalizedUserAgent = userAgent.toLowerCase()
  const standalone = navigator.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
}
Misael
  • 93
  • 1
  • 8