Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding multiple puppeteer blockers on single page object #4160

Open
teammakdi opened this issue Jul 31, 2024 · 2 comments
Open

Adding multiple puppeteer blockers on single page object #4160

teammakdi opened this issue Jul 31, 2024 · 2 comments

Comments

@teammakdi
Copy link

Does adding multiple puppeteer blockers on single puppeteer page object work

Example both

await PuppeteerBlocker.fromLists(fetch, [
    'https://secure.fanboy.co.nz/fanboy-annoyance.txt'
]).then(async (blocker) => {
    await blocker.enableBlockingInPage(page);
});

await PuppeteerBlocker.fromPrebuiltAdsOnly(fetch).then(async (blocker) => {
    await blocker.enableBlockingInPage(page);
});

Not sure if its similar issue as #4133

@seia-soto
Copy link
Member

Hi @teammakdi ,

We don't support putting multiple blocker instances into the single page. In other words, we don't know about the side-effects of doing so.

Also, the "context" created by "PuppeteerBlocker" for the "page" will be discarded when you bind another blocker to the "page".

Best

@teammakdi
Copy link
Author

teammakdi commented Aug 5, 2024

@seia-soto Now since #4133 has been merged

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

const url = 'https://www.rightmove.co.uk'

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

await page.setViewport({ width: 1080, height: 1024 })

const adsAndTrackingEngine = await PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch);

const cookieEngine = await PuppeteerBlocker.fromLists(fetch, [
  'https://secure.fanboy.co.nz/fanboy-cookiemonster.txt',
  'https://raw.githubusercontent.com/cliqz-oss/adblocker/master/packages/adblocker/assets/easylist/easylist-cookie.txt',
  'https://raw.githubusercontent.com/cliqz-oss/adblocker/master/packages/adblocker/assets/ublock-origin/annoyances-cookies.txt'
])

const mergedEngine = PuppeteerBlocker.merge([adsAndTrackingEngine, cookieEngine]);

await mergedEngine.enableBlockingInPage(page)

await page.goto(url)

await page.screenshot({
  path: 'screenshot.jpg'
})

await browser.close()

should work as expected right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants