How to use @cliqz/adblocker-puppeteer - 6 common examples

To help you get started, we’ve selected a few @cliqz/adblocker-puppeteer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microlinkhq / browserless / packages / goto / scripts / postinstall.js View on Github external
const main = async () => {
  // create a ad-blocker engine
  const engine = await PuppeteerBlocker.fromLists(fetch, fullLists)
  await writeFile(OUTPUT_FILENAME, engine.serialize())
}
github microlinkhq / browserless / packages / goto / src / index.js View on Github external
'use strict'

const { PuppeteerBlocker } = require('@cliqz/adblocker-puppeteer')
const debug = require('debug-logfmt')('browserless:goto')
const createDevices = require('@browserless/devices')
const { getDomain } = require('tldts')
const pReflect = require('p-reflect')
const pTimeout = require('p-timeout')
const path = require('path')
const fs = require('fs')

const engine = PuppeteerBlocker.deserialize(
  new Uint8Array(fs.readFileSync(path.resolve(__dirname, './engine.bin')))
)

engine.on('request-blocked', ({ url }) => debug('adblock:block', url))
engine.on('request-redirected', ({ url }) => debug('adblock:redirect', url))

const isEmpty = val => val == null || !(Object.keys(val) || val).length

const parseCookies = (url, str) => {
  const domain = `.${getDomain(url)}`
  return str.split(';').reduce((acc, str) => {
    const [name, value] = str.split('=')
    const cookie = {
      name: name.trim(),
      value,
      domain,
github cliqz-oss / adblocker / packages / adblocker-puppeteer-example / index.ts View on Github external
(async () => {
  const blocker = await PuppeteerBlocker.fromLists(fetch, fullLists, {
    enableCompression: true,
  });
  const browser = await puppeteer.launch({
    defaultViewport: null,
    headless: false,
  });

  const page = await browser.newPage();
  await blocker.enableBlockingInPage(page);

  blocker.on('request-blocked', (request: Request) => {
    console.log('blocked', request.url);
  });

  blocker.on('request-redirected', (request: Request) => {
    console.log('redirected', request.url);
github berstend / puppeteer-extra / packages / puppeteer-extra-plugin-adblocker / src / index.ts View on Github external
private async loadFromCache(): Promise<PuppeteerBlocker> {
    if (!this.opts.useCache) {
      throw new Error('caching disabled')
    }
    this.debug('load from cache', this.engineCacheFile)
    return PuppeteerBlocker.deserialize(
      new Uint8Array(await fs.readFile(this.engineCacheFile))
    )
  }
github berstend / puppeteer-extra / packages / puppeteer-extra-plugin-adblocker / src / index.ts View on Github external
private async loadFromRemote(): Promise<PuppeteerBlocker> {
    this.debug('load from remote', { blockTrackers: this.opts.blockTrackers })
    if (this.opts.blockTrackers === true) {
      return PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch)
    } else {
      return PuppeteerBlocker.fromPrebuiltAdsOnly(fetch)
    }
  }
github berstend / puppeteer-extra / packages / puppeteer-extra-plugin-adblocker / src / index.ts View on Github external
private async loadFromRemote(): Promise<PuppeteerBlocker> {
    this.debug('load from remote', { blockTrackers: this.opts.blockTrackers })
    if (this.opts.blockTrackers === true) {
      return PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch)
    } else {
      return PuppeteerBlocker.fromPrebuiltAdsOnly(fetch)
    }
  }

@cliqz/adblocker-puppeteer

Cliqz adblocker Puppeteer wrapper

MPL-2.0
Latest version published 3 months ago

Package Health Score

84 / 100
Full package analysis

Similar packages