Saturday 24 December 2016

User-Agent Header

The user-agent is a line of text for identifying the browser you are using, its version number and some system details such as operating system, its version by the hosting web server. When a browser connects to a website, it will add the user-agent field in HTTP header for all the requests by default. 

You can imagine the user-agent is the way of introducing himself to the hosting web server. Even though the concept sounds very simple, the logic around has grown increasingly complicated over the years.

JS to get the user-agent details of your browser:
javascript:alert(navigator.userAgent)

History of user-agent naming convention


Mosaic is a discontinued early web browser which has been credited for popularizing the world wide web. 


Then came the new browser Mozilla (Mosaic Killer)/Netscape which supports frames and it called itself as Mozilla/1.0(Win3.1). 


User-Agent Sniffing: Since Mosaic doesn't have support for frames, "user agent sniffing" started to sent out frames only to Netscape browsers.


Then came Internet Explorer which has support for frames. In order to get the pages written for netscape browsers, IE called itself as Mozilla/1.22(MSIE 2.0; Windows 95) to declare that they are Mozilla compatible. This shortcut is the starting point for the chaos in user-agent string.


IE overtook Netscape for a while. Then Netscape was reborn as Mozilla with a whole bunch of new functionalities built with the rendering engine Gecko and called itself as Mozilla/5.0 (Windows NT 5.0; en-US; rv:1.1) Gecko/20020826. 


Then Mozilla was renamed as FireFox and called itself as Mozilla/5.0 (Windows; U; Windows NT 5.1; sv-SE; rv:1.7.5) Gecko/20041108 Firefox/1.0.


Then a whole bunch of other browsers were invented, each pretending to be Mozilla and all of them were powered by Gecko. Since Gecko was so powerful it over took IE. So sinffing was reborn to give mordern web code only to Gecko supported browsers. 


And this point, Linux has its own browser Konqueror whose search engine was KHTML which is as good as Gecko but the mordern web code was not given to it. So they pretend to call themselves as Gecko Mozilla/5.0 (compatible; Konqueror/3.2; FreeBSD) (KHTML, like Gecko) which resulted in much more confusion.


Then comes the Opera, they thought users should be give the choice to select the browser they like to impersonate. So depending on the user selection they called themselves as Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.51, or Mozilla/5.0 (Windows NT 6.0; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.51, or Opera/9.51 (Windows NT 5.1; U; en).


Then Apple built Safari with lot more features on top of KHTML and named the rendering engine as WebKit. To get the pages written for KHTML, safari called itself as Mozilla/5.0 (Macintosh; U; PPC Mac OS X; de-de) AppleWebKit/85.7 (KHTML, like Gecko) Safari/85.5. This made the user-agent even messier.


Then IE returned with abunch of upates and called itself as Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) to get the features supported on other browsers.


Then comes the Chrome with Webkit rendering engine, like Safari to get the pages built for Safari it pretended to be Safari. 

Since,

Chrome prentend to be Safari
Safari pretend to be Konqueror
Konqueror pretend to be Firefox
All browsers pretend to be Mozilla

Chrome called itseld as Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36

Which means chrome support features implemented for Mozilla, KHTML, Gecko, Safari


user-agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36



Some random examples of approximating browser from user agent

Safari:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50

Chrome:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36


Internet Explorer:

1) Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)

2) Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko


In the above case: Option 1 is Internet Explorer 9. Option 2 is Internet Explorer 11.


Reference:

 http://www.useragentstring.com/index.php

No comments:

Post a Comment