This is an ad-blocker for WebKit2 based browsers.
This extension will block all "bad requests" towards blocked domains or matching "bad url fragments".
Create a file with domains or subdomains you want to block and put it in ~/.config/wk_adblock/hosts.txt
.
An example:
very-bad.domain.com
something-bad.other-domain.com
Every request going to these domains or any subdomain (ie: to really.very-bad.domain.com
) will be blocked.
Create a file with url fragments you want to block and put it in ~/.config/wk_adblock/fragments.txt
.
An example:
-fb-pixel-
-coin-hive.js
Every request matching these substrings (ie: to http://good.com/some-fb-pixel-ad.png
) will be blocked.
WebKit2 does not expose a direct way to block requests, see here. You need to build a WebExtension shared object, which webkit can be instructed to load at runtime and that WebExtension can process / reject requests.
This crate implements the necessary bits to reject "bad" requests
Copy-pasted everything from
- https://blogs.igalia.com/carlosgc/2013/09/10/webkit2gtk-web-process-extensions/
- https://github.com/aperezdc/webkit2gtk-python-webextension-example/blob/master/browse-with-extension
sudo apt install llvm clang libwebkit2gtk-4.0 pkg-config libglib2.0-dev
cargo build --release
- https://users.rust-lang.org/t/what-is-the-difference-between-dylib-and-cdylib/28847
- https://docs.rust-embedded.org/book/interoperability/rust-with-c.html
- https://doc.rust-lang.org/std/ffi/struct.CString.html
- https://webkitgtk.org/reference/webkit2gtk/stable/WebKitURIRequest.html
- Generating the bindings from C to rust
- pkg-config at build time
Randomly clicking on pages for a while, the average time to decide whether or not a page was an ad was ~30µs.