Filtering HTML code in Adblock Plus · 2008-09-11 18:54 by Wladimir Palant
Henrik Gemal blogged about a new feature in Firefox, extensions can now inspect and modify the response of HTTP requests before it gets to the sender. And the best news is, it is coming to Firefox 3.0.3 as well, so extension developers don’t need to wait a year before this feature can be used. Obviously, Firebug and Firekeeper developers want this — the former to display the response, the latter to prevent a malicious response from ever reaching the sender. However, it could be useful for Adblock Plus as well.
Now that we have a relatively simple and supported way to change the response coming from a server, filtering HTML code in Adblock Plus is worth considering. It could be filter rules like
http://example.com/bad/*.html$filter=/window\.open\(.*?\)/. The filter above would attach only to pages matching
http://example.com/bad/*.html and then remove everything matching the regular expression
However, there are still open questions. One is performance, how much will filtering slow down page load? Probably quite a bit, so the expression before the
$filter part should be as specific as possible to prevent unnecessary filtering of web pages. Then there is a problem that web page content arrives in chunks. How can one apply a regular expression to it? So far I see only one solution: specifying two regular expressions, one of which marks the beginning of text to be removed and one the end of it. And the beginning marker shouldn’t span too much text so that it can always be found by looking at two consecutive chunks.
Then there is the user interface for this feature. Ideally, matching filters should be displayed in the list of blockable items, so that the user can see when something is removed from the current page. But for that it is necessary to associate an HTTP request with a tab (a content window) in Firefox. I know there is a hack to do it but is there a proper way as well? Finally, what kind of help can be offered when such a filter needs to be created? Problem is that the DOM tree of a web page has no connection to its source code, so any selection in a live web page falls flat. Only option that I see right now is displaying the source code (that might already be a problem if it wasn’t cached) and letting the user select markers for beginning and end of the code to remove. At least it should be possible to show a preview.
Any comments, ideas?
Commenting is closed for this article.