04.11.2015 Views

javascript

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: Client Detection<br />

All of these user - agent strings indicate Gecko - based browsers (albeit using different versions).<br />

Oftentimes, looking for a particular browser is not as important as understanding whether it ’ s Gecko -<br />

based. The Mozilla version hasn ’ t changed from 5.0 since the first Gecko - based browser was released,<br />

and it likely won ’ t change again.<br />

WebKit<br />

In 2003, Apple announced that it would release its own web browser, called Safari. The Safari rendering<br />

engine, called WebKit, began as a fork of the KHTML rendering engine used in the Linux - based<br />

Konqueror web browser. A couple of years later, WebKit was split off into its own open - source project,<br />

focusing on development of the rendering engine.<br />

Developers of this new browser and rendering engine faced a problem similar to that faced by Internet<br />

Explorer 3.0: how do you ensure that the browser isn ’ t locked out of popular sites? The answer is, put<br />

enough information into the user - agent string to convince web sites that the browser is compatible with<br />

another popular browser. This led to a user - agent string with the following format:<br />

Mozilla/5.0 ( Platform ; Encryption ; OS-or-CPU ; Language ) AppleWebKit /<br />

AppleWebKitVersion (KHTML, like Gecko) Safari/ SafariVersion<br />

Here ’ s an example:<br />

Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/124 (KHTML, like Gecko)<br />

Safari/125.1<br />

As you can see, this is another long user - agent string. It takes into account not only the version of the<br />

Apple WebKit but also the Safari version. A point of contention over whether to identify the browser as<br />

Mozilla was resolved rather quickly for compatibility reasons. Now, all WebKit - based browsers identify<br />

themselves as Mozilla 5.0, the same as all Gecko - based browsers. The Safari version has typically been<br />

the build number of the browser, not necessarily a representation of the release version number. So<br />

although Safari 1.25 has the number 125.1 in the user - agent string, there may not always be a one - to - one<br />

match.<br />

The most interesting and controversial part of this user - agent string is the addition of the string<br />

" (KHTML, like Gecko) ” in a pre - 1.0 version of Safari. Apple got a lot of pushback from developers<br />

who saw this as a blatant attempt to trick clients and servers into thinking Safari was actually Gecko (as<br />

if adding Mozilla/5.0 wasn ’ t enough). Apple ’ s response was similar to Microsoft ’ s when the IE user -<br />

agent string came under fire: Safari is compatible with Mozilla, and web sites shouldn ’ t block out Safari<br />

users because they appear to be using an unsupported browser.<br />

Safari ’ s user - agent string was augmented slightly when version 3 was released. The following version<br />

token is now used to identify the actual version of Safari being used:<br />

Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/522.15.5 (KHTML, like<br />

Gecko) Version/3.0.3 Safari/522.15.5<br />

Note that this change was made only to Safari, not to WebKit, so other WebKit - based browsers may not<br />

have this change. Generally speaking, as with Gecko, it ’ s typical to determine that a browser is WebKit -<br />

based rather than trying to identify Safari specifically.<br />

237

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!