@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
30 lines (29 loc) • 893 B
JavaScript
export default async function detectDialog(tab, retries, rules) {
let breakEarly = false;
const found = await new Promise(async (resolve) => {
let earlyReturn = false;
await Promise.all(rules.map(async (r, index) => {
try {
if (await r.detectCmp(tab)) {
earlyReturn = true;
resolve(index);
}
}
catch (e) {
breakEarly = true;
}
}));
if (!earlyReturn) {
resolve(-1);
}
});
if (found === -1 && retries > 0 && !breakEarly) {
return new Promise((resolve) => {
setTimeout(async () => {
const result = detectDialog(tab, retries - 1, rules);
resolve(result);
}, 500);
});
}
return found > -1 ? rules[found] : null;
}