npm install --save @cliqz/adblocker-puppeteer.
For a complete example check-out: @cliqz/adblocker-puppeteer-example.
Creating an instance of
PuppeteerBlocker and start blocking ads!
;;; // required 'fetch'const browser = await puppeteer;const page = await browser;PuppeteerBlocker;
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:
;const blocker = PuppeteerBlocker;
Fetching lists from URLs:
;; // required 'fetch'const blocker = await PuppeteerBlocker;
Use ready-made configs to block ads and optionally trackers:
;; // required 'fetch'let blocker = await PuppeteerBlocker; // ads onlyblocker = await PuppeteerBlocker; // ads and tracking
Disabling Blocker in page
To stop blocking ads in a 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
;;; // required 'fetch'; // used for cachingconst browser = await puppeteer;const page = await browser;PuppeteerBlocker;
Or you can do this manually to control the way caching is done:
;; // required 'fetch'PuppeteerBlocker;