views:

55

answers:

4

I was working with some javascript and found a strange user agent with my Google Chrome.

I have Google Chrome 7.0.517.41 beta installed on my Ubuntu Laptop. Now AFAIK my user agent should be something close to Chrome/7.0.517.41

but it is showing me:

Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7

Why is this happening.. I have disabled all the installed extensions but it is still the same..

+1  A: 

User agent strings are like that, as mentioned.

You haven't said that explictly, but if you are planning to use useragent string to detect the user's browser, please use some good code to do that (i.e. don't code it yourself in a hurry, you'll not get it right).

Here is a nice one that I've used a couple times before: Browser detect.

mdrg
Also, don't detect the browser, detect features (unless you *are* actually interested in what the browser is, for keeping statistics). The creeping horror that is `User-Agent` is the direct result of people trying to detect feature capabilities by detecting browser version (in other words, "yeah, check for the word 'Mozilla' to see if we could use feature X" -> everyone now uses the word "Mozilla" in their UA)
Piskvor
+3  A: 

Basically, Mozilla stands for "Mozilla compatible" while "KHTML, like Gecko" describes the rendering engine.

Essentially, Chrome's user agent string is saying "I'm compatible with Mozilla and my rendering engine is like Gecko" as a way of describing itself to developers.

Most (if not every) browser will identify itself as Mozilla-compatible as a kind of legacy thing, regardless of affiliation with the Mozilla foundation. Yes, even Internet Explorer.

More info on strings in general at: Mozilla's developer center.

Also, if you're developing based on user agent strings, don't. You'll only find yourself in a world of hurt: browsers get upgraded to implement features and your user agent sniff might still exclude them, user agent strings can be spoofed, and good old Opera likes to report itself as Internet Explorer in older versions.

Instead, use feature detection to determine if a feature you're trying to use exists for a given browser and then use it or don't.

ajm
+2  A: 

There are historical reasons for browsers "lying" about themselfs. The main reason for this was user agent sniffing. Opera is the only browser which identifies itself as Opera, all other browsers use Mozilla/5.0 or the older ones Mozilla/4.0.

The only thing you should know about this is: User agent strings cannot be trusted, feautre detection is recommended instead.

galambalazs
Opera used to identify itself as Internet Explorer somewhere around version 8 - precisely because there were sites that said "Not IE, the greatest browser *evar*? You're using an old and ugly browser then, go away" - even if the browser was fully capable of working with the site. This sort of rudeness is not so common on modern sites, as the creators know there are multiple browsers beyond the big 2 (IE and FF) - thus, Opera no longer misrepresents itself (by default).
Piskvor
+1 Yep the versions I was referring: FF 1.5+, Safari 2.0+, IE6+, Opera 9.0+
galambalazs
+2  A: 

The UA string tells the long and tragic history of (in)compatibility attempts. See e.g. this for a brief history of the UA. It should also make clear that UA sniffing is useless, as every modern browser pretends to be many other browsers. That is also the case you see here:

  • Mozilla - the most ancient artefact, dating from the early 1990s
  • X11 - the graphical interface used
  • Linux i686 - OS and processor type
  • en_US - your locale (English, United States)
  • AppleWebKit/534.7 - the actual rendering engine
  • (KHTML, like Gecko) - another artifact of browser sniffing: "Gecko" is the FF rendering engine, KHTML is another browser
  • Chrome/7.0.517.41 - the actual browser version
  • Safari/537 - yet another artifact against scripts sniffing for "Safari" (which uses the same engine)

In short: some broken sites assumed that "only allowing people with Mozilla/Firefox/Webkit/whatever" is a sensible policy; in turn, browsers started lying about their origins to get around these artificial barriers. The UA strings are the result: bloatware, full of useless garbage.

Piskvor