Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect only the native Android browser

Tags:

it's easy to detect the Android device, but I am having trouble detecting ONLY the Android native browser. Problem is the Dolphin browser has an almost identical user-agent string, and I'd like a way to know if they are using the native browser or not..

Is this possible?

like image 943
williamsandonz Avatar asked Feb 15 '12 00:02

williamsandonz


People also ask

What is the native browser on Android?

The default browser on Android is Google Chrome. This uses the Blink layout engine. For AOSP installations without the Google Apps, the default browser is the old "Browser" app that uses Webkit. other third party browsers like Firefox uses Gecko, Opera uses Blink, Dolphin uses Webkit, and there are probably others.

How to determine browser from user agent?

To detect user browser information we use the navigator. userAgent property. And then we match with the browser name to identify the user browser. Now call this JS function on page load, and this will display the user browser name on page load.

What is user agent sniffing?

User-Agent (UA) Sniffing One can derive properties of the client by looking at the User-Agent header in the HTTP request. UA Sniffing usually involves searching for a specific string or pattern in the UA string and basing choices on the result of that search.

How do I find my Chrome user agent?

Google Chrome Chrome's user agent switcher is part of its Developer Tools. Open them by clicking the menu button and selecting More Tools > Developer Tools. You can also use press Ctrl+Shift+I on your keyboard.


1 Answers

you simply need to test a few parts of the user agent string in order to make sure you have the default android browser:

var nua = navigator.userAgent; var is_android = (nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1); 

you can use the following to ensure that you do not match chrome within android, although on a lot of devices now, chrome is being used as the default browser.

var nua = navigator.userAgent; var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1)); 

EDIT: If you want to protect against case sensitivity, you can use the following:

var nua = navigator.userAgent.toLowerCase(); var is_android = ((nua.indexOf('mozilla/5.0') > -1 && nua.indexOf('android ') > -1 && nua.indexOf('applewebkit') > -1) && !(nua.indexOf('chrome') > -1)); 
like image 108
bizzehdee Avatar answered Sep 28 '22 09:09

bizzehdee