Using a "hosts" file to ad-block

One feature still missing from WebPositive is an ad-blocker. Although there are a few caveats and it isn’t exactly straight forward, there is a way to avoid ads. It uses a “hosts” file that redirects traffic from known ad-servers.

  1. Get an ad-blocking hosts file, e.g. Steven Black’s. You may want to update that one regularly.
  2. Unpack the archive and copy the hosts file to /system/settings/network/.
  3. Before starting WebPositive, always start PoorMan (just go with its default settings). It intercepts the redirected traffic, otherwise WebPositive keeps stalling for long periods.

For some reason, some sites don’t like being ad-blocked in this way. Those just never load in WebPositive and leave the page empty. To get them loading, you have to quit WebPositive, rename the hosts file, and restart WebPositive. I can live with that, because I don’t frequent many sites having this problem often.

To make it easier, I created a script “Hosts-are-ON” and put it on the Desktop:


# toggle ad-blocking hosts file

cd /system/settings/network

if [ -e hosts ] ; then
	mv hosts hosts_off
	mv ~/Desktop/Hosts-are-ON ~/Desktop/Hosts-are-OFF
	mv hosts_off hosts
	mv ~/Desktop/Hosts-are-OFF ~/Desktop/Hosts-are-ON

Now a simple double-click on the script renames the hosts file and by renaming the script itself, shows if ad-blocking is turned on or off.

Definitely only a stop-gap solution until WebPositive learns to ad-block itself, and not suited for everyone, but I thought I post about it anyway.


Can you explain why the part concerning Poorman is needed?

The way those “filters” work is by saying the IP of the ad servers is your own machine, so the system sends the requests to your machine instead of to the real servers. Now, if your own machine does not have a web server running, those requests get stuck until a time limit to wait for a response is reached.

Interesting. So different behavior than Windows in that regards at least.
If this is case does Haiku wait too long for a response? I would think that is something that could be altered, because it should know if a certain port is open or not (thinking in netstat terms at least).

I don’t use poorman, but i do use a hosts file

Maybe the Haiku/Web+ behaviour has changed since I wrote that, but back then the delay without a webserver catching those redirects were quite drastic, IIRC.
I’ve been auto-launching Poorman ever since. I copied the Poorman binary and set its flags to “Background app” with the FileType addon, to avoid it clogging the Deskbar…

I think what changed was Stevenblacks’s host list. They no longer designate a “valid” adress like but now use, which is unrouteable and should fail immidiently. This is all Afaik anyhow.

1 Like

Thank you for the tip about poorman, I’ll keep that it mind.

I’m using hblock, but I modified the number of sites that it makes it’s list from, as I found it seemed to bog down WebPositive. StevenBlacks was one of the one’s that I cut. I’ll have to try adding it again, and see what it does.

As an added side bonus, on a fresh install of a development build, using hblock stopped WebPositve from crashing while trying to view the NFL scoreboard on I’ve had problems with WebPositve crashing when viewing some sites, so this helps a lot.

Your link to the hosts file doesn’t work.

I’ve updated the link to the hosts file. Thanks!

1 Like