Giter Club home page Giter Club logo

adblocker's Introduction

Adblocker

Efficient, pure-Javascript, multi-platform adblocker library, by Cliqz.

Features

  • extremely efficient adblocker (both in memory usage and raw speed)
  • pure JavaScript implementation
  • first-class support for Node.js, WebExtension, Electron and Puppeteer.
  • effectively blocks all types of ads and tracking
  • supports cosmetics and scriptlet injection
  • small and minimal (only 64KB minified and gzipped)
  • support most filters: Easylist and uBlock Origin formats

The library provides all necessary building blocks to create a powerful and efficient content-blocker and gives full flexibility as to which lists should be used and how they should be fetched or updated. Being a pure JavaScript library it does not make any assumption regarding the environment it will run in (apart from the availability of a JavaScript engine) and is trivial to include in any new project. It can also be used as a building block for tooling.

Getting Started

Using @cliqz/adblocker you can start blocking ads in only a few steps. Here is an example to block ads in a WebExtension (compatible with Chrome and Firefox):

Install package: npm install --save @cliqz/adblocker-webextension

Put this in your background code:

import { WebExtensionBlocker } from '@cliqz/adblocker-webextension';

WebExtensionBlocker.fromPrebuiltAdsAndTracking().then((blocker) => {
  blocker.enableBlockingInBrowser();
});

Congratulations, you are now blocking all ads!

For more details, check-out the following specialized guides:

Performance

To make sure content blocking can run at full-speed on a variety of devices (including low-end mobile phones), we built the library with performance in mind from the ground-up. From our recent performance study, we perform consistently better than popular alternatives in terms of: memory consumption, start from cache time, matching speed and size of cache.

Matching speed corresponds to the time it takes to decide if a network request should be blocked or allowed. It needs to be as fast as possible to not induce any significant over-head in the browser:

Memory usage is another very important dimension. Here is the memory used after initialization:

Cache size corresponds to the size in bytes of the Uint8Array returned by engine.serialize():

Another interesting metric is the time it takes to initialize the FiltersEngine instance from its serialized form. It is especially beneficial for mobile phones, because this serialized engine can be created backend-side and distributed through a CDN; which means clients do not have any cost to pay except downloading the file.

Supported Filters

The majority of the common filters are supported out of the box but some rare ones are not. To know more, check the compatibility matrix on the wiki.

Development

This project makes use of lerna and yarn workspaces (which is actually transparently used by lerna behind the scene most of the time). To get started:

  1. fork and clone the repository: git clone [email protected]:<your remote>/adblocker.git
  2. bootstrap: yarn bootrap
  3. build packages: yarn bundle
  4. start working on one of the sub-packages!

In case you have any question, feel free to open an issue or a pull request to get some help!

Who is using it?

This library is the building block technology used to power the adblockers from Ghostery and Cliqz on both desktop and mobile platforms. It is already running in production for millions of users and has been used successfully to satisfy the following use-cases:

  • Mobile-friendly adblocker for Android in multiple setups: react-native, WebExtension, etc. (ghostery and cliqz)
  • Ads and trackers blocker in Electron applications, Puppeteer headless browsers, Cliqz browser, WebExtensions (cliqz, ghostery and standalone)
  • Backend requests processing job in Node.js

The innovative algorithms and architecture designed and implemented in this project have been shown to be among the most efficient ways to implement ad-blockers and have been used in other projects to implement highly performant adblockers such as Brave.

Release Checklist

To publish a new version:

  1. Bump ENGINE_VERSION in engine.ts (to invalidate serialized versions)
  2. Create a new branch (e.g.: release-x.y.z)
  3. Update version using lerna: npx lerna version --no-push --no-changelog --no-git-tag-version x.y.z
  4. Update CHANGELOG.md
  5. Create a release commit (e.g.: "Release vx.y.z")
  6. Create a PR for the release
  7. Merge and create a new Release on GitHub
  8. Publish changes: npx lerna publish from-package

License

Mozilla Public License 2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.