Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distinguish Android Chrome from stock browser. Stock browser's user agent contains 'Chrome'

I need to tell what browser the users are using for my website. (edit: Users need to add a bookmarklet, which is not possible on the standard 'internet' browser. I need to know what message to show them.)

EDIT: I don't need to be able to detect any kind of browser. Specifically I need, in this case, to be able to detect whether a browser is truly a Google Chrome browser.

For at least one smart device, I am having trouble telling the difference between the stock 'internet' browser and Chrome; Both contain the word 'Chrome'.

Samsung galaxy s5:

Stock browser user agent:

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

Chrome user agent:

Mozilla/5.0 (Linux; Android 4.4.2; SAMSUNG-SM-G900A Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.128 Mobile Safari/537.36

"Version/X.x" is different, but will that always be the case?

Edit: I did already check for previous answers as suggested in the comments. They assume that the non-Chrome browser does NOT contain the word Chrome.

like image 232
user984003 Avatar asked Jul 24 '14 06:07

user984003


2 Answers

So the difference is this in the user agent:

Version/X.X

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

I suppose a Chrome webview browser can still choose to leave that bit out, but if it DOES have it, then at least I know it isn't true Google Chrome!

like image 69
user984003 Avatar answered Nov 14 '22 21:11

user984003


Please check this link: https://developer.chrome.com/multidevice/user-agent In the last paragraph we find:

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.

like image 21
Alexandre M Avatar answered Nov 14 '22 23:11

Alexandre M