@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
59 lines (51 loc) • 2.1 kB
text/typescript
import AutoConsentBase from './base';
import { TabActor } from '../types';
export default class Cookiebot extends AutoConsentBase {
constructor() {
super('Cybotcookiebot');
}
async detectCmp(tab: TabActor) {
try {
return await tab.eval('typeof window.CookieConsent === "object"');
} catch (e) {
return false;
}
}
detectPopup(tab: TabActor) {
return tab.elementExists('#CybotCookiebotDialog,#dtcookie-container,#cookiebanner');
}
async optOut(tab: TabActor) {
if (await tab.elementExists('#dtcookie-container')) {
return tab.clickElement('.h-dtcookie-decline');
}
if (await tab.elementExists('.cookiebot__button--settings')) {
await tab.clickElement('.cookiebot__button--settings');
}
if (await tab.elementsAreVisible('#CybotCookiebotDialogBodyButtonDecline', 'all')) {
return await tab.clickElement('#CybotCookiebotDialogBodyButtonDecline');
}
await tab.clickElements('.CybotCookiebotDialogBodyLevelButton:checked:enabled,input[id*="CybotCookiebotDialogBodyLevelButton"]:checked:enabled');
if (await tab.elementExists('#CybotCookiebotDialogBodyButtonDecline')) {
await tab.clickElement('#CybotCookiebotDialogBodyButtonDecline');
}
await tab.clickElements('#CybotCookiebotDialogBodyLevelButtonAccept,#CybotCookiebotDialogBodyButtonAccept');
// await tab.clickElement('#CybotCookiebotDialogBodyButtonAccept');
return true;
}
async optIn(tab: TabActor) {
if (await tab.elementExists('#dtcookie-container')) {
return tab.clickElement('.h-dtcookie-accept');
}
await tab.clickElements('.CybotCookiebotDialogBodyLevelButton:not(:checked):enabled');
await tab.clickElement('#CybotCookiebotDialogBodyLevelButtonAccept');
await tab.clickElement('#CybotCookiebotDialogBodyButtonAccept');
return true;
}
async openCmp(tab: TabActor) {
await tab.eval('CookieConsent.renew() || true');
return tab.waitForElement('#CybotCookiebotDialog', 10000);
}
async test(tab: TabActor) {
return tab.eval('CookieConsent.declined === true');
}
}