Nicer Package Manager

    @cliqz/adblocker-webextension
    TypeScript icon, indicating that this package has built-in type declarations

    1.25.1 • Public • Published

    WebExtenstion Adblocker

    Efficient · Minimal · JavaScript · TypeScript · uBlock Origin- and Easylist-compatible
    Node.js · Puppeteer · Electron · WebExtension

    Github Actions Build Status Github Actions Assets Status Blazing Fast npm version weekly downloads from npm
    code style: prettier Follow Cliqz on Twitter Dependabot License Badge LGTM Badge


    Getting Started

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

    Usage

    For a complete example check-out: @cliqz/adblocker-webextension-example.

    Creating an instance of WebExtensionBlocker and start blocking ads!

    From the background page of your extension:

    import { WebExtensionBlocker } from '@cliqz/adblocker-webextension';
    
    WebExtensionBlocker.fromPrebuiltAdsAndTracking().then((blocker) => {
      blocker.enableBlockingInBrowser(browser);
    });

    On Chromium-based browsers you will need a polyfill such as webextension-polyfill to get this working:

    import { browser } from 'webextension-polyfill-ts';
    import { WebExtensionBlocker } from '@cliqz/adblocker-webextension';
    
    WebExtensionBlocker.fromPrebuiltAdsAndTracking().then((blocker) => {
      blocker.enableBlockingInBrowser(browser);
    });

    You are ready to block ads!

    There are other ways you can create an instance of the blocking engine to start blocking ads.

    If you already have filters locally:

    import { WebExtensionBlocker } from '@cliqz/adblocker-webextension';
    
    const blocker = WebExtensionBlocker.parse(fs.readFileSync('easylist.txt', 'utf-8'));

    Fetching lists from URLs:

    import { WebExtensionBlocker } from '@cliqz/adblocker-webextension';
    
    const blocker = await WebExtensionBlocker.fromLists(fetch, [
      'https://easylist.to/easylist/easylist.txt'
    ]);

    Use ready-made configs to block ads and optionally trackers:

    import { WebExtensionBlocker } from '@cliqz/adblocker-webextension';
    
    let blocker = await WebExtensionBlocker.fromPrebuiltAdsOnly(); // ads only
    blocker = await WebExtensionBlocker.fromPrebuiltAdsAndTracking(); // ads and tracking

    Disabling Blocker in extension

    To stop blocking ads:

    blocker.disableBlockingInBrowser();

    Caching Blocker using Serialization

    To avoid having to create the same instance of WebExtensionBlocker all over again, you can serialize it to a byte-array which you can store on disk for faster loading.

    import { WebExtensionBlocker } from '@cliqz/adblocker-webextension';
    
    WebExtensionBlocker.fromPrebuiltAdsAndTracking().then((blocker) => {
      const buffer = blocker.serialize();
      const restoredBlocker = WebExtensionBlocker.deserialize(buffer);
      // `restoredBlocker` is deep-equal to `blocker`!
    });

    Keywords

    none

    Install

    npm i @cliqz/adblocker-webextension

    DownloadsWeekly Downloads

    635

    Version

    1.25.1

    License

    MPL-2.0

    Unpacked Size

    1.04 MB

    Total Files

    13

    Last publish

    Collaborators

    • chrmod
    • remusao