Friday, June 4, 2010

Spoofing Google Chrome

Yes, there are STILL web sites out there that do "browser detection" rather than "feature detection." A good example of this is actually Apple's own HTML5 Showcase, which directs anyone visiting it who isn't already using Apple's "Safari" browser to download it in order to see the content.

Let me go off on an Apple tangent for a moment:

This is blatantly NOT how you are supposed to do detection for support of HTML5 features! They're clearly doing it on purpose to give the (false) impression that ONLY their web browser supports this stuff. If you visit the showcase with Google's Chrome browser you'll still get the "download Safari" message, even though both Safari and Chrome are built atop the same Webkit core. Small point, but Apple also uses a lot of Webkit-specific CSS in their showcase too, when there are perfectly good standards-compliant equivalents available, which means other browsers that DO support HTML5 (like Opera and nightly builds of Firefox) won't render the content correctly because they aren't built on Webkit. C'mon Apple! Don't put up a site that is supposed to showcase HTML5 standards compliance and then use non-compliant CSS!!

Ok, back to Google Chrome:

Because Chrome is the new kid on the block and doesn't support add-ons (yet) you can't easily "spoof" the User Agent for the browser. The "User Agent" is a string that the browser reports to web sites that request it telling the site what kind of browser it is. When you send a user agent string that is different from the actual one, it is called "spoofing." The Opera browser has long had a built-in option to spoof (or they call it "mask") as other browsers, because so few sites are built with Opera in mind if there is any code on the site that requires a specific browser (like Firefox or Internet Explorer) you have to set Opera to lie to the site to get the code to work properly. This was even more of a problem back in the early D0t.Com era when so many sites were designed for either IE or Netscape to the exclusion of each other and everyone else! There are add-ons for Firefox that allow it to masquerade as other browsers - should you stumble across one of these anachronistic web sites. But what about Google Chrome?

Well, there isn't an add-on or a built-in method, but it's still relatively easy to do (Windows instructions):

1. Find the Shortcut to Google Chrome that is most likely on your desktop.
2. Copy the Shortcut and Paste the copy somewhere (like back on the desktop).
3. Right+Click and select "Properties"
4. In the first box named "Target" you'll need to add the following to the line that's already there:

--user-agent="Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_7; en-us) AppleWebKit/533.4 (KHTML, like Gecko) Version/4.1 Safari/533.4"

5. Rename the Shortcut "Chrome as Safari"
6. Use this shortcut to launch Chrome and it will automatically be masquerading as Safari 4.1

Don't believe me? Follow the steps and then go to the Apple HTML5 Showcase mentioned above. You won't get the "Download Safari" message!

You can replace the User Agent string with the string from any other browser, so you could also make shortcuts that launch Google Chrome as Firefox or as Internet Explorer.

No comments: