2

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

My websites backend is PHP and Frontend is Vue.

1
  • The dupes I posted can be used on PHP or client. Scroll down to the newest answer Commented Feb 12, 2023 at 7:12

1 Answer 1

3

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
}
Sign up to request clarification or add additional context in comments.

2 Comments

Is this supposed to show true on iOS on iPhone 13? Because it does not
It is. I started to use a lib for handling this for me npmjs.com/package/is-ua-webview

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.