Detect inside Android Browser or WebView

Viewed 32273

How can Javascript detect whether a website is loaded in Android's stock browser or loaded in a WebView of another app? I would like to run slightly different code in these two cases.

3 Answers

In the newer versions of WebView, Lollipop and above, you can differentiate the WebView by looking for the wv field in user agent string:

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

https://developer.chrome.com/multidevice/user-agent#webview_user_agent

Related