Personal tools

User:Sardisson/Gecko is Gecko

From MozillaWiki

Jump to: navigation, search

a rough draft of some thoughts on what to tell web designers and web application developers about browser sniffing and Gecko browsers

Contents

“Gecko is Gecko” or, A Guide for Web Designers and Web Application Developers who “Must” Sniff User-Agent Strings

Many designers and developers tailor their websites to specific browsers and then use user-agent sniffing to send different bits of code to different browsers. This is a poor practice for a number of reasons:

  • Browsers you’ve never heard of
  • Browsers that get renamed
  • Browsers that switch rendering engines
  • Robots and search engines
  • Web-enabled desktop applications

Developing for Web Standards

In a perfect world, authors would simply write for the web standards and every browser would “just work.” Unfortunately, we live in a world where all browsers have bugs and holes in their standards support (some more than others), and there are significant segments of the world's web users who continue to use older versions of browsers that are even more buggy and have more limited support for web standards than the current generation of browsers.


Pre-Publication Testing against Multiple Rendering Engines

In such a world, the next-best alternative is to test one’s site or applications against as large a number of popular rendering engines as possible, fix bugs in site or application code, and implement work-arounds for common rendering engine bugs—and filing bug reports on the bugs with the rendering engine developers.

“Runtime” Testing for Features

If for some reason this doesn’t work for your site or application—your site can “only” function with a particular user configuration or plug-in, for instance—test the user’s browser at “runtime” to see if it supports the required function or configuration parameters (also called “capability sniffing” or “object detection”).

For example, this ALA article discusses methods of runtime testing of browser features to enable progressive enhancements in web pages.

Modernizr and Detecting HTML5 Features provide sample code and libraries for feature detection for parts of CSS3 and HTML5.

Note: You should never test for the presence or absence of one feature and use the result of that test to deduce a rendering engine (or, worse, browser) and then assume a set of capabilities/supported features based on your knowledge of the browser/rendering engine. (This is little more than user-agent browser sniffing in sheep’s clothing, and it is susceptible to breakage when browsers add, change or remove features.) Instead, you should always test for the presence of specific features you want to use; if they are present in a user’s browser, then you can use them.[1],[2]

User-Agent Sniffing

Finally, if the only solution available to you is sniffing the user-agent string and sending different codepaths to different “browsers,” you should sniff by rendering engine name and version, not by the user-agent (browser) using the engine.

Note that some web browsers have switched rendering engines over the course of their lifetimes (Epiphany switched from Gecko to WebKit, iCab switched from the “iCab 3” engine to WebKit) or support multiple rendering engines (Netscape 8, versions of Epiphany just prior to the switch to WebKit), so sniffing for browser name could cause you to use the wrong codepath or would require you to write extra code to differentiate between versions; all of these troubles can be avoided by sniffing for rendering engine instead when you must sniff.

About Gecko

For Mozilla-based browsers, the rendering engine is Gecko, and “Gecko is Gecko”. Drivers, the group overseeing the Mozilla project, have taken a strong, clear stance that all Gecko-based browsers must support the same web technologies (fn a list of these?) in content area (regardless of whatever user interface or application features distinguish these applications in the mind of end-users).

For a given Gecko version (the rv: value part of a Mozilla-based browser’s user-agent string), all browsers have the same capabilities, support the same technologies, and have the same bugs in the content area. Given identical fonts and settings (and with the exception of form widgets and scrollbars, which adhere to the style of the operating system), all Gecko browsers sharing a Gecko major version (1.8.1, 1.9.0, 1.9.1, etc.) should render a given page identically (if you find this is not the case, this is a serious bug and should be filed in Bugzilla).

Thus authors should sniff—if sniffing is absolutely required—for Gecko and a particular Gecko version instead of the application name.

Sniffing for “Firefox” : Bad

For example, many sites currently sniff for “Firefox” (or perhaps “Firefox/1.0.x” or “Firefox/1.5.0.x”) and send those user-agents code tailored to Gecko’s capabilites and bugs (or Gecko 1.7.x’s or Gecko 1.8.0.x’s) and ignore other Gecko-based browsers, perhaps sending them code “tailored” for unknown user-agents, perhaps lumping other current Gecko browsers with archaic Netscape releases, or, in extreme cases denying entry, sending unstyled content, or the like. (Since spring 2006, sniffing for “Firefox” no longer detects development versions of Firefox, which are branded differently and have user-agent strings to match this branding.)

Sniffing for "Gecko/" : Good

Instead, with absolutely no additional work on the part of the author, the site could work correctly on dozens of other Gecko-based browsers on multiple operating systems and hardware configurations: Camino, Epiphany, Fennec (Mobile Firefox), Flock, Galeon, K-Meleon, SeaMonkey, Netscape Navigator 9, Maemo Browser, and others (as well as Mozilla 1.7.x and Netscape 8, for Gecko 1.7.x).

Given that Safari has a "like Gecko)" in its UserAgent string, you should look for "Gecko/". Do NOT look for "Gecko/20", because the date string may be changed to a version string later, e.g. "Gecko/2.1" or "Gecko/3.0".

So: Check for "Gecko/".

(also Gecko/XULRunner apps that aren’t primarily browsers, like NNW and friends are with WebKit, or site-specific browsers [Prism])

(this is a good thing)

(something about how the rv: compatibility works: 1.7.x, 1.8.0.x, 1.8.1.x, 1.9.x, with aN, bN, and pre)

(nelsonb suggested we show some Gecko UA strings and highlight the common parts)

(similar applies to WebKit on the Mac: Safari, OmniWeb, Shiira, Sunrise Browser, "utilities" like Paparazzi and NNW..., Nokia's S60 browser, Swift on Windows, Unity on Linux, Epiphany; and perhaps WinIE & derivatives?)

Sample Method of Sniffing for Gecko

getGeckoRv(); if you must restrict access based on Gecko version [bclary.com]


(add links as appropriate)

References