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.
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.
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