Safari askew

I rolled out a new addition to the Huffduffer home page earlier this week. If you aren’t logged in, everything looks the same as before: under the heading Create a podcast of found sounds, there’s a short list giving the low-down on what you can do:

  1. Find links to audio files on the Web.
  2. Huffduff the links—add them to your podcast.
  3. Subscribe to podcasts of other found sounds.

But if you are logged in, then a different list appears, this one showing the activity since you last logged in:

  1. How much has been huffduffed.
  2. How much huffduffing your collective has done.
  3. How many people have joined.

Programming this was pretty straightforward. Every time a new session is started—either because you log in or because you return to the site with a “remember me” cookie—a timestamp is recorded. I just need to select the activity since the previous timestamp. Easy peasy.

Except it wasn’t working for me.

I went through all the usual debugging procedures, poring over my code, but I couldn’t find anything wrong. Finally, after plenty of observation, I spotted the pattern that was causing the problem. Bizarrely, every time I opened my browser, a new timestamp was being recorded for my Huffduffer account.

Here’s the problem:

  1. I visit Huffduffer a lot.
  2. I use Safari as my web browser.

One of the new features in Safari 4 is the “Top Sites” view:

Thanks to Top Sites, you can enjoy a stunning, at-a-glance preview of your favorite websites without lifting a finger. Safari 4 tracks the sites you browse and ranks your favorites, presenting up to 24 thumbnails on a single page.

It does indeed look very pretty (if not quite stunning). But here’s the kicker:

Wonder which sites have changed since your last visit? Sites with a star in the upper-right corner have new content.

How does Safari know which sites have changed? It effectively “visits” the site, screwing up your stats in the process. If you have a cookie stored for that site, Safari will use it. This has led to some skewing of Stack Overflow’s ranking system. It’s also the root of my problem with Huffduffer.

As far as I can tell, I just have to suck it up. Safari reports the same user-agent string regardless of whether it’s fetching a URL for the Top Sites list or fetching a URL to render for an end user.

Oh, well. At least this is a problem that will only affect people who visit Huffduffer a lot (and use Safari as their browser). The new homepage feature will work just fine for everyone else.

Hmmm… that new version of Camino looks mighty tempting.

Update: Martin Sutherland writes to tell me the results of his research into this:

The user-agent that Safari reports when it performs a Top Sites call to your server is exactly the same as for a normal call, but a Top Sites request does transmit an additional HTTP header as part of the request: “X-Purpose: preview”.

Excellent! I should be able to sniff for that header and, if I find it, not log the timestamp.

Have you published a response to this? :