Adblock Plus and (a little) more

Hit counts for element hiding: coming · 2007-01-11 15:43 by Wladimir Palant

Recently I wrote about a solution I came up with to provide hit counts for element hiding. However, it uses XBL with the consequence that it would not work when JavaScript is disable and it would probably also slow down browsing. And only today I found the solution that should be obvious, without the disadvantages.

The problem with element hiding is that these rule are converted into regular CSS, e.g.:

div.adbanner {
  display: none;
}

This CSS stylesheet is then applied to all documents and we don’t know whether it actually matches any nodes. My idea now is simple: let the nodes that match the rule try to load something, the content policy will be able to catch this request then. So the CSS changes into something like:

div.adbanner {
  display: none;
  background-image: url(data:image/png,Not really an image.
                        Filter matched: ##div.adbanner);
}

So if the content policy gets a request for a URL of this form it will know that this filter had a hit. It will increase the hit count and it will show this filter in the sidebar in red (it would be nice to show something related to the element itself but unfortunately Gecko doesn’t let us know which element it was that triggered a request).

Now how about element hiding respecting whitelisting? The problem is that Gecko doesn’t let us choose which documents we want to apply our filters on. But now it will be at least possible to detect when element hiding has hits in a whitelisted document. Maybe I manage to somehow use this information to deactivate the stylesheet for the document.

Tags:

Comment [6]

  1. SlimShady · 2007-01-11 17:29 · #

    Hi,

    interesting…

    Now how about element hiding respecting whitelisting? The problem is that Gecko doesn’t let us choose which documents we want to apply our filters on. But now it will be at least possible to detect when element hiding has hits in a whitelisted document. Maybe I manage to somehow use this information to deactivate the stylesheet for the document.

    so you can’t match/test the URL/location of the document before applying the stylesheet?

    Reply from Wladimir Palant:

    The problem is that I’m not the one applying this stylesheet. It is done by Gecko and Gecko applies it to all documents no matter what. I studied this code thoroughly but couldn’t find a way to influence it.

  2. IceDogg · 2007-01-12 02:53 · #

    Can’t wait to get my hands on this! :)

  3. Matt Nordhoff (Peng) · 2007-01-12 15:17 · #

    Could a website detect these images being loaded and/or try to load similar images itself to skew the statistics?

    Reply from Wladimir Palant:

    If they try hard enough – probably. That assuming that they know what your filters are because you need to supply an existing filter with the URL. But then again, if they know your filters they might just as well construct elements that match these filters and skew the statistics this way. So we are not opening any new possibilities for manipulation.

  4. Matt Nordhoff (Peng) · 2007-01-14 14:24 · #

    But could we be opening a new possibility for detection?

    Reply from Wladimir Palant:

    Nothing that hasn’t been there already. If the site knows exactly which element we will hide it can test its runtime styles. Right now it will find display:none, after this change it will simply find one more property that we add.

  5. Matt Nordhoff (Peng) · 2007-01-15 03:42 · #

    Okay, then. It’s kind of an ugly solution, but if it won’t hurt performance noticeably and it won’t cause any problems, it sounds great. :)

  6. chewey · 2007-01-15 14:57 · #

    I think it’s a very ingenious idea. This is one of those solutions seeming obvious – afterwards.

    Superb misuse of “data:” URIs ;-)

Commenting is closed for this article.