Detect if user is using webview for android/iOS or a regular browser

后端 未结 10 2204
迷失自我
迷失自我 2020-11-28 07:27

How to detect if the user is browsing the page using webview for android or iOS?

There are various soluti

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 08:16

    If you're using Flask (and not PHP), you can check to see if "wv" is in the string for the "User-Agent" header. Feel free to edit / add a more precise way of checking it, but basically "wv" is put there if it's a web view; otherwise, it is not there.

    user_agent_header = request.headers.get('User-Agent', None)
    is_web_view = "wv" in str(header_request) if user_agent_header is not None else False
    

    Chrome Developer Docs:

    WebView UA in Lollipop and Above

    In the newer versions of WebView, you can differentiate the WebView by looking for the wv field as highlighted below.

    Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36

提交回复
热议问题