1.34.0 • Published 9 months ago

@cliqz/adblocker-puppeteer v1.34.0

Weekly downloads
9,857
License
MPL-2.0
Repository
github
Last release
9 months ago

Getting Started

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

Usage

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

Creating an instance of PuppeteerBlocker and start blocking ads!

import puppeteer from 'puppeteer';
import { PuppeteerBlocker } from '@cliqz/adblocker-puppeteer';
import fetch from 'cross-fetch'; // required 'fetch'

const browser = await puppeteer.launch();
const page = await browser.newPage();

PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
  blocker.enableBlockingInPage(page);
});

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 { PuppeteerBlocker } from '@cliqz/adblocker-puppeteer';

const blocker = PuppeteerBlocker.parse(fs.readFileSync('easylist.txt', 'utf-8'));

Fetching lists from URLs:

import { PuppeteerBlocker } from '@cliqz/adblocker-puppeteer';
import fetch from 'cross-fetch'; // required 'fetch'

const blocker = await PuppeteerBlocker.fromLists(fetch, [
  'https://easylist.to/easylist/easylist.txt'
]);

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

import { PuppeteerBlocker } from '@cliqz/adblocker-puppeteer';
import fetch from 'cross-fetch'; // required 'fetch'

let blocker = await PuppeteerBlocker.fromPrebuiltAdsOnly(fetch); // ads only
blocker = await PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch); // ads and tracking

Disabling Blocker in page

To stop blocking ads in a page:

await blocker.disableBlockingInPage(page);

Caching Blocker using Serialization

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

import puppeteer from 'puppeteer';
import { PuppeteerBlocker } from '@cliqz/adblocker-puppeteer';
import fetch from 'cross-fetch'; // required 'fetch'
import { promises as fs } from 'fs'; // used for caching

const browser = await puppeteer.launch();
const page = await browser.newPage();

PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch, {
  path: 'engine.bin',
  read: fs.readFile,
  write: fs.writeFile,
}).then((blocker) => {
  blocker.enableBlockingInPage(page);
});

Or you can do this manually to control the way caching is done:

import { PuppeteerBlocker } from '@cliqz/adblocker-puppeteer';
import fetch from 'cross-fetch'; // required 'fetch'

PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
  const buffer = blocker.serialize();
  const restoredBlocker = PuppeteerBlocker.deserialize(buffer);
  // `restoredBlocker` is deep-equal to `blocker`!
});
1.34.0

9 months ago

1.33.1

11 months ago

1.33.2

10 months ago

1.29.0

12 months ago

1.32.0

11 months ago

1.33.0

11 months ago

1.31.3

11 months ago

1.31.4

11 months ago

1.27.6

1 year ago

1.27.7

1 year ago

1.27.4

1 year ago

1.27.5

1 year ago

1.27.8

1 year ago

1.27.9

1 year ago

1.30.0

12 months ago

1.30.1

12 months ago

1.28.1

1 year ago

1.28.2

1 year ago

1.28.0

1 year ago

1.27.11

1 year ago

1.31.1

12 months ago

1.31.2

12 months ago

1.27.10

1 year ago

1.31.0

12 months ago

1.27.3

1 year ago

1.27.2

1 year ago

1.27.1

1 year ago

1.27.0

1 year ago

1.26.16

1 year ago

1.26.15

2 years ago

1.26.14

2 years ago

1.26.13

2 years ago

1.26.7

2 years ago

1.26.8

2 years ago

1.26.9

2 years ago

1.26.11

2 years ago

1.26.10

2 years ago

1.26.12

2 years ago

1.26.6

2 years ago

1.26.3

2 years ago

1.26.4

2 years ago

1.26.5

2 years ago

1.26.2

2 years ago

1.26.1

2 years ago

1.26.0

2 years ago

1.25.2

2 years ago

1.25.0

3 years ago

1.25.1

3 years ago

1.23.9

3 years ago

1.24.0

3 years ago

1.23.8

3 years ago

1.23.7

3 years ago

1.23.2

4 years ago

1.23.3

4 years ago

1.23.6

3 years ago

1.23.4

3 years ago

1.23.5

3 years ago

1.23.1

4 years ago

1.23.0

4 years ago

1.22.7

4 years ago

1.22.6

4 years ago

1.22.5

4 years ago

1.22.4

4 years ago

1.22.3

4 years ago

1.22.2

4 years ago

1.22.0

4 years ago

1.22.1

4 years ago

1.20.5

4 years ago

1.20.6

4 years ago

1.20.4

4 years ago

1.20.3

4 years ago

1.20.2

4 years ago

1.20.1

4 years ago

1.20.0

4 years ago

1.19.0

5 years ago

1.18.8

5 years ago

1.18.7

5 years ago

1.18.6

5 years ago

1.18.5

5 years ago

1.18.4

5 years ago

1.18.3

5 years ago

1.18.2

5 years ago

1.18.1

5 years ago

1.18.0

5 years ago

1.17.0

5 years ago

1.16.1

5 years ago

1.16.0

5 years ago

1.15.1

5 years ago

1.15.0

5 years ago

1.14.4

5 years ago

1.14.3

5 years ago

1.14.2

5 years ago

1.14.1

5 years ago

1.14.0

5 years ago

1.13.1

5 years ago

1.13.0

5 years ago

1.12.3

5 years ago

1.12.2

5 years ago

1.12.1

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.1

5 years ago

1.10.0

5 years ago

1.9.2

5 years ago

1.9.1

5 years ago

1.9.0

5 years ago

1.8.6

5 years ago

1.8.5

5 years ago

1.8.4

5 years ago

1.8.3

5 years ago

1.8.2

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.3

5 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.5.0

6 years ago

1.4.24

6 years ago

1.4.19

6 years ago

1.4.18

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.14.0

6 years ago

0.13.2

6 years ago

0.13.1

6 years ago

0.13.0

6 years ago

0.12.1

6 years ago

0.12.0

6 years ago

0.12.1-alpha.1

6 years ago

0.12.1-alpha.0

6 years ago