@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
53 lines (52 loc) • 1.93 kB
JavaScript
export class ConsentOMaticCMP {
constructor(name, config) {
this.name = name;
this.config = config;
this.methods = new Map();
config.methods.forEach(methodConfig => {
if (methodConfig.action) {
this.methods.set(methodConfig.name, methodConfig.action);
}
});
this.hasSelfTest = this.methods.has("TEST_CONSENT");
}
async detectCmp(tab) {
return (await Promise.all(this.config.detectors.map(detectorConfig => tab.matches(detectorConfig.presentMatcher)))).some(matched => matched);
}
async detectPopup(tab) {
return (await Promise.all(this.config.detectors.map(detectorConfig => tab.matches(detectorConfig.showingMatcher)))).some(matched => matched);
}
async executeAction(tab, method, param) {
if (this.methods.has(method)) {
return tab.executeAction(this.methods.get(method), param);
}
return true;
}
async optOut(tab) {
await this.executeAction(tab, "HIDE_CMP");
await this.executeAction(tab, "OPEN_OPTIONS");
await this.executeAction(tab, "HIDE_CMP");
await this.executeAction(tab, "DO_CONSENT", []);
await this.executeAction(tab, "SAVE_CONSENT");
return true;
}
async optIn(tab) {
await this.executeAction(tab, "HIDE_CMP");
await this.executeAction(tab, "OPEN_OPTIONS");
await this.executeAction(tab, "HIDE_CMP");
await this.executeAction(tab, "DO_CONSENT", ['D', 'A', 'B', 'E', 'F', 'X']);
await this.executeAction(tab, "SAVE_CONSENT");
return true;
}
async openCmp(tab) {
await this.executeAction(tab, "HIDE_CMP");
await this.executeAction(tab, "OPEN_OPTIONS");
return true;
}
test(tab) {
return this.executeAction(tab, "TEST_CONSENT");
}
detectFrame(tab, frame) {
return false;
}
}