Android, webview user agent vs browser user agent

前端 未结 7 1048
眼角桃花
眼角桃花 2020-12-03 03:14

I\'m building my website and I want to know whether the user is using Android\'s browser or an app with a webview.

is it possible ??

7条回答
  •  盖世英雄少女心
    2020-12-03 03:30

    FYI: This can't be done with user agents, however it can be detected. Android's web views send an addition header "X-Requested-With". The value of this header will be the application's name space that is running the webview.

    For Example Dolphin browser sends: "mobi.mgeek.TunnyBrowser" My test app sent: "com.jamestymann.identifyawebview"

    The standard browser actually does not send this header at all, so it is pretty easy to detect these.

    I have two caveats though:

    • "X-Requested-With" is a standard header and could potentially be sent from full blown webpages/browsers from desktops. (For example this is used to detect ajax calls with these values "X-Requested-With XMLHttpRequest")
    • Most google play store browsers use webviews to display webpages. Even though these are full blown browsers, they will still send this header. So if your intent is to disable this feature you may want to be careful as you may be disabling peoples default browsers.

提交回复
热议问题