brave/adblock-rust

How do you use this in a project (such as chromium?)

Alleop5 opened this issue · 1 comments

I would like to implement this in regular chromium. How would I implement this in chromium? Sorry, if this isn't the right place. But as this is the project I would like to implement it looked like the right place. I don't care if it the solution is practical. I just want some experience.

@Alleop5 Depending on your goals and ambition, you have a number of options available.

The simplest way is probably to create a WebExtension that uses the adblock-rust JS bindings. This won't require any patching in the Chromium code, although of course you will be limited to the extension APIs exposed by Manifest v3.

If you're comfortable with a little bit of patching, you can build a Manifest v2 extension (the code for all the Mv2 APIs is still available in Chromium). You can lift the restrictions placed on Mv2 extensions, which would allow you to e.g. use the WebRequest API, have unrestricted background scripts, etc. This is probably flexible enough for most use-cases, although we don't necessarily know how long it'll be until Google removes the Mv2 APIs, at which point you'd have to backport and maintain them.

The most powerful option is to build a C++ binding layer to adblock-rust as a static library, and patch Chromium's C++ code to integrate it directly in the network stack, renderer, etc. That provides ultimate flexibility to implement things like CNAME uncloaking which cannot be done using even the Mv2 APIs. The process involves a bit too much to explain in a GitHub issue comment, but suffice to say that this is exactly the approach Brave Browser uses and all the code for it is open-source at brave/brave-core. In particular you'd probably want to take a look at the C++ bindings, and keep in mind the many patches and source overrides used to tie in all the additional code to the Chromium build process (explained here).

You may also consider using brave-core as your starting point, rather than using Chromium directly, since we have all of this and more built-in already. I know of at least two other browsers building on top of Brave.

Hope that helps!