Distinguish Android Chrome from the stock browser. The product browser user agent contains "Chrome,"

I need to indicate which browser users use for my site. (Edit: users need to add a bookmarklet, which is not possible in the standard Internet browser. I need to know which message to show them.)

EDIT: I do not need to detect any browser. In particular, I need, in this case, to be able to determine if the browser is really a Google Chrome browser .

For at least one smart device, I am having problems with the difference between the Internet browser and Chrome; Both contain the word "Chrome."

Samsung galaxy s5:

Product Browser User Agent:

Mozilla / 5.0 (Linux, Android 4.4.2; ru-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 / Xx" is different, but will it always be?

Edit: I already checked the previous answers as suggested in the comments. They assume that a non-Chrome browser does not contain the word Chrome.

+6
source share
7 answers

So the difference in user agent is:

Version / xx

From https://developer.chrome.com/multidevice/user-agent#webview_user_agent :

"If you are trying to distinguish between WebView and Chrome for Android, you should look for the presence of the Version / XX line in the user-agent line of the WebView."

I believe that the Chrome browser for the web browser may still decide to leave this bit, but if it has one, then at least I know that it is not. Google chrome!

+8
source

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

If you are trying to distinguish between WebView and Chrome for Android, you should look for the version / XX line in the user-agent WebView line.

+3
source

Since I don’t know any glaring differences between the stock browser and chrome, playing “split the difference” with the user agent string, you will find that the version of Chrome declared in the stock browser is pretty true.

While its not the best difference and the brochure browser can always be updated, at least for the moment this might work for you.

... you really did not say how you will use this.

0
source

(I'm not allowed to comment, so I write the answer instead.)

User984003, therefore, if I understand you correctly (from your comment), you want essentially a test to distinguish on mobile devices between stock browsers and the browser set by the user. You want this, because there is a difference between them in accessibility, respectively, of permission to install bookmarklets, right?

Then this question is discussed in this topic: How to determine the Android stock browser (Short and unsatisfactory answer in this topic: "There is no reliable and universal way to detect only exchange browsers.")

In addition, here is some information on how to install booklets on android: http://smallbusiness.chron.com/making-bookmarklets-work-android-50685.html (Maybe these are some alternatives that you don’t know what it does attempts to distinguish browser versions from outdated ones.)

0
source

Read a lot of things, and it seems that they all do little, and it is still a problem to see the difference. I was looking for a network, without a solution.

I went to check it on my own and found this:

Differences between native and Chrome

So, I found out that my own browser (on Samsung S4) was added by SamsungBrowser after "Gecko").

In Chrome, its "like Gecko" Chrome. "

So, right after "Gecko", it's "Chrome."

Perhaps this could do the trick, as Samsung attaches its own string to the user agent.

Is it possible that other devices can cause problems again?

0
source

You can use JavaScript, for example.

var chromeVersion = /^Google/.test(navigator.vendor) && !/ OPR/.test(navigator.userAgent) && /Chrome\/([0-9]+|$)/.exec(navigator.userAgent)[1]; var isChromeWebview = chromeVersion >= 30 && !('chrome' in window); 

window.chrome defined in the Chrome browser (from at least Chrome 10), but it is not defined in Chrome WebView (Chrome was first used for WebView on Android 4.4.x; AOSP was used for WebView for Android 4.3 or less).

I personally will not use this test in production (it will be unreliable for different browsers and versions), but it does what you want if you use it for a purpose that is not critical.

0
source

I would recommend something like this:

 function testForAndroidChrome() { var version = navigator.appVersion; if (version.indexOf('(KHTML, like Gecko) Chrome' != -1) { return true; // it Chrome } else { return false; // it the stock browser } } var myTest = testForAndroidChrome(); // returns true or false 
0
source

Source: https://habr.com/ru/post/972748/


All Articles