Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Brave ad-block does not work when Electron is upgraded to v3.x #155

Open
mailtokartik1 opened this issue Dec 20, 2018 · 0 comments
Open

Comments

@mailtokartik1
Copy link

mailtokartik1 commented Dec 20, 2018

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.
clientPromise.then((client) => {
  const buffer = client.serialize(64);
  return new Promise((resolve, reject) => {
    fs.writeFile(outputPath, buffer, (err) => {
      if (err) {
        reject(err);
      }
      return resolve();
    });
  });
})
.then(() => {
  done();
})
.catch((error) => {
  throw new gulpUtil.PluginError({
    plugin: 'compile-block-ads-list',
    message: error.message + ' ' + error.stack
  });
});
  1. 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);
});
  1. 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 #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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant