Jump to content

Browser sniffing: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
See also: +link
No edit summary
Tags: Visual edit Mobile edit Mobile web edit
 
(44 intermediate revisions by 35 users not shown)
Line 1: Line 1:
{{Short description|Website code to determine a user's browser}}
'''Browser sniffing''' (also known as '''browser detection''') is a set of techniques used in [[website]]s and [[web application]]s in order to determine the [[web browser]] a visitor is using, and to serve browser-appropriate content to the visitor. This practice is sometimes utilized to circumvent incompatibilities between browsers due to misinterpretation of [[HTML]], [[Cascading Style Sheets]] (CSS), or the [[Document Object Model]] (DOM). While the [[World Wide Web Consortium]] maintains up-to-date central versions of some of the most important Web standards in the form of recommendations, in practice no software developer has designed a browser which adheres exactly to these standards; implementation of other standards and protocols, such as [[Scalable Vector Graphics|SVG]] and [[XMLHttpRequest]], varies as well. As a result, different browsers display the same page differently, and so browser sniffing was developed to detect the web browser in order to help ensure consistent display of content.
{{More citations needed|date=August 2022}}

'''Browser sniffing''' (also known as '''browser detection''') is a set of techniques used in [[website]]s and [[web application]]s in order to determine the [[web browser]] a visitor is using, and to serve browser-appropriate content to the visitor. It is also used to detect [[mobile browser]]s and send them mobile-optimized websites. This practice is sometimes used to circumvent incompatibilities between browsers due to misinterpretation of [[HTML]], [[Cascading Style Sheets]] (CSS), or the [[Document Object Model]] (DOM). While the World Wide Web Consortium maintains up-to-date central versions of some of the most important Web standards in the form of recommendations, in practice no software developer has designed a browser which adheres exactly to these standards; implementation of other standards and protocols, such as [[Scalable Vector Graphics|SVG]] and [[XMLHttpRequest]], varies as well. As a result, different browsers display the same page differently, and so browser sniffing was developed to detect the web browser in order to help ensure consistent display of content.<ref>{{Cite book |last=Meiert |first=Jens |title=The Web Development Glossary |publisher=Frontend Dogma |date=14 July 2021 |language=en}}</ref>
It's also used to detect [[mobile browser]]s and send them mobile-optimized websites.


==Sniffer methods==
==Sniffer methods==


===Client-side sniffing===
===Client-side sniffing===
Web pages can use programming languages such as JavaScript which are interpreted by the user agent, with results sent to the [[web server]]. For example:
: see also [[User agent#User agent sniffing]]
Web pages can use [[programming language]]s such as [[JavaScript]] which are interpreted by the [[user agent]], with results sent to the [[web server]].
For example:


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
var isIEBrowser = false;
var isIE = (window.ActiveXObject != undefined);
if (window.ActiveXObject) {
isIEBrowser = true;
}

// Or, shorter:
var isIE = (window.ActiveXObject !== undefined);
</syntaxhighlight>
</syntaxhighlight>


This [[code]] is run by the [[client (computing)|client]] computer, and the results are used by other code to make necessary adjustments on client-side. In this example, the client computer is asked to determine whether the browser can use a feature called [[ActiveX]]. Since this feature was [[wiktionary:proprietary|proprietary]] to [[Microsoft]], a positive result will indicate that the client may be running Microsoft's [[Internet Explorer]]. This is no longer a reliable indicator since Microsoft's open-source release of the ActiveX code, however, meaning that it can be used by any browser.
This code is run by the [[client (computing)|client]] computer, and the results are used by other code to make necessary adjustments on client-side. In this example, the client computer is asked to determine whether the browser can use a feature called [[ActiveX]]. Since this feature was proprietary to Microsoft, a positive result will indicate that the client may be running Microsoft's [[Internet Explorer]]. This is no longer a reliable indicator since Microsoft's open-source release of the ActiveX code, however, meaning that it can be used by any browser.


===Standard Browser detection method===
===Standard Browser detection method===
The web server communicates with the client using a [[Protocol (computing)|communication protocol]] known as [[HTTP]], or Hypertext Transfer Protocol, which specifies that the client send the [[Server (computing)|server]] information about the browser being used to view the [[web site]] in a [[user agent]] string.
The web server communicates with the client using a [[Protocol (computing)|communication protocol]] known as [[HTTP]], or Hypertext Transfer Protocol, which specifies that the client send the [[Server (computing)|server]] information about the browser being used to view the website in a [[User-Agent header]].


===Server-side sniffing===
===Server-side sniffing===
Extensive browser techniques enable persistent user tracking even when users try to stay pseudonymous. See [[device fingerprint]] for more details on browser fingerprinting, a relatively new, extensive browser sniffing on steroids technique.
Extensive browser techniques enable persistent user tracking even if users try to stay anonymous. See [[device fingerprint]] for more details on browser fingerprinting.


==Issues and standards==
==Issues and standards==
Many websites use browser sniffing to determine whether a visitor's browser is unable to use certain features (such as [[Javascript]], [[DHTML]], [[ActiveX]], or [[cascading style sheets]]), and display an error page if a certain browser is not used. However, it is virtually impossible to account for the tremendous variety of browsers available to users. Generally, a web designer using browser sniffing to determine what kind of page to present will test for the three or four most popular browsers, and provide content tailored to each of these. If a user is employing a [[user agent]] not tested for, there is no guarantee that a usable page will be served; thus, the user may be forced either to change browsers or to avoid the page. The [[World Wide Web Consortium]], which sets standards for the construction of web pages, recommends that web sites be designed in accordance with its standards, and be arranged to "[[fail gracefully]]" when presented to a browser which cannot deal with a particular standard.
Many websites use browser sniffing to determine whether a visitor's browser is unable to use certain features (such as [[JavaScript]], [[DHTML]], [[ActiveX]], or [[cascading style sheets]]), and display an error page if a certain browser is not used. However, it is virtually impossible to account for the tremendous variety of browsers available to users. Generally, a web designer using browser sniffing to determine what kind of page to present will test for the three or four most popular browsers, and provide content tailored to each of these.<ref>{{Cite web |title=Browser detection using the user agent |url=https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent |access-date=23 August 2022 |website=mdn web docs}}</ref> If a user is employing a [[user agent]] not tested for, there is no guarantee that a usable page will be served; thus, the user may be forced either to change browsers or to avoid the page. The [[World Wide Web Consortium]], which sets standards for the construction of web pages, recommends that web sites be designed in accordance with its standards, and be arranged to "[[fail gracefully]]" when presented to a browser which cannot deal with a particular standard.

Browser sniffing increases maintenance needed. Websites treating some browsers differently should provide an alternative version for other browsers. Use of user agent strings are error-prone because the developer must check for the appropriate part, such as "[[Gecko (software)|Gecko]]" instead of "[[Firefox]]". They must also ensure that future versions are supported. Furthermore, some browsers allow changing the user agent string, making the technique useless.<ref>{{Cite web |last=Ross |first=David E. |date=2012-11-29 |title="Professional" Web Developers |url=http://www.rossde.com/internet/Webdevelopers.html |url-status=dead |archive-url=https://web.archive.org/web/20130731143514/http://www.rossde.com/internet/Webdevelopers.html |archive-date=2013-07-31 |access-date=2024-10-17 |website=}}</ref>


==See also==
==See also==
*[[Computer Programming]]
*[[Computer programming]]
*[[HTTP]]
*[[HTTP]]
*[[Web browser]]
*[[Web browser]]
** [[Document Object Model]]
** [[Feature detection (web development)]] ("Browser sniffing" synonym in some contexts)
** [[Feature detection (web development)]] ("Browser sniffing" synonym in some contexts)
** [[Browser fingerprint]]
** [[Local shared object]]s (LSOs), commonly called Flash cookies (due to their similarities with HTTP cookies).
** [[Document Object Model]]
** A [[zombie cookie]] is any HTTP cookie that is recreated after deletion, such as by [[Evercookie]].
* [[User agent]]
* [[User agent]]
* [[Web standards]]
* [[Web standards]]
* [[Content sniffing]]
* [[Content sniffing]]

==References==
{{Reflist}}


{{DEFAULTSORT:Browser Sniffing}}
{{DEFAULTSORT:Browser Sniffing}}

Latest revision as of 03:54, 22 November 2024

Browser sniffing (also known as browser detection) is a set of techniques used in websites and web applications in order to determine the web browser a visitor is using, and to serve browser-appropriate content to the visitor. It is also used to detect mobile browsers and send them mobile-optimized websites. This practice is sometimes used to circumvent incompatibilities between browsers due to misinterpretation of HTML, Cascading Style Sheets (CSS), or the Document Object Model (DOM). While the World Wide Web Consortium maintains up-to-date central versions of some of the most important Web standards in the form of recommendations, in practice no software developer has designed a browser which adheres exactly to these standards; implementation of other standards and protocols, such as SVG and XMLHttpRequest, varies as well. As a result, different browsers display the same page differently, and so browser sniffing was developed to detect the web browser in order to help ensure consistent display of content.[1]

Sniffer methods

[edit]

Client-side sniffing

[edit]

Web pages can use programming languages such as JavaScript which are interpreted by the user agent, with results sent to the web server. For example:

var isIEBrowser = false;
if (window.ActiveXObject) {
    isIEBrowser = true;
}

// Or, shorter:
var isIE = (window.ActiveXObject !== undefined);

This code is run by the client computer, and the results are used by other code to make necessary adjustments on client-side. In this example, the client computer is asked to determine whether the browser can use a feature called ActiveX. Since this feature was proprietary to Microsoft, a positive result will indicate that the client may be running Microsoft's Internet Explorer. This is no longer a reliable indicator since Microsoft's open-source release of the ActiveX code, however, meaning that it can be used by any browser.

Standard Browser detection method

[edit]

The web server communicates with the client using a communication protocol known as HTTP, or Hypertext Transfer Protocol, which specifies that the client send the server information about the browser being used to view the website in a User-Agent header.

Server-side sniffing

[edit]

Extensive browser techniques enable persistent user tracking even if users try to stay anonymous. See device fingerprint for more details on browser fingerprinting.

Issues and standards

[edit]

Many websites use browser sniffing to determine whether a visitor's browser is unable to use certain features (such as JavaScript, DHTML, ActiveX, or cascading style sheets), and display an error page if a certain browser is not used. However, it is virtually impossible to account for the tremendous variety of browsers available to users. Generally, a web designer using browser sniffing to determine what kind of page to present will test for the three or four most popular browsers, and provide content tailored to each of these.[2] If a user is employing a user agent not tested for, there is no guarantee that a usable page will be served; thus, the user may be forced either to change browsers or to avoid the page. The World Wide Web Consortium, which sets standards for the construction of web pages, recommends that web sites be designed in accordance with its standards, and be arranged to "fail gracefully" when presented to a browser which cannot deal with a particular standard.

Browser sniffing increases maintenance needed. Websites treating some browsers differently should provide an alternative version for other browsers. Use of user agent strings are error-prone because the developer must check for the appropriate part, such as "Gecko" instead of "Firefox". They must also ensure that future versions are supported. Furthermore, some browsers allow changing the user agent string, making the technique useless.[3]

See also

[edit]

References

[edit]
  1. ^ Meiert, Jens (14 July 2021). The Web Development Glossary. Frontend Dogma.
  2. ^ "Browser detection using the user agent". mdn web docs. Retrieved 23 August 2022.
  3. ^ Ross, David E. (2012-11-29). ""Professional" Web Developers". Archived from the original on 2013-07-31. Retrieved 2024-10-17.