Detect Android Webview via RegEx using Javascript or JQuery?

Discussion in 'Programming' started by Kevin, Sep 28, 2017.

  1. Kevin

    Kevin Oooh, something shiny!

    3,203
    912
    +960
    Hopefully one of you guys/gals with stronger RegEx skills can help out with this one......

    Re: https://developer.chrome.com/multidevice/user-agent

    Using the user agent string of the browser, is there of a quick way of detecting that it is an Android Webview? Using the link above Google says that in modern iterations of Android the string should be something like...

    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​

    ... and that webview can be detected by looking for both the presence of Chrome/{ver} and "wv" as part of the device identifier (shown in red above).

    Detecting the Chrome/{rev} should be easy enough but what about detecting the presence of the "wv"?

    Is there a nice little function out there somewhere already (either JS or JQuery or *cough* CFML *cough*) that detects it? I've been searching and finding some stuff for PHP and similar but plain JS. There are plenty of functions out there to detect Android (tablets) or Android Mobile (phones) but they don't go the extra step of also looking for webview.
     
Verification:
Draft saved Draft deleted