UNPKG

@cliqz/autoconsent

Version:

This is a library of rules for navigating through common consent popups on the web. These rules can be run in a Firefox webextension, or in a puppeteer orchestrated headless browser. Using these rules, opt-in and opt-out options can be selected automatica

31 lines (30 loc) 1.08 kB
import Tab from './puppet/tab'; import detectDialog from './detector'; import TabConsent from './tabwrapper'; export * from './index'; export { ConsentOMaticCMP } from './consentomatic/index'; export { Tab, detectDialog, TabConsent, }; export function attachToPage(page, url, rules, retries = 1) { const frames = {}; const tab = new Tab(page, url, frames); frames[0] = page.mainFrame(); async function onFrame(frame) { const allFrames = await page.frames(); allFrames.forEach((frame, frameId) => { const frameMatch = rules.findIndex(r => r.detectFrame(tab, { url: frame.url(), })); if (frameMatch > -1) { tab.frame = { type: rules[frameMatch].name, url: frame.url(), id: frameId, }; frames[frameId] = frame; } }); } page.on('framenavigated', onFrame); page.frames().forEach(onFrame); return new TabConsent(tab, detectDialog(tab, retries, rules)); }