We have been using Brave Ad-Block for our web-browser project for a long time. Recently, we upgraded the Electron version in our web browser application to v3.0.0 and observed that ad-block did not work for Electron v3.0.0. I figured there may be some flaw in our implementation for ad-block in our application and proceeded to check the implementation. This post is for all those who may encounter such issues in the future.
The way we have implemented ad-block is follows:
1) We get the easylist.txt file from the server.
2) We serialize it and create a buffer for the easylist.txt during the build.
3) We deserialize the buffer in the start process.
fs.readFile(bufferPath, (err, buffer) => {
if ( err ) {
fail(err);
}
const adBlockClient = new AdBlockClient();
adBlockClient.deserialize(buffer);
done(adBlockClient);
});
4) We create an AdblockClient and match the url, the resource type and domain name to the deserialized buffer.
(client as any).matches(url, mapFilterType[details.resourceType], firstPartyUrl.host)
We had some problems in using ad-block in the past with Electron v2.x hence, we forked ad-block and were currently using v3.1.11. The problem being https://github.com/brave/ad-block/issues/117.
After the update to Electron v3.x, adblock stopped working. After some careful research, found out that the buffer creation and the serialization worked as usual but the deserialize function didn't. The way I solved it is by adding the code of deserialize from v3.1.11 into the forked v4.1.0 and it worked like a charm.
If you have any better solutions, feel free to tell us.
Thank you.
We have been using Brave Ad-Block for our web-browser project for a long time. Recently, we upgraded the Electron version in our web browser application to
v3.0.0
and observed that ad-block did not work for Electronv3.0.0
. I figured there may be some flaw in our implementation for ad-block in our application and proceeded to check the implementation. This post is for all those who may encounter such issues in the future. The way we have implemented ad-block is follows: 1) We get the easylist.txt file from the server. 2) We serialize it and create a buffer for the easylist.txt during the build.3) We deserialize the buffer in the start process.
4) We create an AdblockClient and match the url, the resource type and domain name to the deserialized buffer.
We had some problems in using ad-block in the past with Electron
v2.x
hence, we forked ad-block and were currently usingv3.1.11
. The problem being https://github.com/brave/ad-block/issues/117. After the update to Electronv3.x
, adblock stopped working. After some careful research, found out that the buffer creation and the serialization worked as usual but thedeserialize
function didn't. The way I solved it is by adding the code ofdeserialize
fromv3.1.11
into the forkedv4.1.0
and it worked like a charm. If you have any better solutions, feel free to tell us. Thank you.