Strange User Agent With Google Chrome - javascript

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

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 an old rendering engine, predecessor of WebKit (was used by Konqueror browser, then forked by Apple to form WebKit)
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.

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.

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.

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.

After trying everything I have finally used : http://www.useragentstring.com/
You can use the above website to get the formatted user agent and OS.
They have api which you can use directly...
hope it helps..!!!

Related

Why is the User-Agent of Opera mini printed strangely on iPad?

I print User-Agent string of Opera mini on iPad using JavaScript like below.
alert(navigator.userAgent);
Result is
Mozilla/5.0 (iPad; CPU OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77
I don't know how can I detect this browser that is Opera Mini.
Why is the User-Agent of Opera mini printed strangely on iPad?
Opera 16 runs with Webkit engine, hence the different user agent.
With Webkit it now support a lot of features the older version (using the Presto engine) didn't.
The reason they changed it, is most like to get by many web servers that will block the older Opera, where they often is spoofing the user agent, and when finding opera mini, block it as being outdated (and note, Microsoft did a similar trick with Windows phone)
...how can I detect this browser that is Opera Mini
Short answer, you can't
Longer answer, there are CSS features like -o-prefocus, media query hacks etc., many of them you can find here: http://browserhacks.com/
The downside with these, when that browser specific property disappears, so will your detection.
Instead, embrace the more future proof way and detect a feature, with e.g. #supports()
At this question there is some more interested reading with how-to using both CSS and script
Instead of using prefixes I want to ask site visitors to upgrade their browser

Internet Explorer ver 11 enterprise mode detection

Recently my team has landed in a weird situation. End of last year we migrated from IE 8 to IE 11. Our application is now designed to work in IE 11 Enterprise mode.
We need to display a javascript alert message to upgrade the Browser if the user is using IE 8. Alert message is successfully displayed to the users who use IE 8. But problem occurs when the alert message is also displayed to the users who are using IE11 in enterprise mode. I know that IE11 Enterprise mode basically emulates IE 8 behavior and that is the reason why our browser detection functionality is failing.
So I wanted to check if someone has implemented this kind of feature where they can successfully detect the IE version even if they are using IE 11 enterprise mode.
All responses are valuable. Appreciate your response !!!
As per MSDN:
As of Internet Explorer 11, the user-agent string has changed
significantly...Sites that rely on the user-agent string should be
updated to modern techniques, such as feature detection, adaptive
layout, and other modern practices.
https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
Although IE11 in EM throws
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; Tablet PC 2.0)
It is not advisable to just look for "MSIE" in the userAgent but rather try:
var isIE11 = !!navigator.userAgent.match(/Trident.*rv[ :]*11\./)
I'm just looking into this myself. I did stumble across this recently - but couldn't get it to work reliably - however the concept of looking for a feature of IE that shouldn't normally be available is sound.
My plan now is to use IETruth to get the version number (it's very good at doing version detection for IE11) and then do something like:
var IE = IeVersion();
if(IE.TrueVersion < 9 && ('spellcheck' in document.createElement('textarea')) {
// must be running in Enterprise mode because spellcheck wasn't introduced until IE10
}
I'll let you know how I get on!
You can use document mode to check for Enterprise mode. Because in EM the document mode is set to IE 5 to IE 8. This check along with your browser check functionality should work.
How to get browser "Document Mode"

Detecting browser versions on recent mobile devices

I have a need to differentiate between the native (Android) browser and Google Chrome on more recent Android devices, but keep running into problems, specifically with more recent Samsung devices (the Galaxy S4, Galaxy S4 mini and Galaxy Mega).
We have some device detection in-house which analyses the user agent sent from the browser to try and determine which browser is being used. Traditionally to detect Chrome, the code would look for either "Chrome" or "CriOS" within the user agent, normally these are present in the last part of the user agent string (according to the Wikipedia article on User agents, this is used to indicate available enhancements).
Up until very recently, this worked without issue*.
On the latest Samsung Galaxy devices (listed above) running Android 4.2.2, the native browser returns "Chrome" in the user agent string. From some brief reading around the subject, this is because the native browser uses Chromium (I'll admit, I didn't understand the differences between Chromium and Chrome until I read around the subject a bit, more info here).
This also invalidates the use of Chrome feature detection suggested here.
The main issue with this is that we're seeing minor rendering differences between the two browsers, which we'd normally handle with browser specific CSS hacks**, which we're now unable to use.
So far, we've only seen this issue on Samsung Galaxy devices, when tested on a Nexus 4 running Android 4.2.2, the native browser does not return Chrome as part of the user agent. It could be that this is a problem very specific to Samsung Galaxy devices running Android 4.2.2, but at this juncture, we don't have a broad enough range of devices to test on.
Does anyone know of any way of reliably differentiating between the two browsers without using either of the two methods above?
*that's without any issues that we've noticed or that have been reported to us.
**yes, I know using hacks isn't the best way of doing things, but when it's that or re-write large chunks of the code, hacks tend to win out.

Directing clients to the correct page to download IE for their OS version

Just build a site and we're having issues with IE7 users. It had nothing to do with my programming, but a site we have to redirect the customers to that does not handle IE7. Problem is that the client base is not overly tech savvy and telling them to update their version of IE requires they understand what version of Windows they're using (XP or Vista) and also whether their version is 32-bit or 64-bit which I'm sure will really scare the users off.
The issue pretty much boils down to needing to find a way to detect what version of Windows they're using (XP or Vista ... Windows 7 won't run IE7) and then find a way to alert them as to whether they're using 32-bit or 64-bit and direct them accordingly.
Not sure if anyone else has come across this problem and curious how they've handled it.
As you want to find the useragent using javascript, use this
var user_agent = navigator.userAgent
The output to the above command on my machine is:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
The UserAgent string in the http header can often be used to determine their OS, Browser, and their architecture (32 vs 64).

jQuery - detecting the operating system and operating system version

I have been writing a userscript for the past few months, for my company, and have just designed the main site for it with installation instructions (our employees are based all around the world and very few have heard of userscripts, let alone used them, so this frontend is meant to cut down the time I spend supporting the script).
What I would like to do is, on the installation page, detect which browser and OS / OS version they're using so that I can highlight the most relevant instructions slightly darker than the rest, or simply not display irrelevant sections.
For example for IE6 you must use Trixie (I believe) to install userscripts, and this is supported on Win XP only. IE7 is supported on Win XP, IE8 is supported on Win XP & Win 7 and IE9 is supported on Win 7 only. For IE7, 8 & 9 I am advising to use IEPro. The difference between Trixie & IEPro is that Trixie requires a file extension of .user.js which must be saved in C:/Program Files/bhelpuri. IEPro, on the other hand, requires the extension to be .ieuser and saves to a different location. For IE specifically, I would like to detect the version and display only the correct link (either .user.js or .ieuser, depending on what plugin they should be using for their current browser) so that they're taken to the correct version of the file for that browser with the correct save path for that OS / OS version. Is this making any sense so far?
Basically my question is, does anyone know of a way to detect the operating system version? I am currently using http://www.stoimen.com/blog/2009/07/04/jquery-os-detection/ but that doesn't give the OS version, only the OS. I have tried looping through all of the variables stored in the navigator object with no success. Any help would be greatly appreciated.
Edit: Thanks to Nates answer, I have put the exact code at http://jsfiddle.net/Mu8r5/1/. I hope this helps someone in the future.
Your best bet is to use the navigator.userAgent property. It will give the windows version number. You can see a table of how the Windows version number map to the OS here:
OSVERSIONINFO
Here is some example detection code:
var os = (function() {
var ua = navigator.userAgent.toLowerCase();
return {
isWin2K: /windows nt 5.0/.test(ua),
isXP: /windows nt 5.1/.test(ua),
isVista: /windows nt 6.0/.test(ua),
isWin7: /windows nt 6.1/.test(ua),
isWin8: /windows nt 6.2/.test(ua),
isWin81: /windows nt 6.3/.test(ua)
};
}());
if(os.isWin7) {
...
}
http://jsfiddle.net/45jEc/
You can use this great javascript library: http://www.visitorjs.com/details It is open-sourced recently
Edit: Actually, it is now renamed to session.js http://github.com/codejoust/session.js and to my knowledge, that is the best you can get.
The Stack Overflow question
Detect exact OS version from browser goes into some interesting detail about getting the OS version from the User-Agent header which I believe contains the same information that can be accessed from JavaScript.

Categories

Resources