10. The Filter File

Any web page can be dynamically modified with the filter file. This modification can be removal, or re-writing, of any web page content, including tags and non-visible content. The default filter file is oddly enough default.filter, located in the config directory.

This is potentially a very powerful feature, and requires knowledge of both "regular expression" and HTML in order create custom filters. But, there are a number of useful filters included with Privoxy for many common situations.

The included example file is divided into sections. Each section begins with the FILTER keyword, followed by the identifier for that section, e.g. "FILTER: webbugs". Each section performs a similar type of filtering, such as "html-annoyances".

This file uses regular expressions to alter or remove any string in the target page. The expressions can only operate on one line at a time. Some examples from the included default default.filter:

Stop web pages from displaying annoying messages in the status bar by deleting such references:

 FILTER: html-annoyances

 # New browser windows should be resizeable and have a location and status
 # bar. Make it so.
 #
 s/resizable="?(no|0)"?/resizable=1/ig s/noresize/yesresize/ig
 s/location="?(no|0)"?/location=1/ig s/status="?(no|0)"?/status=1/ig
 s/scrolling="?(no|0|Auto)"?/scrolling=1/ig
 s/menubar="?(no|0)"?/menubar=1/ig 

 # The <BLINK> tag was a crime!
 #
 s*<blink>|</blink>**ig

 # Is this evil? 
 #
 #s/framespacing="?(no|0)"?//ig
 #s/margin(height|width)=[0-9]*//gi
   

Just for kicks, replace any occurrence of "Microsoft" with "MicroSuck", and have a little fun with topical buzzwords:

 FILTER: fun

 s/microsoft(?!.com)/MicroSuck/ig

 # Buzzword Bingo:
 #
 s/industry-leading|cutting-edge|award-winning/<font color=red><b>BINGO!</b></font>/ig
   

Kill those pesky little web-bugs:

 # webbugs: Squish WebBugs (1x1 invisible GIFs used for user tracking)
 FILTER: webbugs

 s/<img\s+[^>]*?(width|height)\s*=\s*['"]?1\D[^>]*?(width|height)\s*=\s*['"]?1(\D[^>]*?)?>/<!-- Squished WebBug -->/sig
   

10.1. The +filter Action

Filters are enabled with the "+filter" action from within one of the actions files. "+filter" requires one parameter, which should match one of the section identifiers in the filter file itself. Example:

  +filter{html-annoyances}

This would activate that particular filter. Similarly, "+filter" can be turned off for selected sites as: "-filter{html-annoyances}". Remember too, all actions are off by default, unless they are explicity enabled in one of the actions files.