Flock is a browser with some unique capabilities, but that also means it has some unique problems to solve as far as browsers go. Core to the Flock experience is the tight integration we provide with various online services — including social, media, blog and bookmarking services.

Many of these services have APIs that we call in order to perform certain tasks, but there are some things we must do without API support… some tasks that require us to examine the actual HTML content of the pages the user is loading up and look for certain patterns. We need to be able to detect when a user logs in to (or out of) a supported service, for example, since some integration features will only work when the user is logged-in. We also need to detect when there are “media streams” available from a given page so that we can allow the user to open them in the media bar.

How do we know if a user is logged in to Service X? Well generally speaking, if you’re logged in to a service then there’s a button or link on the page to allow you to log out. Spotting that button or link is a great clue for the browser to know you’re logged in. If we’re lucky, the button has an id that makes it especially easy to spot, for instance: id=”logoutButton”.

But the thing about web services is that they’re likely to change their HTML at some point. Since that “logoutButton” isn’t part of a published API, there’s nothing to stop Service X from changing it to a link, and perhaps dropping the id attribute. This is a problem for Flock, since it would break our integration. We would no longer be able to detect that the user had logged in to the service, and some Flock functionality would be broken or disabled as a result.

To combat this problem, we have developed a technology called Web Detective. Web Detective lets us specify detection “rules” in an updateable XML file for each service. So if ServiceX ever changes their HTML and breaks Flock’s integration, we can just update the serviceX.xml file and within a few hours Flock users will be running with the new rules and all will be good with the world again.

Here’s documentation on Web Detective and how to understand and write the rules files:

Ideally, the services we support would never change the IDs of key HTML elements (like the example “logoutButton” above), so that Flock’s integration would never break. It’s not really reasonable to expect services to keep the same HTML forever, however. The best case scenario would be if all supported services provided META tags in their HTML HEAD sections on every document. For example:

<meta name=”session-loggedin” content=”y” />
<meta name=”session-userid” content=”JoeUser23″ />

The first tag, “session-loggedin”, would simply have a content of “y” if the user was currently logged in and “n” otherwise. The second tag need only be present if the user is logged in, and would have as content the unique user ID of the logged-in user. For some services this is the same as the username or email addy used to log in, but other services use a separate unique identifier.

If all services supported something along those lines, it would be easy for us to detect and it wouldn’t have to be in danger of breaking when they changed the visual HTML markup on their pages.

Blogged with Flock