47

Navigating to http://whatsmyuseragent.com/ shows me my stock Android browser on my Galaxy Nexus running 4.2.1 has the user agent

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.34 Safari/534.24

There is nothing in this user agent that allows me to uniquely detect that it is a stock Android browser. The Chrome for Android app at least has android in the UA. Is there any way for me to detect the stock Android app?

gsingh2011
  • 11,032
  • 21
  • 93
  • 138
  • 1
    What do you consider "a stock Android browser" to be? Bear in mind that different devices can ship with different browsers pre-installed. – CommonsWare Jan 18 '13 at 17:03
  • 4
    @CommonsWare The default, AOSP web browser that is developed by Google, not any other browser that could be installed by a company before shipping. – gsingh2011 Jan 18 '13 at 17:44
  • This question was also discussed at: http://stackoverflow.com/questions/9286355/how-to-detect-only-the-native-android-browser. – jwmajors81 Oct 14 '13 at 18:20
  • Possible duplicate of [How to detect only the native Android browser](https://stackoverflow.com/questions/9286355/how-to-detect-only-the-native-android-browser) – mcmimik May 31 '19 at 22:42

14 Answers14

27
var navU = navigator.userAgent;

// Android Mobile
var isAndroidMobile = navU.indexOf('Android') > -1 && navU.indexOf('Mozilla/5.0') > -1 && navU.indexOf('AppleWebKit') > -1;

// Apple webkit
var regExAppleWebKit = new RegExp(/AppleWebKit\/([\d.]+)/);
var resultAppleWebKitRegEx = regExAppleWebKit.exec(navU);
var appleWebKitVersion = (resultAppleWebKitRegEx === null ? null : parseFloat(regExAppleWebKit.exec(navU)[1]));

// Chrome
var regExChrome = new RegExp(/Chrome\/([\d.]+)/);
var resultChromeRegEx = regExChrome.exec(navU);
var chromeVersion = (resultChromeRegEx === null ? null : parseFloat(regExChrome.exec(navU)[1]));

// Native Android Browser
var isAndroidBrowser = isAndroidMobile && (appleWebKitVersion !== null && appleWebKitVersion < 537) || (chromeVersion !== null && chromeVersion < 37);
efusien
  • 281
  • 3
  • 5
  • 4
    I abstracted this to `var rxaosp = window.navigator.userAgent.match(/Android.*AppleWebKit\/([\d.]+)/); var isaosp = (rxaosp && rxaosp[1]<537);` – commonpike Apr 29 '14 at 12:37
  • @commonpike What does 'rx' mean? – mikemaccana Jan 09 '15 at 16:59
  • @mikemaccana nothing - its just a variable name signaling it has something to do with regular expressions. looking at it now, i thinks its a bit of a misnomer: both rxaosp and isaosp are booleans. – commonpike Jan 18 '15 at 10:56
  • For those finding this question in the future – this detection script isn't working. Tested on the AOSP browser and Chrome, says both are not AOSP browsers. – scuds Mar 10 '15 at 15:34
  • 1
    @Carlin Please run again your tests with the updated version. – efusien Mar 11 '15 at 18:53
  • @commonpike Maybe you want to turn the updated version to tiny regex. – efusien Mar 11 '15 at 18:53
  • Appears to work as intended now. What did you change? – scuds Mar 11 '15 at 20:33
  • 2
    This code is missing the check for the "Version" as quoted [here](https://developer.chrome.com/multidevice/user-agent#webview_user_agent): "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." I know it says WebView but most of Samsung's phone will have the Version/_x.x_ on it. – Felipe Duarte Mar 11 '15 at 20:57
  • 1
    @Carlin We now check both AppleWebkit version and Chrome Version. – efusien Mar 12 '15 at 21:11
  • @fcduarte, I'm not convined the `Version/_X.X_` heuristic is accurate. I'm testing an HTC One SV with the latest stock browser and it doesn't have a `Version/_X.X_` in the UA: `mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.34 Safari/534.24` – Sam Hasler May 01 '15 at 11:57
  • @efusien AppleWebKit for stock Android Browser in 5.1 API 22 is 537.36 causing this test to fail. Possibly need final test to say appleWebKitVersion < 537.4 or appleWebKitVersion < 538 – zen Mar 02 '16 at 23:06
  • You have to put a parseFloat around the appleWebKitVersion I use parseFloat(appleWebKitVersion) < parseFloat(537.36). I think it has to be && chrome === null because the AndroidStock Browser has no "Chrome" in his uaString. The Samsung Browser has a "Chrome" in his userAgent. But that is a totally other browser. (see here: https://medium.com/samsung-internet-dev/introducing-samsung-internet-for-developers-6c3a3be42f72#.pi697da3p) – fwebdev Nov 04 '16 at 13:51
16

"Android Browser" is the name of a browser. Confusing perhaps, but with a question like this, it shouldn't be. It's the browser that comes with the vast majority of Android devices, and he's obviously not talking about Chrome.

According to http://www.useragentstring.com/ this is the full list of Android Stock Browser strings. I am currently unsure whether there is a better way to select all of them at once, since some will continue to be added, and also which would not accidentally target Chrome on Android. Hopefully someone gives you a better answer as I am curious myself of the best way to go about this.

Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30

Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30

Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9

Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; HTC_IncredibleS_S710e Build/GRJ90) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.3.4; fr-fr; HTC Desire Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile myTouch 3G Slide Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.3.3; zh-tw; HTC_Pyramid Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.3.3; zh-tw; HTC_Pyramid Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari

Mozilla/5.0 (Linux; U; Android 2.3.3; zh-tw; HTC Pyramid Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.3.3; ko-kr; LG-LU3000 Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; HTC_DesireS_S510e Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; HTC_DesireS_S510e Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile

Mozilla/5.0 (Linux; U; Android 2.3.3; de-de; HTC Desire Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.3.3; de-ch; HTC Desire Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.2; fr-lu; HTC Legend Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.2; en-sa; HTC_DesireHD_A9191 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.2.1; fr-fr; HTC_DesireZ_A7272 Build/FRG83D) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.2.1; en-gb; HTC_DesireZ_A7272 Build/FRG83D) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.2.1; de-de; HTC_Wildfire_A3333 Build/FRG83D) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Mozilla/5.0 (Linux; U; Android 2.1-update1; es-mx; SonyEricssonE10a Build/2.0.A.0.504) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17

Mozilla/5.0 (Linux; U; Android 1.6; ar-us; SonyEricssonX10i Build/R2BA026) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1
TelFiRE
  • 347
  • 5
  • 17
  • 1
    Thanks for this, seems to me you can check for presence of 'Android' and abundance of 'Chrome', 'Firefox' and 'Opera'. Not the best solution but should work for majority of cases – Ege Akpinar Jul 16 '13 at 13:20
  • @Ege Akpinar: Android Stock Browser on S4 mini (Android 4.2.2) does contains "Chrome": Mozilla/5.0 (Linux; Android 4.2.2; en-gb; SAMSUNG GT-I9195 Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Version/1.0 Chrome/18.0.1025.308 Mobile Safari.535.19 .. checking the AppleWebKit version being lower than 537 seems to be a better check covering all android versions – Luca Borrione Oct 22 '14 at 10:08
  • 3
    Note in 2015 **most Android devices now ship with Chrome by default** – mikemaccana Jan 09 '15 at 16:58
  • 1
    This list is missing a lot of devices .. There's a better list here: http://www.webapps-online.com/online-tools/user-agent-strings/dv/operatingsystem51850/android – Felipe Duarte Mar 11 '15 at 21:02
14

You can tell the difference between the stock browser and the Chrome browser by looking for "Android" in the useragent, and checking the AppleWebKit/### version number.

The stock Android browser never went above 534, and Chrome is 537 or higher.

var maybeAndroid = navigator.userAgent.indexOf('Android') >= 0;
var webkitVer = parseInt(/WebKit\/([0-9]+)|$/.exec(navigator.appVersion)[1], 10); // also matches AppleWebKit
var isAOSP = maybeAndroid && webkitVer <= 534 && navigator.vendor.indexOf('Google') == 0;

This is 99% reliable, and very useful for an app on Android 4.x using a WebView.

==details (if you want to go into depth!)==

Edit 7: 'AudioNode' in window is probably a safe sniff for AOSP (or old Chrome) versus modern Chrome versions. Try it here. window.AudioNode was introduced as part of WebAudio support in Chrome 29 (and unlikely to be back-ported by manufacturers). Our 4.0.3 phone has Chrome 41 on it, and 'AudioNode' in window returns true for Chrome and false for AOSP. You could also sniff for other features introduced after AOSP finished development -- see this link for other potential features to sniff. Choose a feature introduced before Chrome 42 because Android 4.0 users can't upgrade past that version. As usual with Android, there are sure to be strange edge cases, but that sniff is likely about as good as you can get (especially if combined with checking that WebKit version < 537).

Edit 8:

==WebView on Android==

Checking for <= 534 is a perfect test when using a WebView within an app. The compatibility definition for Android 4.3 (the last Android version to use AOSP for WebView), says the WebView user agent MUST be: "Mozilla/5.0 (Linux; U; Android $(VERSION); $(LOCALE); $(MODEL) Build/$(BUILD)) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30".

The compatibility definition for Android 4.4 (the first Android version to use Chromium for WebView ), says the WebView user agent MUST be: "Mozilla/5.0 (Linux; Android $(VERSION); $(MODEL) Build/$(BUILD); wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 $(CHROMIUM_VER) Mobile Safari/537.36".

Less than Android 4.3 is very similar to the 4.3 definition (always AOSP). Greater than 4.4 is very similar to the 4.4 definition (always Chromium).

==AOSP on Android==

For the browser on the device (not WebView), the user agent is not proscribed by the Compatibility Definition. The actual browser version used varies a lot as documented on quirksmode and as documented for the Samsung browser version.

Edit 4: The recommended solution is to look for Android without Chrome in the user agent as per: https://developer.chrome.com/multidevice/user-agent#webview_user_agent however it may also be necessary to ensure the absence of /Windows Phone/ because Mobile-IE11-8.1-Update also has Android in the UA "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537". Edit 5: https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx shows that IE12 on Windows Phone will still have Android in the user agent.

Edit 3: As commenters have stated, there are devices out there with AOSP and >= 535, but this is the most reliable test I have found (I would love to see something better). You can but try to make sure your code is still functional if the sniff fails, and accept that Android fragmentation means that there will be odd devices that fail. Caveat Emptor. Edit 6: Looking at some data for a specific site about 1% of what look to be AOSP logins have WebKit 537, so although it seems fairly reliable, it definitely isn't 100% reliable.

Edit 2: If you are using a WebView in an App, this detection is useful for Android >= 4.0 && Android < 4.4.4, because WebView component uses AOSP even if Chrome is installed on the device.

Edit 1: Since native android is now "obsolete" it is reasonable to test for it (and use the flag to work around differences that can't be detected using feature detection).

robocat
  • 4,857
  • 40
  • 62
  • 2
    This reports Chrome as the stock browser too – Xander Dec 31 '14 at 19:06
  • Xander. I think you are wrong. I have been using this rule for years in production and it has been reliable (just retested using http://jsbin.com/vayipu on Chrome 39 - works fine). It would be incorrect if you were using an obsolete version of Chrome released 3 years ago (Chrome 12 or older). What is your user-agent? – robocat Jan 01 '15 at 20:36
  • This isn't working. I'm looking at a version of the AOSP browser that reports 537.36. – scuds Mar 10 '15 at 15:36
  • nexus 5 4.4 simulator stock browser UA: Mozilla/5.0 (Linux; Android 5.1; Android SDK built for x86 Build/LKY45) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 – mabeiyi Aug 27 '15 at 00:47
  • @mabeiyi I personally use a Nexus 5: Android 4.4 as standard didn't come with the stock browser, and the Android System Webview used Chrome. AFAIK your example is broken. – robocat Sep 02 '15 at 03:15
  • I looked at some device data I had from January: about 1% of Android AOSP logins (no `Chrome` in the user agent) were using 537 as example: `Mozilla/5.0 (Linux; U; Android 4.4.2; en-gb; TegraNote-P1640 Build/KOT49H) AppleWebKit/537.16 (KHTML, like Gecko) Version/4.0 Safari/537.16` with vendor `Google Inc.` and platform `Linux armv7l`. – robocat Oct 29 '15 at 03:44
4

As of right now there is no true method to detect this. I am currently on Android 4.2.2 stock Galaxy S4 AT&T and the default browser now has Chrome in the user-agent (but still has the TouchWiz issues of position fixed)

Until Samsung can either a) fix touchwiz or b) remove chrome from the ua string, we have no true method of detecting the android default browser. I cannot say if this is the case for all 4.2x + phones but this is a big issue for developing teams requiring manufacture/browser specific queries.

I am apart of an active developing team for mobile-end web-apps and it seems TouchWiz causes a lot of issues for different aspects being developed.

Another issue is there are companies like Dolphin (great browser, terrible UA) which in all these cases would pop back as the default browser since it doesn't provide a "dolphin" string and uses AppleWebKit534x


Also regarding the U in the user-agent string it had nothing to do with what browser. Infact this has to do with the encryption method being used for each browser (usually standard based on location)

"Web browsers created in the United States, such as Netscape Navigator and Internet Explorer, use the letters U, I, and N to specify the encryption strength in the user agent string. Until 1996, when the United States government disallowed encryption with keys longer than 40 bits to be exported, vendors shipped various browser versions with different encryption strengths. "U" stands for "USA" (for the version with 128-bit encryption), "I" stands for "International" — the browser has 40-bit encryption and can be used anywhere in the world — and "N" stands (de facto) for "None" (no encryption).[10] Following the lifting of export restrictions, most vendors supported 256-bit encryption."

Source: http://en.wikipedia.org/wiki/User_agent#Encryption_strength_notations

Cory
  • 41
  • 1
3

efusien's answer (Nov 11 '13 at 20:18) works for me, although a variable hasn't been declared, and a comma was used in one spot instead of a semicolon, which results in a big fail for anyone looking for a copy/paste answer.

The following is what worked for me, including a practical example using an "if it's the native browser" condition:

var navU = navigator.userAgent;
// Android Mobile
var isAndroidMobile = navU.indexOf('Android') > -1 && navU.indexOf('Mozilla/5.0') > -1 && navU.indexOf('AppleWebKit') > -1;
// Android Browser (not Chrome)
var regExAppleWebKit = new RegExp(/AppleWebKit\/([\d.]+)/);
var resultAppleWebKitRegEx = regExAppleWebKit.exec(navU);
var appleWebKitVersion = (resultAppleWebKitRegEx === null ? null : parseFloat(regExAppleWebKit.exec(navU)[1]));
var isAndroidBrowser = isAndroidMobile && appleWebKitVersion !== null && appleWebKitVersion < 537;

$(window).load(function() {
    if (isAndroidBrowser) {
        // It's Android's native browser (and not Chrome), so do something
    }
});
Nick
  • 31
  • 1
2

It looks like the presence of "Linux; U; Android" is a consistent differentiator for the stock browser. Who knows what the "U" means, but I suspect it will be unreliable in the future. Hopefully the browser will either go away or start to play like Chrome when the strings change. Some other strings are below for comparison

Android Chrome: "Mozilla/5.0 (Linux; Android 4.1.2; SAMSUNG-SGH-I727 Build/JZO54K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.94 Mobile Safari/537.36"

Android Firefox: "Mozilla/5.0 (Android; Mobile; rv:23.0) Gecko/23.0 Firefox/23.0"

Android Opera: "Mozilla/5.0 (Linux; Android 4.1.2; SAMSUNG-SGH-I727 Build/JZO54K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.63 Mobile Safari/537.36 OPR/15.0.1162.61541"

Paul Fox
  • 31
  • 1
  • 2
    Linux; U; Android doesn't work any longer. I just tested on an Android Gallaxy S4 and the user string was: Mozilla/5.0 (Linux; Android 4.2.2; en-gb; SAMSUNG GT-I9500 Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Version/1.0 Chrome/18.0.1025.308 Mobile Safari/535.19 Please note that the 'U' is missing – jwmajors81 Oct 14 '13 at 18:13
1

If JavaScript instead of server-side UA sniffing is an option for you, try (!!window.chrome) && (!window.chrome.app). I can't guarantee, however, that this one is "safe", will work "forever", or something like that. Consider it an evil hack to be used for testing purposes only.

Explanation: Chrome (or Chromium?) Browsers (well, the ones I tested here, which were Chrome and Android stock on Cyanogenmod 10) have an object named window.chrome, but on the Android stock browser, the one I tested at least, this object does not have the app property.

Edit: Seems like older Chrome versions will give false positives with this solution. In turn, newer versions of the stock browser will most likely give "false negatives".

depoulo
  • 315
  • 2
  • 9
1

Your'e not getting android in the UA because you're using Desktop View. There's seemingly no way to identify that this is a mobile device in that mode. Once you'll switch to normal view you'll see the right UA.

AsafK
  • 2,901
  • 3
  • 26
  • 35
  • Request Desktop Site can be detected the majority of the time using: `if (('ontouchstart' in document.documentElement) && /^Linux armv/.test(navigator.platform)) {`. False negatives for x86 based Android devices, false negatives for non-touch Android devices (e.g. clamshell), maybe false positive for Linux Chromium on Arm processor with touch support. – robocat Mar 11 '15 at 22:29
1

I think you are searching for this:

Android native browser not updated above version 534.30 so you can filter to the version and Android UA string combination (above we can presume its a Chrome browser)

Here's my sample JavaScript code:

(If you need specific styling I would add a class to the body with the following JS snippet)

var defectAndroid = $window.navigator && $window.navigator.userAgent.indexOf('534.30') > 0 && $window.navigator.userAgent.toLowerCase().match(/android/);

if (defectAndroid) {
   // sample code specific for your Android Stock browser
}

(Some Android devices reporting 'android' that's why we need the lower case conversation)

Peter MK
  • 134
  • 5
1

Samsung Galaxy Note 3 running Android 4.4.2 has the following UA string for the stock 'Internet' browser (not Chrome or any other browser):

Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SM-N900 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36

Samsung Galaxy S5 running Android 4.4.2 has the following UA string for the stock 'Internet' browser (not Chrome or any other browser):

Mozilla/5.0 (Linux; Android 4.4.2; en-gb; SAMSUNG SM-G900H Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.6 Chrome/28.0.1500.94 Mobile Safari/537.36

We cannot only check for AppleWebKit < 537 anymore.

I am currently checking if AppleWebKit < 537 OR Chrome < 29 using user efusien's method.

Ian
  • 31
  • 6
1

Ref from Nick's and efusien's answers. This works for me with Android OS 4.4.2

// Native Android Browser
var navU = navigator.userAgent;
var isAndroidMobile = navU.indexOf('Android') > -1 && navU.indexOf('Mozilla/5.0') > -1 && navU.indexOf('AppleWebKit') > -1;
var regExAppleWebKit = new RegExp(/AppleWebKit\/([\d.]+)/);
var resultAppleWebKitRegEx = regExAppleWebKit.exec(navU);
var appleWebKitVersion = (resultAppleWebKitRegEx === null ? null : parseFloat(regExAppleWebKit.exec(navU)[1]));
var regExChrome = new RegExp(/Chrome\/([\d.]+)/);
var resultChromeRegEx = regExChrome.exec(navU);
var chromeVersion = (resultChromeRegEx === null ? null : parseFloat(regExChrome.exec(navU)[1]));
var isAndroidBrowser = isAndroidMobile && (appleWebKitVersion !== null && appleWebKitVersion >= 537) && (chromeVersion !== null && chromeVersion < 29);

because now on Kitkat, native browser on Android is using WebKit 537.36 same as Chrome when we log userAgent. By checking also chromeVersion < 29 then I can get native browser on Android 4.4.2. (Chrome version on my Samsung S4 now is 40).

See in this link WebKit table on different Android version : http://jimbergman.net/webkit-version-in-android-version/

Prakarangs
  • 49
  • 4
  • This fails to correctly identify the stock browser when Chrome is not in the userAgent string. – Derek Henderson Oct 27 '15 at 12:15
  • 1
    I don't mean to take away your points or claim points for myself, so instead of posting my own answer, change yours to reflect the following and I will take away my downvote and give you an upvote: `isStockBrowser = isAndroidMobile && (appleWebKitVersion !== null && (appleWebKitVersion < 537 || (chromeVersion !== null && chromeVersion < 29)));` – Derek Henderson Oct 27 '15 at 12:47
1

I need to detect Android Stock Browser to add some custom styles because it doesn't seem to handle box-sizing properly. The code I used is based on @Prakarangs answer which was not working for me. (It did not detect the stock browser on a Galaxy Note 2)

var navU = navigator.userAgent;
var isAndroidMobile = navU.indexOf('Android') > -1 && navU.indexOf('Mozilla/5.0') > -1 && navU.indexOf('AppleWebKit') > -1;
var regExAppleWebKit = new RegExp(/AppleWebKit\/([\d.]+)/);
var resultAppleWebKitRegEx = regExAppleWebKit.exec(navU);
var appleWebKitVersion = (resultAppleWebKitRegEx === null ? null : parseFloat(regExAppleWebKit.exec(navU)[1]));
var isAndroidStockBrowser = isAndroidMobile && (appleWebKitVersion !== null && appleWebKitVersion < 535);

Maybe this is helpful for someone else too.

tim-we
  • 949
  • 7
  • 16
1

If you need a regular expression:

/Android[\s|/].+(AppleWebKit|Nokia)(.(?!Chrome|Presto|UCBrowser))+.$/gi
mcmimik
  • 639
  • 7
  • 24
-2

You must remove SamsungBrowser from your regexp.

For SamSungBrowser, you can use SamsungBrowser/([0-9]*.[0-9]*) or Android.*SAMSUNG.*Version/([0-9]*.[0-9]*) for old browser

http://developer.samsung.com/technical-doc/view.do?v=T000000203

cestmoi
  • 1
  • 2