You can use the following to detect mobile devices devices:
// detect browser
var android = navigator.userAgent.match(/Android/i) != null; // Check if using Android
var iPad = navigator.userAgent.match(/iPad/i) != null; // Check if using an iPad
var iPhone = navigator.userAgent.match(/iPhone/i) != null; // Check if using an iPhone
Detecting Webviews inside apps is much harder as those are not really distinguished from normal browser views.
From Google Dev docs you can check for Version/_X.X_
:
If you’re attempting to differentiate between the WebView and Chrome
for Android, you should look for the presence of the Version/X.X
string in the WebView user-agent string. Don’t rely on the specific
Chrome version number (for example, 30.0.0.0) as the version numbers
changes with each release.
https://developer.chrome.com/multidevice/user-agent#webview_user_agent
And then this posts answer gives good info on detecting for iOS
detect ipad/iphone webview via javascript
Something like this comment: https://stackoverflow.com/a/10170885/5234751
var is_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent);
var is_safari_or_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent);