llelectronics / webcat

WebCat is a Webkit based webbrowser for sailfish os
19 stars 13 forks source link

Adblocker support #4

Closed ghost closed 9 years ago

ghost commented 10 years ago

Some websites have so much advertises that it's hard to find the actual content. It would be very nice to have an adblocker in the browser.

llelectronics commented 10 years ago

I add it to the todo list though this one might be very hard.

jklingen commented 10 years ago

I suggest to implement a blacklist-mode blocking mechanism, this should be easier to implement and is fair towards publishers of free and/or open source content/services/software who handle advertising in a fair way. (Many of them are running only on advertising and donations.)

I don't know about webcat internals but I could imagine something like

  1. user selects an option "hide ads on this domain"
  2. display a list of external references (img, script, iframe) found in the page markup, like "http://pagead2.googlesyndication.com/pagead/show_ads.js"
  3. user selects list item to either block it directly or derive a block pattern from it, e.g. "http://pagead2.googlesyndication.com/*"
  4. store block pattern together with current domain name
  5. before rendering next page from the domain find & replace all occurrences of block patterns defined for this domain name.
sandsmark commented 9 years ago

I'd just borrow the adblocking from arora (formerly known as the qwebkit demo browser): https://github.com/icefox/arora/tree/master/src/adblock

it is pretty straightforward, and uses the normal adblock style files.

I'll see if I find time for implementing this myself.

Dax89 commented 9 years ago

Today I have made this script: https://github.com/Dax89/harbour-webpirate/blob/master/qml/js/helpers/AdBlock.js

Tecnically it isn't an AdBlocking system but a simple blacklist one, it's still in its infancy, but it blocks some unwanted ads, currently the rules are hardcoded.

It's sufficient to call __wp_adblock__.blockAds() (you can change the prefix, if you want :P) when the page is loaded and the ads will be hidden, the commented code contains an object that allows to intercept Ajax requests done by the webpage, but it is untested.

llelectronics commented 9 years ago

Thx I will take a look at it. Main problem I see currently is the scalability. So the bigger the adblocking lists are the more ram the browser needs and the slower it will get. Maybe taking the lighter approach only blocking some ads (most of the annoying ones) is better here. Let's see :)

Dax89 commented 9 years ago

I agree with you! It's not possible to make a full fledged AdBlock without using a lot of ram.

The filters should be less as possible and they should detect the most common/annoying (as you said) ads

llelectronics commented 9 years ago

Thx Dax89. Due to your excellent work I was also able to ad a simple adblocker to webcat. I added some more default rules to block some nasty ads I encountered on some sites.

Dax89 commented 9 years ago

If you don't want to hardcode the rules, there is also the editor :)

C++ Side: https://github.com/Dax89/harbour-webpirate/tree/master/src/adblock

Qml Side: https://github.com/Dax89/harbour-webpirate/tree/master/qml/pages/adblock

llelectronics commented 9 years ago

Thanks again will take a look at it and maybe implement it. I rather want to keep this feature as simple and basic as possible though as I know from experience if you give users the chance to edit those filters they will add a whole lot of that with the potential to make the browser slow as hell :)