@duckduckgo/autoconsent 1.0.7 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +14 -0
- package/.vscode/.idea/.vscode.iml +9 -0
- package/.vscode/.idea/modules.xml +8 -0
- package/.vscode/.idea/workspace.xml +28 -0
- package/.vscode/settings.json +7 -0
- package/Jenkinsfile +68 -39
- package/api.md +104 -0
- package/dist/addon-firefox/background.bundle.js +1 -0
- package/dist/addon-firefox/content.bundle.js +1 -0
- package/dist/addon-firefox/icons/cog.png +0 -0
- package/dist/addon-firefox/icons/cookie-idle.png +0 -0
- package/dist/addon-firefox/icons/cookie.png +0 -0
- package/dist/addon-firefox/icons/party.png +0 -0
- package/dist/addon-firefox/icons/tick.png +0 -0
- package/dist/addon-firefox/icons/verified.png +0 -0
- package/dist/addon-firefox/rules.json +4167 -0
- package/dist/addon-mv3/background.bundle.js +1 -0
- package/dist/addon-mv3/content.bundle.js +1 -0
- package/dist/addon-mv3/icons/cog.png +0 -0
- package/dist/addon-mv3/icons/cookie-idle.png +0 -0
- package/dist/addon-mv3/icons/cookie.png +0 -0
- package/dist/addon-mv3/icons/party.png +0 -0
- package/dist/addon-mv3/icons/tick.png +0 -0
- package/dist/addon-mv3/icons/verified.png +0 -0
- package/dist/addon-mv3/rules.json +4167 -0
- package/dist/autoconsent.cjs.js +1 -1383
- package/dist/autoconsent.esm.js +1 -1375
- package/dist/autoconsent.playwright.js +1 -0
- package/lib/cmps/all.ts +15 -10
- package/lib/cmps/base.ts +95 -90
- package/lib/cmps/consentmanager.ts +31 -19
- package/lib/cmps/consentomatic.ts +89 -0
- package/lib/cmps/cookiebot.ts +62 -53
- package/lib/cmps/evidon.ts +29 -18
- package/lib/cmps/onetrust.ts +32 -20
- package/lib/cmps/sourcepoint-frame.ts +104 -0
- package/lib/cmps/sourcepoint-top.ts +47 -0
- package/lib/cmps/trustarc-frame.ts +115 -0
- package/lib/cmps/trustarc-top.ts +97 -0
- package/lib/consentomatic/index.ts +233 -70
- package/lib/{web/consentomatic → consentomatic}/tools.ts +0 -0
- package/lib/eval-handler.ts +58 -0
- package/lib/index.ts +0 -2
- package/lib/messages.ts +100 -0
- package/lib/rule-executors.ts +108 -0
- package/lib/rules.ts +82 -0
- package/lib/types.ts +35 -0
- package/lib/utils.ts +64 -0
- package/lib/web.ts +288 -74
- package/package.json +20 -16
- package/playwright/content.ts +21 -0
- package/playwright/runner.ts +162 -0
- package/playwright.config.ts +7 -0
- package/readme.md +61 -47
- package/rollup.config.js +30 -16
- package/rules/autoconsent/192.json +17 -0
- package/rules/autoconsent/ausopen.json +8 -0
- package/rules/autoconsent/baden-wuerttemberg-de.json +7 -3
- package/rules/autoconsent/bing.json +14 -0
- package/rules/autoconsent/bundesregierung-de.json +5 -1
- package/rules/autoconsent/cc-banner.json +0 -1
- package/rules/autoconsent/cookie-law-info.json +1 -1
- package/rules/autoconsent/cookie-notice.json +1 -2
- package/rules/autoconsent/cookieconsent.json +5 -6
- package/rules/autoconsent/destatis-de.json +2 -2
- package/rules/autoconsent/dunelm.json +18 -0
- package/rules/autoconsent/etsy.json +4 -3
- package/rules/autoconsent/eu-cookie-compliance.json +0 -1
- package/rules/autoconsent/gov-uk.json +10 -0
- package/rules/autoconsent/hl-co-uk.json +8 -9
- package/rules/autoconsent/johnlewis.json +5 -2
- package/rules/autoconsent/marksandspencer.json +8 -0
- package/rules/autoconsent/mediamarkt-de.json +1 -1
- package/rules/autoconsent/microsoft.json +1 -1
- package/rules/autoconsent/notice-cookie.json +0 -1
- package/rules/autoconsent/osano.json +4 -2
- package/rules/autoconsent/{paypal-de.json → paypal.json} +6 -2
- package/rules/autoconsent/snigel.json +2 -1
- package/rules/autoconsent/tealium.json +4 -5
- package/rules/autoconsent/thefreedictionary.json +1 -1
- package/rules/autoconsent/uswitch.json +8 -0
- package/rules/autoconsent/waitrose.json +28 -0
- package/rules/autoconsent/wetransfer.json +7 -0
- package/rules/rules.json +345 -45
- package/tests/192.spec.ts +7 -0
- package/tests/arzt-auskunft.spec.ts +1 -1
- package/tests/asus.spec.ts +1 -1
- package/tests/ausopen.spec.ts +7 -0
- package/tests/aws.amazon.spec.ts +1 -1
- package/tests/baden-wuerttemberg.spec.ts +1 -1
- package/tests/borlabs.spec.ts +1 -1
- package/tests/bundesregierung.spec.ts +5 -2
- package/tests/ccbanner.spec.ts +1 -1
- package/tests/consentmanager.spec.ts +3 -3
- package/tests/cookiebot.spec.ts +8 -1
- package/tests/cookieconsent.spec.ts +1 -1
- package/tests/cookielawinfo.spec.ts +1 -1
- package/tests/cookienotice.spec.ts +1 -1
- package/tests/corona-in-zahlen.spec.ts +1 -1
- package/tests/deepl.spec.ts +1 -1
- package/tests/destatis.spec.ts +1 -1
- package/tests/didomi.spec.ts +7 -3
- package/tests/drupal.spec.ts +8 -0
- package/tests/dunelm.spec.ts +7 -0
- package/tests/etsy.spec.ts +1 -1
- package/tests/eu-cookie-compliance-banner.spec.ts +1 -1
- package/tests/evidon.spec.ts +7 -2
- package/tests/fundingchoices.spec.ts +2 -1
- package/tests/gov-uk.spec.ts +9 -0
- package/tests/hl-co-uk.spec.ts +1 -1
- package/tests/hubspot.spec.ts +1 -1
- package/tests/ionos.spec.ts +1 -1
- package/tests/johnlewis.spec.ts +2 -2
- package/tests/klaro.spec.ts +1 -1
- package/tests/marksandspencer.spec.ts +7 -0
- package/tests/mediamarkt.spec.ts +1 -1
- package/tests/metoffice-gov-uk.spec.ts +1 -1
- package/tests/microsoft.spec.ts +1 -1
- package/tests/moneysavingexpert.spec.ts +1 -1
- package/tests/motor-talk.spec.ts +1 -1
- package/tests/national-lottery.spec.ts +1 -1
- package/tests/netflix.spec.ts +1 -1
- package/tests/nhs.spec.ts +1 -1
- package/tests/notice-cookie.spec.ts +1 -1
- package/tests/obi.spec.ts +1 -1
- package/tests/oil.spec.ts +2 -2
- package/tests/onetrust.spec.ts +27 -2
- package/tests/osano.spec.ts +1 -1
- package/tests/otto.spec.ts +1 -1
- package/tests/paypal.spec.ts +8 -6
- package/tests/quantcast.spec.ts +5 -2
- package/tests/snigel.spec.ts +1 -1
- package/tests/sourcepoint.spec.ts +8 -8
- package/tests/springer.spec.ts +2 -2
- package/tests/steampowered.spec.ts +1 -1
- package/tests/tealium.spec.ts +1 -1
- package/tests/testcmp.spec.ts +1 -1
- package/tests/thalia.spec.ts +1 -1
- package/tests/thefreedictionary.spec.ts +1 -1
- package/tests/trustarc.spec.ts +26 -3
- package/tests/usercentrics-1.spec.ts +1 -1
- package/tests/uswitch.spec.ts +7 -0
- package/tests/vodafone.spec.ts +1 -1
- package/tests/waitrose.spec.ts +7 -0
- package/tests/wetransfer.spec.ts +7 -0
- package/tests/wordpressgdpr.spec.ts +2 -2
- package/tests/xing.spec.ts +1 -1
- package/tsconfig.json +2 -2
- package/update_version.js +10 -6
- package/.eslintrc +0 -12
- package/cosmetics/rules.json +0 -110
- package/dist/autoconsent.puppet.js +0 -1074
- package/lib/cmps/all.js +0 -19
- package/lib/cmps/base.js +0 -174
- package/lib/cmps/consentmanager.js +0 -31
- package/lib/cmps/cookiebot.js +0 -73
- package/lib/cmps/evidon.js +0 -26
- package/lib/cmps/onetrust.js +0 -34
- package/lib/cmps/sourcepoint.js +0 -82
- package/lib/cmps/sourcepoint.ts +0 -95
- package/lib/cmps/trustarc.js +0 -106
- package/lib/cmps/trustarc.ts +0 -147
- package/lib/config.js +0 -1
- package/lib/consentomatic/index.js +0 -52
- package/lib/detector.js +0 -33
- package/lib/detector.ts +0 -34
- package/lib/hider.js +0 -13
- package/lib/hider.ts +0 -16
- package/lib/index.js +0 -4
- package/lib/messages.d.ts +0 -61
- package/lib/node.js +0 -35
- package/lib/node.ts +0 -43
- package/lib/puppet/tab.js +0 -121
- package/lib/puppet/tab.ts +0 -146
- package/lib/rules.d.ts +0 -80
- package/lib/tabwrapper.js +0 -67
- package/lib/tabwrapper.ts +0 -74
- package/lib/types.d.ts +0 -61
- package/lib/web/consentomatic/index.ts +0 -249
- package/lib/web/content-utils.js +0 -29
- package/lib/web/content-utils.ts +0 -31
- package/lib/web/content.js +0 -89
- package/lib/web/content.ts +0 -80
- package/lib/web/tab.js +0 -112
- package/lib/web/tab.ts +0 -178
- package/lib/web.js +0 -95
- package/tests/runner.ts +0 -61
package/dist/autoconsent.esm.js
CHANGED
|
@@ -1,1375 +1 @@
|
|
|
1
|
-
const enableLogs = false; // change this to enable debug logs
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-restricted-syntax,no-await-in-loop,no-underscore-dangle */
|
|
4
|
-
async function waitFor(predicate, maxTimes, interval) {
|
|
5
|
-
let result = await predicate();
|
|
6
|
-
if (!result && maxTimes > 0) {
|
|
7
|
-
return new Promise((resolve) => {
|
|
8
|
-
setTimeout(async () => {
|
|
9
|
-
resolve(waitFor(predicate, maxTimes - 1, interval));
|
|
10
|
-
}, interval);
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
return Promise.resolve(result);
|
|
14
|
-
}
|
|
15
|
-
async function success(action) {
|
|
16
|
-
const result = await action;
|
|
17
|
-
if (!result) {
|
|
18
|
-
throw new Error(`Action failed: ${action} ${result}`);
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
class AutoConsentBase {
|
|
23
|
-
constructor(name) {
|
|
24
|
-
this.hasSelfTest = true;
|
|
25
|
-
this.name = name;
|
|
26
|
-
}
|
|
27
|
-
detectCmp(tab) {
|
|
28
|
-
throw new Error('Not Implemented');
|
|
29
|
-
}
|
|
30
|
-
async detectPopup(tab) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
detectFrame(tab, frame) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
optOut(tab) {
|
|
37
|
-
throw new Error('Not Implemented');
|
|
38
|
-
}
|
|
39
|
-
optIn(tab) {
|
|
40
|
-
throw new Error('Not Implemented');
|
|
41
|
-
}
|
|
42
|
-
openCmp(tab) {
|
|
43
|
-
throw new Error('Not Implemented');
|
|
44
|
-
}
|
|
45
|
-
async test(tab) {
|
|
46
|
-
// try IAB by default
|
|
47
|
-
return Promise.resolve(true);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function evaluateRule(rule, tab) {
|
|
51
|
-
if (rule.frame && !tab.frame) {
|
|
52
|
-
await waitFor(() => Promise.resolve(!!tab.frame), 10, 500);
|
|
53
|
-
}
|
|
54
|
-
const frameId = rule.frame && tab.frame ? tab.frame.id : undefined;
|
|
55
|
-
const results = [];
|
|
56
|
-
if (rule.exists) {
|
|
57
|
-
results.push(tab.elementExists(rule.exists, frameId));
|
|
58
|
-
}
|
|
59
|
-
if (rule.visible) {
|
|
60
|
-
results.push(tab.elementsAreVisible(rule.visible, rule.check, frameId));
|
|
61
|
-
}
|
|
62
|
-
if (rule.eval) {
|
|
63
|
-
results.push(new Promise(async (resolve) => {
|
|
64
|
-
// catch eval error silently
|
|
65
|
-
try {
|
|
66
|
-
resolve(await tab.eval(rule.eval, frameId));
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
resolve(false);
|
|
70
|
-
}
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
if (rule.waitFor) {
|
|
74
|
-
results.push(tab.waitForElement(rule.waitFor, rule.timeout || 10000, frameId));
|
|
75
|
-
}
|
|
76
|
-
if (rule.click) {
|
|
77
|
-
if (rule.all === true) {
|
|
78
|
-
results.push(tab.clickElements(rule.click, frameId));
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
results.push(tab.clickElement(rule.click, frameId));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (rule.waitForThenClick) {
|
|
85
|
-
results.push(tab.waitForElement(rule.waitForThenClick, rule.timeout || 10000, frameId)
|
|
86
|
-
.then(() => tab.clickElement(rule.waitForThenClick, frameId)));
|
|
87
|
-
}
|
|
88
|
-
if (rule.wait) {
|
|
89
|
-
results.push(tab.wait(rule.wait));
|
|
90
|
-
}
|
|
91
|
-
if (rule.goto) {
|
|
92
|
-
results.push(tab.goto(rule.goto));
|
|
93
|
-
}
|
|
94
|
-
if (rule.hide) {
|
|
95
|
-
results.push(tab.hideElements(rule.hide, frameId));
|
|
96
|
-
}
|
|
97
|
-
if (rule.undoHide) {
|
|
98
|
-
results.push(tab.undoHideElements(frameId));
|
|
99
|
-
}
|
|
100
|
-
if (rule.waitForFrame) {
|
|
101
|
-
results.push(waitFor(() => !!tab.frame, 40, 500));
|
|
102
|
-
}
|
|
103
|
-
// boolean and of results
|
|
104
|
-
return (await Promise.all(results)).reduce((a, b) => a && b, true);
|
|
105
|
-
}
|
|
106
|
-
class AutoConsent extends AutoConsentBase {
|
|
107
|
-
constructor(config) {
|
|
108
|
-
super(config.name);
|
|
109
|
-
this.config = config;
|
|
110
|
-
}
|
|
111
|
-
get prehideSelectors() {
|
|
112
|
-
return this.config.prehideSelectors;
|
|
113
|
-
}
|
|
114
|
-
get isHidingRule() {
|
|
115
|
-
return this.config.isHidingRule;
|
|
116
|
-
}
|
|
117
|
-
async _runRulesParallel(tab, rules) {
|
|
118
|
-
const detections = await Promise.all(rules.map(rule => evaluateRule(rule, tab)));
|
|
119
|
-
return detections.every(r => !!r);
|
|
120
|
-
}
|
|
121
|
-
async _runRulesSequentially(tab, rules) {
|
|
122
|
-
for (const rule of rules) {
|
|
123
|
-
const result = await evaluateRule(rule, tab);
|
|
124
|
-
if (!result && !rule.optional) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
async detectCmp(tab) {
|
|
131
|
-
if (this.config.detectCmp) {
|
|
132
|
-
return this._runRulesParallel(tab, this.config.detectCmp);
|
|
133
|
-
}
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
async detectPopup(tab) {
|
|
137
|
-
if (this.config.detectPopup) {
|
|
138
|
-
return this._runRulesParallel(tab, this.config.detectPopup);
|
|
139
|
-
}
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
detectFrame(tab, frame) {
|
|
143
|
-
if (this.config.frame) {
|
|
144
|
-
return frame.url.startsWith(this.config.frame);
|
|
145
|
-
}
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
async optOut(tab) {
|
|
149
|
-
if (this.config.optOut) {
|
|
150
|
-
return this._runRulesSequentially(tab, this.config.optOut);
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
async optIn(tab) {
|
|
155
|
-
if (this.config.optIn) {
|
|
156
|
-
return this._runRulesSequentially(tab, this.config.optIn);
|
|
157
|
-
}
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
async openCmp(tab) {
|
|
161
|
-
if (this.config.openCmp) {
|
|
162
|
-
return this._runRulesSequentially(tab, this.config.openCmp);
|
|
163
|
-
}
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
async test(tab) {
|
|
167
|
-
if (this.config.test) {
|
|
168
|
-
return this._runRulesSequentially(tab, this.config.test);
|
|
169
|
-
}
|
|
170
|
-
return super.test(tab);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
class TabActions {
|
|
175
|
-
constructor(tabId, frame, sendContentMessage, browser) {
|
|
176
|
-
this.frame = frame;
|
|
177
|
-
this.sendContentMessage = sendContentMessage;
|
|
178
|
-
this.browser = browser;
|
|
179
|
-
this.id = tabId;
|
|
180
|
-
}
|
|
181
|
-
async elementExists(selector, frameId = 0) {
|
|
182
|
-
return this.sendContentMessage(this.id, {
|
|
183
|
-
type: "elemExists",
|
|
184
|
-
selector
|
|
185
|
-
}, {
|
|
186
|
-
frameId
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
async clickElement(selector, frameId = 0) {
|
|
190
|
-
return this.sendContentMessage(this.id, {
|
|
191
|
-
type: "click",
|
|
192
|
-
selector
|
|
193
|
-
}, {
|
|
194
|
-
frameId
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
async clickElements(selector, frameId = 0) {
|
|
198
|
-
return this.sendContentMessage(this.id, {
|
|
199
|
-
type: "click",
|
|
200
|
-
all: true,
|
|
201
|
-
selector
|
|
202
|
-
}, {
|
|
203
|
-
frameId
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
async elementsAreVisible(selector, check, frameId = 0) {
|
|
207
|
-
return this.sendContentMessage(this.id, {
|
|
208
|
-
type: "elemVisible",
|
|
209
|
-
selector,
|
|
210
|
-
check
|
|
211
|
-
}, {
|
|
212
|
-
frameId
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
async getAttribute(selector, attribute, frameId = 0) {
|
|
216
|
-
return this.sendContentMessage(this.id, {
|
|
217
|
-
type: "getAttribute",
|
|
218
|
-
selector,
|
|
219
|
-
attribute
|
|
220
|
-
}, { frameId });
|
|
221
|
-
}
|
|
222
|
-
async eval(script, frameId = 0) {
|
|
223
|
-
// console.log(`run ${script} in tab ${this.id}`);
|
|
224
|
-
return await this.sendContentMessage(this.id, {
|
|
225
|
-
type: "eval",
|
|
226
|
-
script
|
|
227
|
-
}, { frameId });
|
|
228
|
-
}
|
|
229
|
-
async waitForElement(selector, timeout, frameId = 0) {
|
|
230
|
-
const interval = 200;
|
|
231
|
-
const times = Math.ceil(timeout / interval);
|
|
232
|
-
return waitFor(() => this.elementExists(selector, frameId), times, interval);
|
|
233
|
-
}
|
|
234
|
-
async waitForThenClick(selector, timeout, frameId = 0) {
|
|
235
|
-
if (await this.waitForElement(selector, timeout, frameId)) {
|
|
236
|
-
return await this.clickElement(selector, frameId);
|
|
237
|
-
}
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
async hideElements(selectors, frameId = 0, method = 'display') {
|
|
241
|
-
return this.sendContentMessage(this.id, {
|
|
242
|
-
type: "hide",
|
|
243
|
-
selectors,
|
|
244
|
-
method,
|
|
245
|
-
}, { frameId });
|
|
246
|
-
}
|
|
247
|
-
async undoHideElements(frameId = 0) {
|
|
248
|
-
return this.sendContentMessage(this.id, {
|
|
249
|
-
type: "undohide",
|
|
250
|
-
}, { frameId });
|
|
251
|
-
}
|
|
252
|
-
async getBrowserTab() {
|
|
253
|
-
return this.browser.tabs.get(this.id);
|
|
254
|
-
}
|
|
255
|
-
async goto(url) {
|
|
256
|
-
return this.browser.tabs.update(this.id, { url });
|
|
257
|
-
}
|
|
258
|
-
wait(ms) {
|
|
259
|
-
return new Promise(resolve => {
|
|
260
|
-
setTimeout(() => {
|
|
261
|
-
resolve(true);
|
|
262
|
-
}, ms);
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
matches(matcherConfig) {
|
|
266
|
-
return this.sendContentMessage(this.id, {
|
|
267
|
-
type: "matches",
|
|
268
|
-
config: matcherConfig
|
|
269
|
-
}, { frameId: 0 });
|
|
270
|
-
}
|
|
271
|
-
executeAction(config, param) {
|
|
272
|
-
return this.sendContentMessage(this.id, {
|
|
273
|
-
type: "executeAction",
|
|
274
|
-
config,
|
|
275
|
-
param
|
|
276
|
-
}, { frameId: 0 });
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* This code is in most parts copied from https://github.com/cavi-au/Consent-O-Matic/blob/master/Extension/Tools.js
|
|
282
|
-
* which is licened under the MIT.
|
|
283
|
-
*/
|
|
284
|
-
class Tools {
|
|
285
|
-
static setBase(base) {
|
|
286
|
-
Tools.base = base;
|
|
287
|
-
}
|
|
288
|
-
static findElement(options, parent = null, multiple = false) {
|
|
289
|
-
let possibleTargets = null;
|
|
290
|
-
if (parent != null) {
|
|
291
|
-
possibleTargets = Array.from(parent.querySelectorAll(options.selector));
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
if (Tools.base != null) {
|
|
295
|
-
possibleTargets = Array.from(Tools.base.querySelectorAll(options.selector));
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
possibleTargets = Array.from(document.querySelectorAll(options.selector));
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (options.textFilter != null) {
|
|
302
|
-
possibleTargets = possibleTargets.filter(possibleTarget => {
|
|
303
|
-
let textContent = possibleTarget.textContent.toLowerCase();
|
|
304
|
-
if (Array.isArray(options.textFilter)) {
|
|
305
|
-
let foundText = false;
|
|
306
|
-
for (let text of options.textFilter) {
|
|
307
|
-
if (textContent.indexOf(text.toLowerCase()) !== -1) {
|
|
308
|
-
foundText = true;
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return foundText;
|
|
313
|
-
}
|
|
314
|
-
else if (options.textFilter != null) {
|
|
315
|
-
return textContent.indexOf(options.textFilter.toLowerCase()) !== -1;
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
if (options.styleFilters != null) {
|
|
320
|
-
possibleTargets = possibleTargets.filter(possibleTarget => {
|
|
321
|
-
let styles = window.getComputedStyle(possibleTarget);
|
|
322
|
-
let keep = true;
|
|
323
|
-
for (let styleFilter of options.styleFilters) {
|
|
324
|
-
let option = styles[styleFilter.option];
|
|
325
|
-
if (styleFilter.negated) {
|
|
326
|
-
keep = keep && option !== styleFilter.value;
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
keep = keep && option === styleFilter.value;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return keep;
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
if (options.displayFilter != null) {
|
|
336
|
-
possibleTargets = possibleTargets.filter(possibleTarget => {
|
|
337
|
-
if (options.displayFilter) {
|
|
338
|
-
//We should be displayed
|
|
339
|
-
return possibleTarget.offsetHeight !== 0;
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
//We should not be displayed
|
|
343
|
-
return possibleTarget.offsetHeight === 0;
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
if (options.iframeFilter != null) {
|
|
348
|
-
possibleTargets = possibleTargets.filter(possibleTarget => {
|
|
349
|
-
if (options.iframeFilter) {
|
|
350
|
-
//We should be inside an iframe
|
|
351
|
-
return window.location !== window.parent.location;
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
//We should not be inside an iframe
|
|
355
|
-
return window.location === window.parent.location;
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
if (options.childFilter != null) {
|
|
360
|
-
possibleTargets = possibleTargets.filter(possibleTarget => {
|
|
361
|
-
let oldBase = Tools.base;
|
|
362
|
-
Tools.setBase(possibleTarget);
|
|
363
|
-
let childResults = Tools.find(options.childFilter);
|
|
364
|
-
Tools.setBase(oldBase);
|
|
365
|
-
return childResults.target != null;
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
if (multiple) {
|
|
369
|
-
return possibleTargets;
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
if (possibleTargets.length > 1) {
|
|
373
|
-
console.warn("Multiple possible targets: ", possibleTargets, options, parent);
|
|
374
|
-
}
|
|
375
|
-
return possibleTargets[0];
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
static find(options, multiple = false) {
|
|
379
|
-
let results = [];
|
|
380
|
-
if (options.parent != null) {
|
|
381
|
-
let parent = Tools.findElement(options.parent, null, multiple);
|
|
382
|
-
if (parent != null) {
|
|
383
|
-
if (parent instanceof Array) {
|
|
384
|
-
parent.forEach(p => {
|
|
385
|
-
let targets = Tools.findElement(options.target, p, multiple);
|
|
386
|
-
if (targets instanceof Array) {
|
|
387
|
-
targets.forEach(target => {
|
|
388
|
-
results.push({
|
|
389
|
-
parent: p,
|
|
390
|
-
target: target
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
results.push({
|
|
396
|
-
parent: p,
|
|
397
|
-
target: targets
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
return results;
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
let targets = Tools.findElement(options.target, parent, multiple);
|
|
405
|
-
if (targets instanceof Array) {
|
|
406
|
-
targets.forEach(target => {
|
|
407
|
-
results.push({
|
|
408
|
-
parent: parent,
|
|
409
|
-
target: target
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
results.push({
|
|
415
|
-
parent: parent,
|
|
416
|
-
target: targets
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
let targets = Tools.findElement(options.target, null, multiple);
|
|
424
|
-
if (targets instanceof Array) {
|
|
425
|
-
targets.forEach(target => {
|
|
426
|
-
results.push({
|
|
427
|
-
parent: null,
|
|
428
|
-
target: target
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
results.push({
|
|
434
|
-
parent: null,
|
|
435
|
-
target: targets
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
if (results.length === 0) {
|
|
440
|
-
results.push({
|
|
441
|
-
parent: null,
|
|
442
|
-
target: null
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
if (multiple) {
|
|
446
|
-
return results;
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
if (results.length !== 1) {
|
|
450
|
-
console.warn("Multiple results found, even though multiple false", results);
|
|
451
|
-
}
|
|
452
|
-
return results[0];
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
Tools.base = null;
|
|
457
|
-
|
|
458
|
-
function matches(config) {
|
|
459
|
-
const result = Tools.find(config);
|
|
460
|
-
if (config.type === "css") {
|
|
461
|
-
return !!result.target;
|
|
462
|
-
}
|
|
463
|
-
else if (config.type === "checkbox") {
|
|
464
|
-
return !!result.target && result.target.checked;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
async function executeAction(config, param) {
|
|
468
|
-
switch (config.type) {
|
|
469
|
-
case "click":
|
|
470
|
-
return clickAction(config);
|
|
471
|
-
case "list":
|
|
472
|
-
return listAction(config, param);
|
|
473
|
-
case "consent":
|
|
474
|
-
return consentAction(config, param);
|
|
475
|
-
case "ifcss":
|
|
476
|
-
return ifCssAction(config, param);
|
|
477
|
-
case "waitcss":
|
|
478
|
-
return waitCssAction(config);
|
|
479
|
-
case "foreach":
|
|
480
|
-
return forEachAction(config, param);
|
|
481
|
-
case "hide":
|
|
482
|
-
return hideAction(config);
|
|
483
|
-
case "slide":
|
|
484
|
-
return slideAction(config);
|
|
485
|
-
case "close":
|
|
486
|
-
return closeAction();
|
|
487
|
-
case "wait":
|
|
488
|
-
return waitAction(config);
|
|
489
|
-
case "eval":
|
|
490
|
-
return evalAction(config);
|
|
491
|
-
default:
|
|
492
|
-
throw "Unknown action type: " + config.type;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
const STEP_TIMEOUT = 0;
|
|
496
|
-
function waitTimeout(timeout) {
|
|
497
|
-
return new Promise(resolve => {
|
|
498
|
-
setTimeout(() => {
|
|
499
|
-
resolve();
|
|
500
|
-
}, timeout);
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
async function clickAction(config) {
|
|
504
|
-
const result = Tools.find(config);
|
|
505
|
-
if (result.target != null) {
|
|
506
|
-
result.target.click();
|
|
507
|
-
}
|
|
508
|
-
return waitTimeout(STEP_TIMEOUT);
|
|
509
|
-
}
|
|
510
|
-
async function listAction(config, param) {
|
|
511
|
-
for (let action of config.actions) {
|
|
512
|
-
await executeAction(action, param);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
async function consentAction(config, consentTypes) {
|
|
516
|
-
for (const consentConfig of config.consents) {
|
|
517
|
-
const shouldEnable = consentTypes.indexOf(consentConfig.type) !== -1;
|
|
518
|
-
if (consentConfig.matcher && consentConfig.toggleAction) {
|
|
519
|
-
const isEnabled = matches(consentConfig.matcher);
|
|
520
|
-
if (isEnabled !== shouldEnable) {
|
|
521
|
-
await executeAction(consentConfig.toggleAction);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
if (shouldEnable) {
|
|
526
|
-
await executeAction(consentConfig.trueAction);
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
await executeAction(consentConfig.falseAction);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
async function ifCssAction(config, param) {
|
|
535
|
-
const result = Tools.find(config);
|
|
536
|
-
if (!result.target) {
|
|
537
|
-
if (config.trueAction) {
|
|
538
|
-
await executeAction(config.trueAction, param);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
else {
|
|
542
|
-
if (config.falseAction) {
|
|
543
|
-
await executeAction(config.falseAction, param);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
async function waitCssAction(config) {
|
|
548
|
-
await new Promise(resolve => {
|
|
549
|
-
let numRetries = config.retries || 10;
|
|
550
|
-
const waitTime = config.waitTime || 250;
|
|
551
|
-
const checkCss = () => {
|
|
552
|
-
const result = Tools.find(config);
|
|
553
|
-
if ((config.negated && result.target) ||
|
|
554
|
-
(!config.negated && !result.target)) {
|
|
555
|
-
if (numRetries > 0) {
|
|
556
|
-
numRetries -= 1;
|
|
557
|
-
setTimeout(checkCss, waitTime);
|
|
558
|
-
}
|
|
559
|
-
else {
|
|
560
|
-
resolve();
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
else {
|
|
564
|
-
resolve();
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
checkCss();
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
async function forEachAction(config, param) {
|
|
571
|
-
const results = Tools.find(config, true);
|
|
572
|
-
const oldBase = Tools.base;
|
|
573
|
-
for (const result of results) {
|
|
574
|
-
if (result.target) {
|
|
575
|
-
Tools.setBase(result.target);
|
|
576
|
-
await executeAction(config.action, param);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
Tools.setBase(oldBase);
|
|
580
|
-
}
|
|
581
|
-
async function hideAction(config) {
|
|
582
|
-
const result = Tools.find(config);
|
|
583
|
-
if (result.target) {
|
|
584
|
-
result.target.classList.add("Autoconsent-Hidden");
|
|
585
|
-
// result.target.setAttribute("style", "display: none;");
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
async function slideAction(config) {
|
|
589
|
-
const result = Tools.find(config);
|
|
590
|
-
const dragResult = Tools.find(config.dragTarget);
|
|
591
|
-
if (result.target) {
|
|
592
|
-
let targetBounds = result.target.getBoundingClientRect();
|
|
593
|
-
let dragTargetBounds = dragResult.target.getBoundingClientRect();
|
|
594
|
-
let yDiff = dragTargetBounds.top - targetBounds.top;
|
|
595
|
-
let xDiff = dragTargetBounds.left - targetBounds.left;
|
|
596
|
-
if (this.config.axis.toLowerCase() === "y") {
|
|
597
|
-
xDiff = 0;
|
|
598
|
-
}
|
|
599
|
-
if (this.config.axis.toLowerCase() === "x") {
|
|
600
|
-
yDiff = 0;
|
|
601
|
-
}
|
|
602
|
-
let screenX = window.screenX + targetBounds.left + targetBounds.width / 2.0;
|
|
603
|
-
let screenY = window.screenY + targetBounds.top + targetBounds.height / 2.0;
|
|
604
|
-
let clientX = targetBounds.left + targetBounds.width / 2.0;
|
|
605
|
-
let clientY = targetBounds.top + targetBounds.height / 2.0;
|
|
606
|
-
let mouseDown = document.createEvent("MouseEvents");
|
|
607
|
-
mouseDown.initMouseEvent("mousedown", true, true, window, 0, screenX, screenY, clientX, clientY, false, false, false, false, 0, result.target);
|
|
608
|
-
let mouseMove = document.createEvent("MouseEvents");
|
|
609
|
-
mouseMove.initMouseEvent("mousemove", true, true, window, 0, screenX + xDiff, screenY + yDiff, clientX + xDiff, clientY + yDiff, false, false, false, false, 0, result.target);
|
|
610
|
-
let mouseUp = document.createEvent("MouseEvents");
|
|
611
|
-
mouseUp.initMouseEvent("mouseup", true, true, window, 0, screenX + xDiff, screenY + yDiff, clientX + xDiff, clientY + yDiff, false, false, false, false, 0, result.target);
|
|
612
|
-
result.target.dispatchEvent(mouseDown);
|
|
613
|
-
await this.waitTimeout(10);
|
|
614
|
-
result.target.dispatchEvent(mouseMove);
|
|
615
|
-
await this.waitTimeout(10);
|
|
616
|
-
result.target.dispatchEvent(mouseUp);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
async function waitAction(config) {
|
|
620
|
-
await waitTimeout(config.waitTime);
|
|
621
|
-
}
|
|
622
|
-
async function closeAction(config) {
|
|
623
|
-
window.close();
|
|
624
|
-
}
|
|
625
|
-
async function evalAction(config) {
|
|
626
|
-
console.log("eval!", config.code);
|
|
627
|
-
return new Promise(resolve => {
|
|
628
|
-
try {
|
|
629
|
-
if (config.async) {
|
|
630
|
-
window.eval(config.code);
|
|
631
|
-
setTimeout(() => {
|
|
632
|
-
resolve(window.eval("window.__consentCheckResult"));
|
|
633
|
-
}, config.timeout || 250);
|
|
634
|
-
}
|
|
635
|
-
else {
|
|
636
|
-
resolve(window.eval(config.code));
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
catch (e) {
|
|
640
|
-
console.warn("eval error", e, config.code);
|
|
641
|
-
resolve(false);
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
// get or create a style container for CSS overrides
|
|
647
|
-
function getStyleElementUtil() {
|
|
648
|
-
const styleOverrideElementId = "autoconsent-css-rules";
|
|
649
|
-
const styleSelector = `style#${styleOverrideElementId}`;
|
|
650
|
-
const existingElement = document.querySelector(styleSelector);
|
|
651
|
-
if (existingElement && existingElement instanceof HTMLStyleElement) {
|
|
652
|
-
return existingElement;
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
const parent = document.head ||
|
|
656
|
-
document.getElementsByTagName("head")[0] ||
|
|
657
|
-
document.documentElement;
|
|
658
|
-
const css = document.createElement("style");
|
|
659
|
-
css.id = styleOverrideElementId;
|
|
660
|
-
parent.appendChild(css);
|
|
661
|
-
return css;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
// hide elements with a CSS rule
|
|
665
|
-
function hideElementsUtil(selectors, method) {
|
|
666
|
-
const hidingSnippet = method === 'display' ? `display: none` : `opacity: 0`;
|
|
667
|
-
const rule = `${selectors.join(",")} { ${hidingSnippet} !important; z-index: -1 !important; pointer-events: none !important; } `;
|
|
668
|
-
const styleEl = getStyleElementUtil();
|
|
669
|
-
if (styleEl instanceof HTMLStyleElement) {
|
|
670
|
-
styleEl.innerText += rule;
|
|
671
|
-
return selectors.length > 0;
|
|
672
|
-
}
|
|
673
|
-
return false;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
let actionQueue = Promise.resolve(null);
|
|
677
|
-
function handleMessage(message, debug = false) {
|
|
678
|
-
if (message.type === "click") {
|
|
679
|
-
const elem = document.querySelectorAll(message.selector);
|
|
680
|
-
debug && console.log("[click]", message.selector, elem);
|
|
681
|
-
if (elem.length > 0) {
|
|
682
|
-
if (message.all === true) {
|
|
683
|
-
elem.forEach(e => e.click());
|
|
684
|
-
}
|
|
685
|
-
else {
|
|
686
|
-
elem[0].click();
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
return elem.length > 0;
|
|
690
|
-
}
|
|
691
|
-
else if (message.type === "elemExists") {
|
|
692
|
-
const exists = document.querySelector(message.selector) !== null;
|
|
693
|
-
debug && console.log("[exists?]", message.selector, exists);
|
|
694
|
-
return exists;
|
|
695
|
-
}
|
|
696
|
-
else if (message.type === "elemVisible") {
|
|
697
|
-
const elem = document.querySelectorAll(message.selector);
|
|
698
|
-
const results = new Array(elem.length);
|
|
699
|
-
elem.forEach((e, i) => {
|
|
700
|
-
// check for display: none
|
|
701
|
-
results[i] = false;
|
|
702
|
-
if (e.offsetParent !== null) {
|
|
703
|
-
results[i] = true;
|
|
704
|
-
}
|
|
705
|
-
else {
|
|
706
|
-
const css = window.getComputedStyle(e);
|
|
707
|
-
if (css.position === 'fixed' && css.display !== "none") { // fixed elements may be visible even if the parent is not
|
|
708
|
-
results[i] = true;
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
});
|
|
712
|
-
debug && console.log("[visible?]", message.selector, elem, results);
|
|
713
|
-
if (results.length === 0) {
|
|
714
|
-
return false;
|
|
715
|
-
}
|
|
716
|
-
else if (message.check === "any") {
|
|
717
|
-
return results.some(r => r);
|
|
718
|
-
}
|
|
719
|
-
else if (message.check === "none") {
|
|
720
|
-
return results.every(r => !r);
|
|
721
|
-
}
|
|
722
|
-
// all
|
|
723
|
-
return results.every(r => r);
|
|
724
|
-
}
|
|
725
|
-
else if (message.type === "getAttribute") {
|
|
726
|
-
const elem = document.querySelector(message.selector);
|
|
727
|
-
debug && console.log("[getAttribute]", message.selector, elem);
|
|
728
|
-
if (!elem) {
|
|
729
|
-
return false;
|
|
730
|
-
}
|
|
731
|
-
return elem.getAttribute(message.attribute);
|
|
732
|
-
}
|
|
733
|
-
else if (message.type === "eval") {
|
|
734
|
-
// TODO: chrome support
|
|
735
|
-
debug && console.log("about to [eval]", message.script); // this will not show in Webkit console
|
|
736
|
-
const result = window.eval(message.script); // eslint-disable-line no-eval
|
|
737
|
-
return result;
|
|
738
|
-
}
|
|
739
|
-
else if (message.type === "hide") {
|
|
740
|
-
debug && console.log("[hide]", message.selectors);
|
|
741
|
-
return hideElementsUtil(message.selectors, message.method);
|
|
742
|
-
}
|
|
743
|
-
else if (message.type === "undohide") {
|
|
744
|
-
const existingElement = getStyleElementUtil();
|
|
745
|
-
debug && console.log("[unhide]", !!existingElement);
|
|
746
|
-
if (existingElement) {
|
|
747
|
-
existingElement.remove();
|
|
748
|
-
}
|
|
749
|
-
return !!existingElement;
|
|
750
|
-
}
|
|
751
|
-
else if (message.type === "matches") {
|
|
752
|
-
const matched = matches(message.config);
|
|
753
|
-
debug && console.log("[matches?]", message.config.type, JSON.stringify(message.config), matched);
|
|
754
|
-
return matched;
|
|
755
|
-
}
|
|
756
|
-
else if (message.type === "executeAction") {
|
|
757
|
-
debug && console.log("[executeAction]", message);
|
|
758
|
-
actionQueue = actionQueue.then(() => executeAction(message.config, message.param));
|
|
759
|
-
return true;
|
|
760
|
-
}
|
|
761
|
-
return null;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
class TabConsent {
|
|
765
|
-
constructor(tab, ruleCheckPromise) {
|
|
766
|
-
this.tab = tab;
|
|
767
|
-
this.optOutStatus = null;
|
|
768
|
-
this.checked = ruleCheckPromise;
|
|
769
|
-
ruleCheckPromise.then(rule => this.rule = rule);
|
|
770
|
-
}
|
|
771
|
-
getCMPName() {
|
|
772
|
-
if (this.rule) {
|
|
773
|
-
return this.rule.name;
|
|
774
|
-
}
|
|
775
|
-
return null;
|
|
776
|
-
}
|
|
777
|
-
async isPopupOpen(retries = 1, interval = 1000) {
|
|
778
|
-
const isOpen = await this.rule.detectPopup(this.tab);
|
|
779
|
-
if (!isOpen && retries > 0) {
|
|
780
|
-
return new Promise((resolve) => setTimeout(() => resolve(this.isPopupOpen(retries - 1, interval)), interval));
|
|
781
|
-
}
|
|
782
|
-
return isOpen;
|
|
783
|
-
}
|
|
784
|
-
async doOptOut() {
|
|
785
|
-
try {
|
|
786
|
-
enableLogs && console.log(`doing opt out ${this.getCMPName()} in tab ${this.tab.id}`);
|
|
787
|
-
this.optOutStatus = await this.rule.optOut(this.tab);
|
|
788
|
-
return this.optOutStatus;
|
|
789
|
-
}
|
|
790
|
-
catch (e) {
|
|
791
|
-
console.error('error during opt out', e);
|
|
792
|
-
this.optOutStatus = e;
|
|
793
|
-
throw e;
|
|
794
|
-
}
|
|
795
|
-
finally {
|
|
796
|
-
if (!this.rule.isHidingRule) {
|
|
797
|
-
if (this.getCMPName().startsWith('com_')) {
|
|
798
|
-
this.tab.wait(5000).then(() => this.tab.undoHideElements());
|
|
799
|
-
}
|
|
800
|
-
else {
|
|
801
|
-
await this.tab.undoHideElements();
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
async doOptIn() {
|
|
807
|
-
try {
|
|
808
|
-
return this.rule.optIn(this.tab);
|
|
809
|
-
}
|
|
810
|
-
finally {
|
|
811
|
-
if (!this.rule.isHidingRule) {
|
|
812
|
-
await this.tab.undoHideElements();
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
hasTest() {
|
|
817
|
-
return !!this.rule.hasSelfTest;
|
|
818
|
-
}
|
|
819
|
-
async testOptOutWorked() {
|
|
820
|
-
return this.rule.test(this.tab);
|
|
821
|
-
}
|
|
822
|
-
async applyCosmetics(selectors) {
|
|
823
|
-
const hidden = await this.tab.hideElements(selectors);
|
|
824
|
-
return hidden;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
async function detectDialog(tab, retries, rules) {
|
|
829
|
-
let breakEarly = false;
|
|
830
|
-
const found = await new Promise(async (resolve) => {
|
|
831
|
-
let earlyReturn = false;
|
|
832
|
-
await Promise.all(rules.map(async (r, index) => {
|
|
833
|
-
try {
|
|
834
|
-
if (await r.detectCmp(tab)) {
|
|
835
|
-
earlyReturn = true;
|
|
836
|
-
enableLogs && console.log(`Found CMP in [${tab.id}]: ${r.name}`);
|
|
837
|
-
resolve(index);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
catch (e) {
|
|
841
|
-
breakEarly = true;
|
|
842
|
-
}
|
|
843
|
-
}));
|
|
844
|
-
if (!earlyReturn) {
|
|
845
|
-
resolve(-1);
|
|
846
|
-
}
|
|
847
|
-
});
|
|
848
|
-
if (found === -1 && retries > 0 && !breakEarly) {
|
|
849
|
-
return new Promise((resolve) => {
|
|
850
|
-
setTimeout(async () => {
|
|
851
|
-
const result = detectDialog(tab, retries - 1, rules);
|
|
852
|
-
resolve(result);
|
|
853
|
-
}, 500);
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
return found > -1 ? rules[found] : null;
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
class TrustArc extends AutoConsentBase {
|
|
860
|
-
constructor() {
|
|
861
|
-
super("TrustArc");
|
|
862
|
-
this.prehideSelectors = [
|
|
863
|
-
".trustarc-banner-container",
|
|
864
|
-
".truste_popframe,.truste_overlay,.truste_box_overlay,#truste-consent-track",
|
|
865
|
-
];
|
|
866
|
-
}
|
|
867
|
-
detectFrame(_, frame) {
|
|
868
|
-
return frame.url.startsWith("https://consent-pref.trustarc.com/?");
|
|
869
|
-
}
|
|
870
|
-
async detectCmp(tab) {
|
|
871
|
-
if (tab.frame &&
|
|
872
|
-
tab.frame.url.startsWith("https://consent-pref.trustarc.com/?")) {
|
|
873
|
-
return true;
|
|
874
|
-
}
|
|
875
|
-
return tab.elementExists("#truste-show-consent");
|
|
876
|
-
}
|
|
877
|
-
async detectPopup(tab) {
|
|
878
|
-
return ((await tab.elementsAreVisible("#truste-consent-content,#trustarc-banner-overlay")) ||
|
|
879
|
-
(tab.frame &&
|
|
880
|
-
(await tab.waitForElement("#defaultpreferencemanager", 5000, tab.frame.id))));
|
|
881
|
-
}
|
|
882
|
-
async openFrame(tab) {
|
|
883
|
-
if (await tab.elementExists("#truste-show-consent")) {
|
|
884
|
-
await tab.clickElement("#truste-show-consent");
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
async navigateToSettings(tab, frameId) {
|
|
888
|
-
// wait for it to load
|
|
889
|
-
await waitFor(async () => {
|
|
890
|
-
return ((await tab.elementExists(".shp", frameId)) ||
|
|
891
|
-
(await tab.elementsAreVisible(".advance", "any", frameId)) ||
|
|
892
|
-
tab.elementExists(".switch span:first-child", frameId));
|
|
893
|
-
}, 10, 500);
|
|
894
|
-
// splash screen -> hit more information
|
|
895
|
-
if (await tab.elementExists(".shp", frameId)) {
|
|
896
|
-
await tab.clickElement(".shp", frameId);
|
|
897
|
-
}
|
|
898
|
-
await tab.waitForElement(".prefPanel", 5000, frameId);
|
|
899
|
-
// go to advanced settings if not yet shown
|
|
900
|
-
if (await tab.elementsAreVisible(".advance", "any", frameId)) {
|
|
901
|
-
await tab.clickElement(".advance", frameId);
|
|
902
|
-
}
|
|
903
|
-
// takes a while to load the opt-in/opt-out buttons
|
|
904
|
-
return await waitFor(() => tab.elementsAreVisible(".switch span:first-child", "any", frameId), 5, 1000);
|
|
905
|
-
}
|
|
906
|
-
async optOut(tab) {
|
|
907
|
-
// await tab.hideElements(['.truste_overlay', '.truste_box_overlay', '.trustarc-banner', '.truste-banner']);
|
|
908
|
-
if (await tab.elementExists("#truste-consent-required")) {
|
|
909
|
-
return tab.clickElement("#truste-consent-required");
|
|
910
|
-
}
|
|
911
|
-
if (!tab.frame) {
|
|
912
|
-
await tab.clickElement("#truste-show-consent");
|
|
913
|
-
await waitFor(async () => !!tab.frame &&
|
|
914
|
-
(await tab.elementsAreVisible(".mainContent", "any", tab.frame.id)), 50, 100);
|
|
915
|
-
}
|
|
916
|
-
const frameId = tab.frame.id;
|
|
917
|
-
await waitFor(() => tab.eval("document.readyState === 'complete'", frameId), 20, 100);
|
|
918
|
-
tab.hideElements([".truste_popframe", ".truste_overlay", ".truste_box_overlay", "#truste-consent-track"]);
|
|
919
|
-
if (await tab.elementExists('.rejectAll', frameId)) {
|
|
920
|
-
return tab.clickElement('.rejectAll', frameId);
|
|
921
|
-
}
|
|
922
|
-
if (await tab.waitForElement('#catDetails0', 1000, frameId)) {
|
|
923
|
-
await tab.clickElement("#catDetails0", frameId);
|
|
924
|
-
return tab.clickElement(".submit", frameId);
|
|
925
|
-
}
|
|
926
|
-
if (await tab.elementExists(".required", frameId)) {
|
|
927
|
-
await tab.clickElement(".required", frameId);
|
|
928
|
-
}
|
|
929
|
-
else {
|
|
930
|
-
await this.navigateToSettings(tab, frameId);
|
|
931
|
-
await tab.clickElements(".switch span:nth-child(1):not(.active)", frameId);
|
|
932
|
-
await tab.clickElement(".submit", frameId);
|
|
933
|
-
}
|
|
934
|
-
try {
|
|
935
|
-
await tab.waitForThenClick("#gwt-debug-close_id", 20000, tab.frame.id);
|
|
936
|
-
}
|
|
937
|
-
catch (e) {
|
|
938
|
-
// ignore frame disappearing
|
|
939
|
-
}
|
|
940
|
-
return true;
|
|
941
|
-
}
|
|
942
|
-
async optIn(tab) {
|
|
943
|
-
if (!tab.frame) {
|
|
944
|
-
await this.openFrame(tab);
|
|
945
|
-
await waitFor(() => !!tab.frame, 10, 200);
|
|
946
|
-
}
|
|
947
|
-
const frameId = tab.frame.id;
|
|
948
|
-
await this.navigateToSettings(tab, frameId);
|
|
949
|
-
await tab.clickElements(".switch span:nth-child(2)", frameId);
|
|
950
|
-
await tab.clickElement(".submit", frameId);
|
|
951
|
-
await waitFor(() => tab.elementExists("#gwt-debug-close_id", frameId), 300, 1000);
|
|
952
|
-
await tab.clickElement("#gwt-debug-close_id", frameId);
|
|
953
|
-
return true;
|
|
954
|
-
}
|
|
955
|
-
async openCmp(tab) {
|
|
956
|
-
await tab.eval("truste.eu.clickListener()");
|
|
957
|
-
return true;
|
|
958
|
-
}
|
|
959
|
-
async test() {
|
|
960
|
-
// TODO: find out how to test TrustArc
|
|
961
|
-
return true;
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
class Cookiebot extends AutoConsentBase {
|
|
966
|
-
constructor() {
|
|
967
|
-
super('Cybotcookiebot');
|
|
968
|
-
this.prehideSelectors = ["#CybotCookiebotDialog,#dtcookie-container,#cookiebanner"];
|
|
969
|
-
}
|
|
970
|
-
async detectCmp(tab) {
|
|
971
|
-
try {
|
|
972
|
-
return await tab.eval('typeof window.CookieConsent === "object" && typeof window.CookieConsent.name === "string"');
|
|
973
|
-
}
|
|
974
|
-
catch (e) {
|
|
975
|
-
return false;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
detectPopup(tab) {
|
|
979
|
-
return tab.elementExists('#CybotCookiebotDialog,#dtcookie-container,#cookiebanner');
|
|
980
|
-
}
|
|
981
|
-
async optOut(tab) {
|
|
982
|
-
if (await tab.elementExists('.cookie-alert-extended-detail-link')) {
|
|
983
|
-
await tab.clickElement('.cookie-alert-extended-detail-link');
|
|
984
|
-
await tab.waitForElement('.cookie-alert-configuration', 1000);
|
|
985
|
-
await tab.clickElements('.cookie-alert-configuration-input:checked');
|
|
986
|
-
return tab.clickElement('.cookie-alert-extended-button-secondary');
|
|
987
|
-
}
|
|
988
|
-
if (await tab.elementExists('#dtcookie-container')) {
|
|
989
|
-
return tab.clickElement('.h-dtcookie-decline');
|
|
990
|
-
}
|
|
991
|
-
if (await tab.elementExists('.cookiebot__button--settings')) {
|
|
992
|
-
await tab.clickElement('.cookiebot__button--settings');
|
|
993
|
-
}
|
|
994
|
-
if (await tab.elementsAreVisible('#CybotCookiebotDialogBodyButtonDecline', 'all')) {
|
|
995
|
-
return await tab.clickElement('#CybotCookiebotDialogBodyButtonDecline');
|
|
996
|
-
}
|
|
997
|
-
if (await tab.elementExists('.cookiebanner__link--details')) {
|
|
998
|
-
await tab.clickElement('.cookiebanner__link--details');
|
|
999
|
-
}
|
|
1000
|
-
await tab.clickElements('.CybotCookiebotDialogBodyLevelButton:checked:enabled,input[id*="CybotCookiebotDialogBodyLevelButton"]:checked:enabled');
|
|
1001
|
-
if (await tab.elementExists('#CybotCookiebotDialogBodyButtonDecline')) {
|
|
1002
|
-
await tab.clickElement('#CybotCookiebotDialogBodyButtonDecline');
|
|
1003
|
-
}
|
|
1004
|
-
if (await tab.elementExists('input[id^=CybotCookiebotDialogBodyLevelButton]:checked')) {
|
|
1005
|
-
await tab.clickElements('input[id^=CybotCookiebotDialogBodyLevelButton]:checked');
|
|
1006
|
-
}
|
|
1007
|
-
if (await tab.elementExists('#CybotCookiebotDialogBodyButtonAcceptSelected')) {
|
|
1008
|
-
await tab.clickElement('#CybotCookiebotDialogBodyButtonAcceptSelected');
|
|
1009
|
-
}
|
|
1010
|
-
else {
|
|
1011
|
-
await tab.clickElements('#CybotCookiebotDialogBodyLevelButtonAccept,#CybotCookiebotDialogBodyButtonAccept,#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowallSelection');
|
|
1012
|
-
}
|
|
1013
|
-
// some sites have custom submit buttons with no obvious selectors. In this case we just call the submitConsent API.
|
|
1014
|
-
if (await tab.eval('CookieConsent.hasResponse !== true')) {
|
|
1015
|
-
await tab.eval('Cookiebot.dialog.submitConsent() || true');
|
|
1016
|
-
await tab.wait(500);
|
|
1017
|
-
}
|
|
1018
|
-
return true;
|
|
1019
|
-
}
|
|
1020
|
-
async optIn(tab) {
|
|
1021
|
-
if (await tab.elementExists('#dtcookie-container')) {
|
|
1022
|
-
return tab.clickElement('.h-dtcookie-accept');
|
|
1023
|
-
}
|
|
1024
|
-
await tab.clickElements('.CybotCookiebotDialogBodyLevelButton:not(:checked):enabled');
|
|
1025
|
-
await tab.clickElement('#CybotCookiebotDialogBodyLevelButtonAccept');
|
|
1026
|
-
await tab.clickElement('#CybotCookiebotDialogBodyButtonAccept');
|
|
1027
|
-
return true;
|
|
1028
|
-
}
|
|
1029
|
-
async openCmp(tab) {
|
|
1030
|
-
await tab.eval('CookieConsent.renew() || true');
|
|
1031
|
-
return tab.waitForElement('#CybotCookiebotDialog', 10000);
|
|
1032
|
-
}
|
|
1033
|
-
async test(tab) {
|
|
1034
|
-
return tab.eval('CookieConsent.declined === true');
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
class SourcePoint extends AutoConsentBase {
|
|
1039
|
-
constructor() {
|
|
1040
|
-
super("Sourcepoint");
|
|
1041
|
-
this.ccpaMode = false;
|
|
1042
|
-
this.prehideSelectors = ["div[id^='sp_message_container_'],.message-overlay"];
|
|
1043
|
-
}
|
|
1044
|
-
detectFrame(_, frame) {
|
|
1045
|
-
try {
|
|
1046
|
-
const url = new URL(frame.url);
|
|
1047
|
-
if (url.searchParams.has('message_id') && url.hostname === 'ccpa-notice.sp-prod.net') {
|
|
1048
|
-
this.ccpaMode = true;
|
|
1049
|
-
return true;
|
|
1050
|
-
}
|
|
1051
|
-
return (url.pathname === '/index.html' || url.pathname === '/privacy-manager/index.html')
|
|
1052
|
-
&& url.searchParams.has('message_id') && url.searchParams.has('requestUUID');
|
|
1053
|
-
}
|
|
1054
|
-
catch (e) {
|
|
1055
|
-
return false;
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
async detectCmp(tab) {
|
|
1059
|
-
return await tab.elementExists("div[id^='sp_message_container_']") || !!tab.frame;
|
|
1060
|
-
}
|
|
1061
|
-
async detectPopup(tab) {
|
|
1062
|
-
return await tab.elementsAreVisible("div[id^='sp_message_container_']");
|
|
1063
|
-
}
|
|
1064
|
-
async optIn(tab) {
|
|
1065
|
-
return tab.clickElement(".sp_choice_type_11", tab.frame.id);
|
|
1066
|
-
}
|
|
1067
|
-
isManagerOpen(tab) {
|
|
1068
|
-
return tab.frame && new URL(tab.frame.url).pathname === "/privacy-manager/index.html";
|
|
1069
|
-
}
|
|
1070
|
-
async optOut(tab) {
|
|
1071
|
-
try {
|
|
1072
|
-
tab.hideElements(["div[id^='sp_message_container_']"]);
|
|
1073
|
-
if (!this.isManagerOpen(tab)) {
|
|
1074
|
-
if (!await waitFor(() => !!tab.frame, 30, 100)) {
|
|
1075
|
-
throw "Frame never opened";
|
|
1076
|
-
}
|
|
1077
|
-
if (!await tab.elementExists("button.sp_choice_type_12", tab.frame.id)) {
|
|
1078
|
-
// do not sell button
|
|
1079
|
-
return tab.clickElement('button.sp_choice_type_13', tab.frame.id);
|
|
1080
|
-
}
|
|
1081
|
-
await success(tab.clickElement("button.sp_choice_type_12", tab.frame.id));
|
|
1082
|
-
await waitFor(() => new URL(tab.frame.url).pathname === "/privacy-manager/index.html", 200, 100);
|
|
1083
|
-
}
|
|
1084
|
-
await tab.waitForElement('.type-modal', 20000, tab.frame.id);
|
|
1085
|
-
// reject all button is offered by some sites
|
|
1086
|
-
try {
|
|
1087
|
-
const path = await Promise.race([
|
|
1088
|
-
tab.waitForElement('.sp_choice_type_REJECT_ALL', 2000, tab.frame.id).then(r => 0),
|
|
1089
|
-
tab.waitForElement('.reject-toggle', 2000, tab.frame.id).then(() => 1),
|
|
1090
|
-
tab.waitForElement('.pm-features', 2000, tab.frame.id).then(r => 2),
|
|
1091
|
-
]);
|
|
1092
|
-
if (path === 0) {
|
|
1093
|
-
await tab.wait(1000);
|
|
1094
|
-
return await success(tab.clickElement('.sp_choice_type_REJECT_ALL', tab.frame.id));
|
|
1095
|
-
}
|
|
1096
|
-
else if (path === 1) {
|
|
1097
|
-
await tab.clickElement('.reject-toggle', tab.frame.id);
|
|
1098
|
-
}
|
|
1099
|
-
else {
|
|
1100
|
-
await tab.waitForElement('.pm-features', 10000, tab.frame.id);
|
|
1101
|
-
await tab.clickElements('.checked > span', tab.frame.id);
|
|
1102
|
-
if (await tab.elementExists('.chevron', tab.frame.id)) {
|
|
1103
|
-
await tab.clickElement('.chevron', tab.frame.id);
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
catch (e) { }
|
|
1108
|
-
return await tab.clickElement('.sp_choice_type_SAVE_AND_EXIT', tab.frame.id);
|
|
1109
|
-
}
|
|
1110
|
-
finally {
|
|
1111
|
-
tab.undoHideElements();
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
async test(tab) {
|
|
1115
|
-
await tab.eval("__tcfapi('getTCData', 2, r => window.__rcsResult = r)");
|
|
1116
|
-
return tab.eval("Object.values(window.__rcsResult.purpose.consents).every(c => !c)");
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
// Note: JS API is also available:
|
|
1121
|
-
// https://help.consentmanager.net/books/cmp/page/javascript-api
|
|
1122
|
-
class ConsentManager extends AutoConsentBase {
|
|
1123
|
-
constructor() {
|
|
1124
|
-
super("consentmanager.net");
|
|
1125
|
-
this.prehideSelectors = ["#cmpbox,#cmpbox2"];
|
|
1126
|
-
}
|
|
1127
|
-
detectCmp(tab) {
|
|
1128
|
-
return tab.elementExists("#cmpbox");
|
|
1129
|
-
}
|
|
1130
|
-
detectPopup(tab) {
|
|
1131
|
-
return tab.elementsAreVisible("#cmpbox .cmpmore", "any");
|
|
1132
|
-
}
|
|
1133
|
-
async optOut(tab) {
|
|
1134
|
-
if (await tab.elementExists(".cmpboxbtnno")) {
|
|
1135
|
-
return tab.clickElement(".cmpboxbtnno");
|
|
1136
|
-
}
|
|
1137
|
-
if (await tab.elementExists(".cmpwelcomeprpsbtn")) {
|
|
1138
|
-
await tab.clickElements(".cmpwelcomeprpsbtn > a[aria-checked=true]");
|
|
1139
|
-
return await tab.clickElement(".cmpboxbtnsave");
|
|
1140
|
-
}
|
|
1141
|
-
await tab.clickElement(".cmpboxbtncustom");
|
|
1142
|
-
await tab.waitForElement(".cmptblbox", 2000);
|
|
1143
|
-
await tab.clickElements(".cmptdchoice > a[aria-checked=true]");
|
|
1144
|
-
return tab.clickElement(".cmpboxbtnyescustomchoices");
|
|
1145
|
-
}
|
|
1146
|
-
async optIn(tab) {
|
|
1147
|
-
return tab.clickElement(".cmpboxbtnyes");
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
// Note: JS API is also available:
|
|
1152
|
-
// https://help.consentmanager.net/books/cmp/page/javascript-api
|
|
1153
|
-
class Evidon extends AutoConsentBase {
|
|
1154
|
-
constructor() {
|
|
1155
|
-
super("Evidon");
|
|
1156
|
-
}
|
|
1157
|
-
detectCmp(tab) {
|
|
1158
|
-
return tab.elementExists("#_evidon_banner");
|
|
1159
|
-
}
|
|
1160
|
-
detectPopup(tab) {
|
|
1161
|
-
return tab.elementsAreVisible("#_evidon_banner");
|
|
1162
|
-
}
|
|
1163
|
-
async optOut(tab) {
|
|
1164
|
-
if (await tab.elementExists("#_evidon-decline-button")) {
|
|
1165
|
-
return tab.clickElement("#_evidon-decline-button");
|
|
1166
|
-
}
|
|
1167
|
-
tab.hideElements(["#evidon-prefdiag-overlay", "#evidon-prefdiag-background"]);
|
|
1168
|
-
await tab.clickElement("#_evidon-option-button");
|
|
1169
|
-
await tab.waitForElement("#evidon-prefdiag-overlay", 5000);
|
|
1170
|
-
return tab.clickElement("#evidon-prefdiag-decline");
|
|
1171
|
-
}
|
|
1172
|
-
async optIn(tab) {
|
|
1173
|
-
return tab.clickElement("#_evidon-accept-button");
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
class Onetrust extends AutoConsentBase {
|
|
1178
|
-
constructor() {
|
|
1179
|
-
super("Onetrust");
|
|
1180
|
-
this.prehideSelectors = ["#onetrust-banner-sdk,#onetrust-consent-sdk,.optanon-alert-box-wrapper,.onetrust-pc-dark-filter,.js-consent-banner"];
|
|
1181
|
-
}
|
|
1182
|
-
detectCmp(tab) {
|
|
1183
|
-
return tab.elementExists("#onetrust-banner-sdk,.optanon-alert-box-wrapper");
|
|
1184
|
-
}
|
|
1185
|
-
detectPopup(tab) {
|
|
1186
|
-
return tab.elementsAreVisible("#onetrust-banner-sdk,.optanon-alert-box-wrapper");
|
|
1187
|
-
}
|
|
1188
|
-
async optOut(tab) {
|
|
1189
|
-
if (await tab.elementExists("#onetrust-pc-btn-handler")) { // "show purposes" button inside a popup
|
|
1190
|
-
await success(tab.clickElement("#onetrust-pc-btn-handler"));
|
|
1191
|
-
}
|
|
1192
|
-
else { // otherwise look for a generic "show settings" button
|
|
1193
|
-
await success(tab.clickElement(".ot-sdk-show-settings,button.js-cookie-settings"));
|
|
1194
|
-
}
|
|
1195
|
-
await success(tab.waitForElement("#onetrust-consent-sdk", 2000));
|
|
1196
|
-
await success(tab.wait(1000));
|
|
1197
|
-
await tab.clickElements("#onetrust-consent-sdk input.category-switch-handler:checked,.js-editor-toggle-state:checked"); // optional step
|
|
1198
|
-
await success(tab.waitForThenClick(".save-preference-btn-handler,.js-consent-save", 1000));
|
|
1199
|
-
// popup doesn't disappear immediately
|
|
1200
|
-
await waitFor(async () => !(await tab.elementsAreVisible("#onetrust-banner-sdk")), 10, 500);
|
|
1201
|
-
return true;
|
|
1202
|
-
}
|
|
1203
|
-
async optIn(tab) {
|
|
1204
|
-
return tab.clickElement("onetrust-accept-btn-handler,js-accept-cookies");
|
|
1205
|
-
}
|
|
1206
|
-
async test(tab) {
|
|
1207
|
-
return tab.eval("window.OnetrustActiveGroups.split(',').filter(s => s.length > 0).length <= 1");
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
const rules = [
|
|
1212
|
-
new TrustArc(),
|
|
1213
|
-
new Cookiebot(),
|
|
1214
|
-
new SourcePoint(),
|
|
1215
|
-
new ConsentManager(),
|
|
1216
|
-
new Evidon(),
|
|
1217
|
-
new Onetrust(),
|
|
1218
|
-
];
|
|
1219
|
-
function createAutoCMP(config) {
|
|
1220
|
-
return new AutoConsent(config);
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
const rules$1 = rules;
|
|
1224
|
-
|
|
1225
|
-
class ConsentOMaticCMP {
|
|
1226
|
-
constructor(name, config) {
|
|
1227
|
-
this.name = name;
|
|
1228
|
-
this.config = config;
|
|
1229
|
-
this.methods = new Map();
|
|
1230
|
-
config.methods.forEach(methodConfig => {
|
|
1231
|
-
if (methodConfig.action) {
|
|
1232
|
-
this.methods.set(methodConfig.name, methodConfig.action);
|
|
1233
|
-
}
|
|
1234
|
-
});
|
|
1235
|
-
this.hasSelfTest = this.methods.has("TEST_CONSENT");
|
|
1236
|
-
}
|
|
1237
|
-
async detectCmp(tab) {
|
|
1238
|
-
return (await Promise.all(this.config.detectors.map(detectorConfig => tab.matches(detectorConfig.presentMatcher)))).some(matched => matched);
|
|
1239
|
-
}
|
|
1240
|
-
async detectPopup(tab) {
|
|
1241
|
-
return (await Promise.all(this.config.detectors.map(detectorConfig => tab.matches(detectorConfig.showingMatcher)))).some(matched => matched);
|
|
1242
|
-
}
|
|
1243
|
-
async executeAction(tab, method, param) {
|
|
1244
|
-
if (this.methods.has(method)) {
|
|
1245
|
-
return tab.executeAction(this.methods.get(method), param);
|
|
1246
|
-
}
|
|
1247
|
-
return true;
|
|
1248
|
-
}
|
|
1249
|
-
async optOut(tab) {
|
|
1250
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
1251
|
-
await this.executeAction(tab, "OPEN_OPTIONS");
|
|
1252
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
1253
|
-
await this.executeAction(tab, "DO_CONSENT", []);
|
|
1254
|
-
await this.executeAction(tab, "SAVE_CONSENT");
|
|
1255
|
-
return true;
|
|
1256
|
-
}
|
|
1257
|
-
async optIn(tab) {
|
|
1258
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
1259
|
-
await this.executeAction(tab, "OPEN_OPTIONS");
|
|
1260
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
1261
|
-
await this.executeAction(tab, "DO_CONSENT", ['D', 'A', 'B', 'E', 'F', 'X']);
|
|
1262
|
-
await this.executeAction(tab, "SAVE_CONSENT");
|
|
1263
|
-
return true;
|
|
1264
|
-
}
|
|
1265
|
-
async openCmp(tab) {
|
|
1266
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
1267
|
-
await this.executeAction(tab, "OPEN_OPTIONS");
|
|
1268
|
-
return true;
|
|
1269
|
-
}
|
|
1270
|
-
test(tab) {
|
|
1271
|
-
return this.executeAction(tab, "TEST_CONSENT");
|
|
1272
|
-
}
|
|
1273
|
-
detectFrame(tab, frame) {
|
|
1274
|
-
return false;
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
// hide rules not specific to a single CMP rule
|
|
1279
|
-
const globalHidden = [
|
|
1280
|
-
"#didomi-popup,.didomi-popup-container,.didomi-popup-notice,.didomi-consent-popup-preferences,#didomi-notice,.didomi-popup-backdrop,.didomi-screen-medium",
|
|
1281
|
-
];
|
|
1282
|
-
async function prehideElements(tab, rules) {
|
|
1283
|
-
const selectors = rules.reduce((selectorList, rule) => {
|
|
1284
|
-
if (rule.prehideSelectors) {
|
|
1285
|
-
return [...selectorList, ...rule.prehideSelectors];
|
|
1286
|
-
}
|
|
1287
|
-
return selectorList;
|
|
1288
|
-
}, globalHidden);
|
|
1289
|
-
await tab.hideElements(selectors, undefined, 'opacity');
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
class AutoConsent$1 {
|
|
1293
|
-
constructor(browser, sendContentMessage) {
|
|
1294
|
-
this.browser = browser;
|
|
1295
|
-
this.sendContentMessage = sendContentMessage;
|
|
1296
|
-
this.consentFrames = new Map();
|
|
1297
|
-
this.tabCmps = new Map();
|
|
1298
|
-
this.sendContentMessage = sendContentMessage;
|
|
1299
|
-
this.rules = [...rules$1];
|
|
1300
|
-
}
|
|
1301
|
-
addCMP(config) {
|
|
1302
|
-
this.rules.push(createAutoCMP(config));
|
|
1303
|
-
}
|
|
1304
|
-
disableCMPs(cmpNames) {
|
|
1305
|
-
this.rules = this.rules.filter((cmp) => !cmpNames.includes(cmp.name));
|
|
1306
|
-
}
|
|
1307
|
-
addConsentomaticCMP(name, config) {
|
|
1308
|
-
this.rules.push(new ConsentOMaticCMP(`com_${name}`, config));
|
|
1309
|
-
}
|
|
1310
|
-
createTab(tabId) {
|
|
1311
|
-
return new TabActions(tabId, this.consentFrames.get(tabId), this.sendContentMessage, this.browser);
|
|
1312
|
-
}
|
|
1313
|
-
async checkTab(tabId, prehide = true) {
|
|
1314
|
-
const tab = this.createTab(tabId);
|
|
1315
|
-
if (prehide) {
|
|
1316
|
-
this.prehideElements(tab);
|
|
1317
|
-
}
|
|
1318
|
-
const consent = new TabConsent(tab, this.detectDialog(tab, 20));
|
|
1319
|
-
this.tabCmps.set(tabId, consent);
|
|
1320
|
-
// check tabs
|
|
1321
|
-
consent.checked.then((rule) => {
|
|
1322
|
-
if (this.consentFrames.has(tabId) && rule) {
|
|
1323
|
-
const frame = this.consentFrames.get(tabId);
|
|
1324
|
-
if (frame.type === rule.name) {
|
|
1325
|
-
consent.tab.frame = frame;
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
// no CMP detected, undo hiding
|
|
1329
|
-
if (!rule && prehide) {
|
|
1330
|
-
tab.undoHideElements();
|
|
1331
|
-
}
|
|
1332
|
-
});
|
|
1333
|
-
return this.tabCmps.get(tabId);
|
|
1334
|
-
}
|
|
1335
|
-
removeTab(tabId) {
|
|
1336
|
-
this.tabCmps.delete(tabId);
|
|
1337
|
-
this.consentFrames.delete(tabId);
|
|
1338
|
-
}
|
|
1339
|
-
onFrame({ tabId, url, frameId }) {
|
|
1340
|
-
// ignore main frames
|
|
1341
|
-
if (frameId === 0) {
|
|
1342
|
-
return;
|
|
1343
|
-
}
|
|
1344
|
-
try {
|
|
1345
|
-
const frame = {
|
|
1346
|
-
id: frameId,
|
|
1347
|
-
url: url,
|
|
1348
|
-
};
|
|
1349
|
-
const tab = this.createTab(tabId);
|
|
1350
|
-
const frameMatch = this.rules.findIndex(r => r.detectFrame(tab, frame));
|
|
1351
|
-
if (frameMatch > -1) {
|
|
1352
|
-
this.consentFrames.set(tabId, {
|
|
1353
|
-
type: this.rules[frameMatch].name,
|
|
1354
|
-
url,
|
|
1355
|
-
id: frameId,
|
|
1356
|
-
});
|
|
1357
|
-
if (this.tabCmps.has(tabId)) {
|
|
1358
|
-
this.tabCmps.get(tabId).tab.frame = this.consentFrames.get(tabId);
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
catch (e) {
|
|
1363
|
-
console.error(e);
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
async detectDialog(tab, retries) {
|
|
1367
|
-
return detectDialog(tab, retries, this.rules);
|
|
1368
|
-
}
|
|
1369
|
-
async prehideElements(tab) {
|
|
1370
|
-
return prehideElements(tab, this.rules);
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
export default AutoConsent$1;
|
|
1375
|
-
export { TabActions as Tab, createAutoCMP, handleMessage as handleContentMessage, rules$1 as rules, waitFor };
|
|
1
|
+
class e{constructor(e,t=1e3){this.id=e,this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t})),this.timer=window.setTimeout((()=>{this.reject(new Error("timeout"))}),t)}}const t={pending:new Map,sendContentMessage:null};function n(e="autoconsent-css-rules"){const t=`style#${e}`,n=document.querySelector(t);if(n&&n instanceof HTMLStyleElement)return n;{const t=document.head||document.getElementsByTagName("head")[0]||document.documentElement,n=document.createElement("style");return n.id=e,t.appendChild(n),n}}function o(e,t,n="display"){const o="opacity"===n?"opacity: 0":"display: none",s=`${t.join(",")} { ${o} !important; z-index: -1 !important; pointer-events: none !important; } `;return e instanceof HTMLStyleElement&&(e.innerText+=s,t.length>0)}async function s(e,t,n){const o=await e();return!o&&t>0?new Promise((o=>{setTimeout((async()=>{o(s(e,t-1,n))}),n)})):Promise.resolve(o)}function i(n){return function(n){let o;o=crypto&&void 0!==crypto.randomUUID?crypto.randomUUID():Math.random().toString(),t.sendContentMessage({type:"eval",id:o,code:n});const s=new e(o);return t.pending.set(s.id,s),s.promise}(n).catch((e=>!1))}function r(e,t=!1){const n=document.querySelectorAll(e);return n.length>0&&(t?n.forEach((e=>e.click())):n[0].click()),n.length>0}function a(e){return null!==document.querySelector(e)}function c(e,t){const n=document.querySelectorAll(e),o=new Array(n.length);return n.forEach(((e,t)=>{o[t]=function(e){if(!e)return!1;if(null!==e.offsetParent)return!0;{const t=window.getComputedStyle(e);if("fixed"===t.position&&"none"!==t.display)return!0}return!1}(e)})),0!==o.length&&("any"===t?o.some((e=>e)):"none"===t?o.every((e=>!e)):o.every((e=>e)))}function u(e,t=1e4){return s((()=>null!==document.querySelector(e)),Math.ceil(t/200),200)}function l(e){return new Promise((t=>{setTimeout((()=>{t(!0)}),e)}))}function d(){const e=n("autoconsent-prehide");return e&&e.remove(),!!e}const p={main:!0,frame:!1,url:""};class h{constructor(e){this.runContext=p,this.name=e}get hasSelfTest(){throw new Error("Not Implemented")}get isIntermediate(){throw new Error("Not Implemented")}checkRunContext(){const e={...p,...this.runContext},t=window.top===window;return!(t&&!e.main)&&(!(!t&&!e.frame)&&!(e.url&&!window.location.href.startsWith(e.url)))}detectCmp(){throw new Error("Not Implemented")}async detectPopup(){return!1}optOut(){throw new Error("Not Implemented")}optIn(){throw new Error("Not Implemented")}openCmp(){throw new Error("Not Implemented")}async test(){return Promise.resolve(!0)}}async function m(e){const t=[];if(e.exists&&t.push(a(e.exists)),e.visible&&t.push(c(e.visible,e.check)),e.eval){const n=i(e.eval);t.push(n)}var d,p;if(e.waitFor&&t.push(u(e.waitFor,e.timeout)),e.waitForVisible&&t.push(function(e,t=1e4,n="any"){return s((()=>c(e,n)),Math.ceil(t/200),200)}(e.waitForVisible,e.timeout,e.check)),e.click&&t.push(r(e.click,e.all)),e.waitForThenClick&&t.push(async function(e,t=1e4,n=!1){return await u(e,t),r(e,n)}(e.waitForThenClick,e.timeout,e.all)),e.wait&&t.push(l(e.wait)),e.hide&&t.push((d=e.hide,p=e.method,o(n(),d,p))),0===t.length)return!1;return(await Promise.all(t)).reduce(((e,t)=>e&&t),!0)}class f extends h{constructor(e){super(e.name),this.config=e,this.runContext=e.runContext||p}get hasSelfTest(){return!!this.config.test}get isIntermediate(){return!!this.config.intermediate}get prehideSelectors(){return this.config.prehideSelectors}async _runRulesParallel(e){const t=e.map((e=>m(e)));return(await Promise.all(t)).every((e=>!!e))}async _runRulesSequentially(e){for(const t of e){if(!await m(t)&&!t.optional)return!1}return!0}async detectCmp(){return!!this.config.detectCmp&&this._runRulesParallel(this.config.detectCmp)}async detectPopup(){return!!this.config.detectPopup&&this._runRulesParallel(this.config.detectPopup)}async optOut(){return!!this.config.optOut&&this._runRulesSequentially(this.config.optOut)}async optIn(){return!!this.config.optIn&&this._runRulesSequentially(this.config.optIn)}async openCmp(){return!!this.config.openCmp&&this._runRulesSequentially(this.config.openCmp)}async test(){return this.hasSelfTest?this._runRulesSequentially(this.config.test):super.test()}}function w(e){return new f(e)}const y=[new class extends h{constructor(){super("TrustArc-top"),this.prehideSelectors=[".trustarc-banner-container",".truste_popframe,.truste_overlay,.truste_box_overlay,#truste-consent-track"],this.runContext={main:!0,frame:!1},this._shortcutButton=null,this._optInDone=!1}get hasSelfTest(){return!1}get isIntermediate(){return!this._optInDone&&!this._shortcutButton}async detectCmp(){const e=a("#truste-show-consent,#truste-consent-track");return e&&(this._shortcutButton=document.querySelector("#truste-consent-required")),e}async detectPopup(){return c("#truste-consent-content,#trustarc-banner-overlay,#truste-consent-track","all")}openFrame(){r("#truste-show-consent")}async optOut(){return this._shortcutButton?(this._shortcutButton.click(),!0):(o(n(),[".truste_popframe",".truste_overlay",".truste_box_overlay","#truste-consent-track"]),r("#truste-show-consent"),setTimeout((()=>{n().remove()}),1e4),!0)}async optIn(){return this._optInDone=!0,r("#truste-consent-button")}async openCmp(){return!0}async test(){return!0}},new class extends h{constructor(){super("TrustArc-frame"),this.runContext={main:!1,frame:!0,url:"https://consent-pref.trustarc.com/?"}}get hasSelfTest(){return!1}get isIntermediate(){return!1}async detectCmp(){return!0}async detectPopup(){return c("#defaultpreferencemanager","any")&&c(".mainContent","any")}async navigateToSettings(){return await s((async()=>a(".shp")||c(".advance","any")||a(".switch span:first-child")),10,500),a(".shp")&&r(".shp"),await u(".prefPanel",5e3),c(".advance","any")&&r(".advance"),await s((()=>c(".switch span:first-child","any")),5,1e3)}async optOut(){return await s((()=>"complete"===document.readyState),20,100),await u(".mainContent[aria-hidden=false]",5e3),!!r(".rejectAll")||(a(".prefPanel")&&await u('.prefPanel[style="visibility: visible;"]',3e3),r("#catDetails0")?(r(".submit"),!0):(r(".required")||(await this.navigateToSettings(),r(".switch span:nth-child(1):not(.active)",!0),r(".submit"),u("#gwt-debug-close_id",3e5).then((()=>{r("#gwt-debug-close_id")}))),!0))}async optIn(){return await this.navigateToSettings(),r(".switch span:nth-child(2)",!0),r(".submit"),u("#gwt-debug-close_id",3e5).then((()=>{r("#gwt-debug-close_id")})),!0}},new class extends h{constructor(){super("Cybotcookiebot"),this.prehideSelectors=["#CybotCookiebotDialog,#dtcookie-container,#cookiebanner,#cb-cookieoverlay"]}get hasSelfTest(){return!0}get isIntermediate(){return!1}async detectCmp(){return a("#CybotCookiebotDialogBodyLevelButtonPreferences")}async detectPopup(){return a("#CybotCookiebotDialog,#dtcookie-container,#cookiebanner,#cb-cookiebanner")}async optOut(){return r(".cookie-alert-extended-detail-link")?(await u(".cookie-alert-configuration",2e3),r(".cookie-alert-configuration-input:checked",!0),r(".cookie-alert-extended-button-secondary"),!0):a("#dtcookie-container")?r(".h-dtcookie-decline"):(r(".cookiebot__button--settings")||r("#CybotCookiebotDialogBodyButtonDecline")||(r(".cookiebanner__link--details"),r('.CybotCookiebotDialogBodyLevelButton:checked:enabled,input[id*="CybotCookiebotDialogBodyLevelButton"]:checked:enabled',!0),r("#CybotCookiebotDialogBodyButtonDecline"),r("input[id^=CybotCookiebotDialogBodyLevelButton]:checked",!0),a("#CybotCookiebotDialogBodyButtonAcceptSelected")?r("#CybotCookiebotDialogBodyButtonAcceptSelected"):r("#CybotCookiebotDialogBodyLevelButtonAccept,#CybotCookiebotDialogBodyButtonAccept,#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowallSelection",!0),await i("window.CookieConsent.hasResponse !== true")&&(await i("window.Cookiebot.dialog.submitConsent()"),await l(500)),a("#cb-confirmedSettings")&&await i("endCookieProcess()")),!0)}async optIn(){return a("#dtcookie-container")?r(".h-dtcookie-accept"):(r(".CybotCookiebotDialogBodyLevelButton:not(:checked):enabled",!0),r("#CybotCookiebotDialogBodyLevelButtonAccept"),r("#CybotCookiebotDialogBodyButtonAccept"),!0)}async test(){return i("window.CookieConsent.declined === true")}},new class extends h{constructor(){super("Sourcepoint-top"),this.prehideSelectors=["div[id^='sp_message_container_'],.message-overlay"],this.runContext={main:!0,frame:!1}}get hasSelfTest(){return!0}get isIntermediate(){return!0}async detectCmp(){return a("div[id^='sp_message_container_']")}async detectPopup(){return c("div[id^='sp_message_container_']","all")}async optIn(){return!0}async optOut(){return!0}async test(){return await i("__tcfapi('getTCData', 2, r => window.__rcsResult = r)"),await i("Object.values(window.__rcsResult.purpose.consents).every(c => !c)")}},new class extends h{constructor(){super("Sourcepoint-frame"),this.ccpaMode=!1,this.runContext={main:!1,frame:!0}}get hasSelfTest(){return!1}get isIntermediate(){return!1}async detectCmp(){const e=new URL(location.href);return e.searchParams.has("message_id")&&"ccpa-notice.sp-prod.net"===e.hostname?(this.ccpaMode=!0,!0):("/index.html"===e.pathname||"/privacy-manager/index.html"===e.pathname)&&e.searchParams.has("message_id")&&e.searchParams.has("requestUUID")}async detectPopup(){return!0}async optIn(){return await u(".sp_choice_type_11,.sp_choice_type_ACCEPT_ALL",2e3),!!r(".sp_choice_type_11")||!!r(".sp_choice_type_ACCEPT_ALL")}isManagerOpen(){return"/privacy-manager/index.html"===new URL(location.href).pathname}async optOut(){if(!this.isManagerOpen()){if(!await u("button.sp_choice_type_12,button.sp_choice_type_13"))return!1;if(!a("button.sp_choice_type_12"))return r("button.sp_choice_type_13");r("button.sp_choice_type_12"),await s((()=>"/privacy-manager/index.html"===location.pathname),200,100)}await u(".type-modal",2e4);try{const e=".sp_choice_type_REJECT_ALL",t=".reject-toggle",n=await Promise.race([u(e,2e3).then((e=>e?0:-1)),u(t,2e3).then((e=>e?1:-1)),u(".pm-features",2e3).then((e=>e?2:-1))]);if(0===n)return await l(1e3),r(e);if(1===n)return r(t);2===n&&(await u(".pm-features",1e4),r(".checked > span",!0),r(".chevron"))}catch(e){}return r(".sp_choice_type_SAVE_AND_EXIT")}},new class extends h{constructor(){super("consentmanager.net"),this.prehideSelectors=["#cmpbox,#cmpbox2"]}get hasSelfTest(){return!1}get isIntermediate(){return!1}async detectCmp(){return a("#cmpbox")}async detectPopup(){return c("#cmpbox .cmpmore","any")}async optOut(){return!!r(".cmpboxbtnno")||(a(".cmpwelcomeprpsbtn")?(r(".cmpwelcomeprpsbtn > a[aria-checked=true]",!0),r(".cmpboxbtnsave"),!0):(r(".cmpboxbtncustom"),await u(".cmptblbox",2e3),r(".cmptdchoice > a[aria-checked=true]",!0),r(".cmpboxbtnyescustomchoices"),!0))}async optIn(){return r(".cmpboxbtnyes")}},new class extends h{constructor(){super("Evidon")}get hasSelfTest(){return!1}get isIntermediate(){return!1}async detectCmp(){return a("#_evidon_banner")}async detectPopup(){return c("#_evidon_banner","any")}async optOut(){return r("#_evidon-decline-button")||(o(n(),["#evidon-prefdiag-overlay","#evidon-prefdiag-background"]),r("#_evidon-option-button"),await u("#evidon-prefdiag-overlay",5e3),r("#evidon-prefdiag-decline")),!0}async optIn(){return r("#_evidon-accept-button")}},new class extends h{constructor(){super("Onetrust"),this.prehideSelectors=["#onetrust-banner-sdk,#onetrust-consent-sdk,.optanon-alert-box-wrapper,.onetrust-pc-dark-filter,.js-consent-banner"]}get hasSelfTest(){return!0}get isIntermediate(){return!1}async detectCmp(){return a("#onetrust-banner-sdk,.optanon-alert-box-wrapper")}async detectPopup(){return c("#onetrust-banner-sdk,.optanon-alert-box-wrapper","all")}async optOut(){return a("#onetrust-pc-btn-handler")?r("#onetrust-pc-btn-handler"):r(".ot-sdk-show-settings,button.js-cookie-settings"),await u("#onetrust-consent-sdk",2e3),await l(1e3),r("#onetrust-consent-sdk input.category-switch-handler:checked,.js-editor-toggle-state:checked",!0),await u(".save-preference-btn-handler,.js-consent-save",2e3),r(".save-preference-btn-handler,.js-consent-save"),await s((()=>c("#onetrust-banner-sdk","none")),10,500),!0}async optIn(){return r("#onetrust-accept-btn-handler,.js-accept-cookies")}async test(){return await i("window.OnetrustActiveGroups.split(',').filter(s => s.length > 0).length <= 1")}}];class g{static setBase(e){g.base=e}static findElement(e,t=null,n=!1){let o=null;return o=null!=t?Array.from(t.querySelectorAll(e.selector)):null!=g.base?Array.from(g.base.querySelectorAll(e.selector)):Array.from(document.querySelectorAll(e.selector)),null!=e.textFilter&&(o=o.filter((t=>{let n=t.textContent.toLowerCase();if(Array.isArray(e.textFilter)){let t=!1;for(let o of e.textFilter)if(-1!==n.indexOf(o.toLowerCase())){t=!0;break}return t}if(null!=e.textFilter)return-1!==n.indexOf(e.textFilter.toLowerCase())}))),null!=e.styleFilters&&(o=o.filter((t=>{let n=window.getComputedStyle(t),o=!0;for(let t of e.styleFilters){let e=n[t.option];o=t.negated?o&&e!==t.value:o&&e===t.value}return o}))),null!=e.displayFilter&&(o=o.filter((t=>e.displayFilter?0!==t.offsetHeight:0===t.offsetHeight))),null!=e.iframeFilter&&(o=o.filter((t=>e.iframeFilter?window.location!==window.parent.location:window.location===window.parent.location))),null!=e.childFilter&&(o=o.filter((t=>{let n=g.base;g.setBase(t);let o=g.find(e.childFilter);return g.setBase(n),null!=o.target}))),n?o:(o.length>1&&console.warn("Multiple possible targets: ",o,e,t),o[0])}static find(e,t=!1){let n=[];if(null!=e.parent){let o=g.findElement(e.parent,null,t);if(null!=o){if(o instanceof Array)return o.forEach((o=>{let s=g.findElement(e.target,o,t);s instanceof Array?s.forEach((e=>{n.push({parent:o,target:e})})):n.push({parent:o,target:s})})),n;{let s=g.findElement(e.target,o,t);s instanceof Array?s.forEach((e=>{n.push({parent:o,target:e})})):n.push({parent:o,target:s})}}}else{let o=g.findElement(e.target,null,t);o instanceof Array?o.forEach((e=>{n.push({parent:null,target:e})})):n.push({parent:null,target:o})}return 0===n.length&&n.push({parent:null,target:null}),t?n:(1!==n.length&&console.warn("Multiple results found, even though multiple false",n),n[0])}}function C(e){const t=g.find(e);return"css"===e.type?!!t.target:"checkbox"===e.type?!!t.target&&t.target.checked:void 0}async function b(e,t){switch(e.type){case"click":return async function(e){const t=g.find(e);null!=t.target&&t.target.click();return _(0)}(e);case"list":return async function(e,t){for(let n of e.actions)await b(n,t)}(e,t);case"consent":return async function(e,t){for(const n of e.consents){const e=-1!==t.indexOf(n.type);if(n.matcher&&n.toggleAction){C(n.matcher)!==e&&await b(n.toggleAction)}else e?await b(n.trueAction):await b(n.falseAction)}}(e,t);case"ifcss":return async function(e,t){g.find(e).target?e.falseAction&&await b(e.falseAction,t):e.trueAction&&await b(e.trueAction,t)}(e,t);case"waitcss":return async function(e){await new Promise((t=>{let n=e.retries||10;const o=e.waitTime||250,s=()=>{const i=g.find(e);(e.negated&&i.target||!e.negated&&!i.target)&&n>0?(n-=1,setTimeout(s,o)):t()};s()}))}(e);case"foreach":return async function(e,t){const n=g.find(e,!0),o=g.base;for(const o of n)o.target&&(g.setBase(o.target),await b(e.action,t));g.setBase(o)}(e,t);case"hide":return async function(e){const t=g.find(e);t.target&&t.target.classList.add("Autoconsent-Hidden")}(e);case"slide":return async function(e){const t=g.find(e),n=g.find(e.dragTarget);if(t.target){let e=t.target.getBoundingClientRect(),o=n.target.getBoundingClientRect(),s=o.top-e.top,i=o.left-e.left;"y"===this.config.axis.toLowerCase()&&(i=0),"x"===this.config.axis.toLowerCase()&&(s=0);let r=window.screenX+e.left+e.width/2,a=window.screenY+e.top+e.height/2,c=e.left+e.width/2,u=e.top+e.height/2,l=document.createEvent("MouseEvents");l.initMouseEvent("mousedown",!0,!0,window,0,r,a,c,u,!1,!1,!1,!1,0,t.target);let d=document.createEvent("MouseEvents");d.initMouseEvent("mousemove",!0,!0,window,0,r+i,a+s,c+i,u+s,!1,!1,!1,!1,0,t.target);let p=document.createEvent("MouseEvents");p.initMouseEvent("mouseup",!0,!0,window,0,r+i,a+s,c+i,u+s,!1,!1,!1,!1,0,t.target),t.target.dispatchEvent(l),await this.waitTimeout(10),t.target.dispatchEvent(d),await this.waitTimeout(10),t.target.dispatchEvent(p)}}(e);case"close":return async function(e){window.close()}();case"wait":return async function(e){await _(e.waitTime)}(e);case"eval":return async function(e){return console.log("eval!",e.code),new Promise((t=>{try{e.async?(window.eval(e.code),setTimeout((()=>{t(window.eval("window.__consentCheckResult"))}),e.timeout||250)):t(window.eval(e.code))}catch(n){console.warn("eval error",n,e.code),t(!1)}}))}(e);default:throw"Unknown action type: "+e.type}}g.base=null;function _(e){return new Promise((t=>{setTimeout((()=>{t()}),e)}))}class v{constructor(e,t){this.name=e,this.config=t,this.methods=new Map,this.runContext=p,t.methods.forEach((e=>{e.action&&this.methods.set(e.name,e.action)})),this.hasSelfTest=!1}get isIntermediate(){return!1}checkRunContext(){return!0}async detectCmp(){return this.config.detectors.map((e=>C(e.presentMatcher))).some((e=>!!e))}async detectPopup(){return this.config.detectors.map((e=>C(e.showingMatcher))).some((e=>!!e))}async executeAction(e,t){return!this.methods.has(e)||b(this.methods.get(e),t)}async optOut(){return await this.executeAction("HIDE_CMP"),await this.executeAction("OPEN_OPTIONS"),await this.executeAction("HIDE_CMP"),await this.executeAction("DO_CONSENT",[]),await this.executeAction("SAVE_CONSENT"),!0}async optIn(){return await this.executeAction("HIDE_CMP"),await this.executeAction("OPEN_OPTIONS"),await this.executeAction("HIDE_CMP"),await this.executeAction("DO_CONSENT",["D","A","B","E","F","X"]),await this.executeAction("SAVE_CONSENT"),!0}async openCmp(){return await this.executeAction("HIDE_CMP"),await this.executeAction("OPEN_OPTIONS"),!0}async test(){return!0}}class k{constructor(e,n=null,o=null){if(this.rules=[],this.foundCmp=null,t.sendContentMessage=e,this.sendContentMessage=e,this.rules=[...y],n)this.initialize(n,o);else{o&&this.parseRules(o);e({type:"init",url:window.location.href})}}initialize(e,t){if(this.config=e,e.enabled){if(t&&this.parseRules(t),e.disabledCmps?.length>0&&this.disableCMPs(e.disabledCmps),e.enablePrehide)if(document.documentElement)this.prehideElements();else{const e=()=>{window.removeEventListener("DOMContentLoaded",e),this.prehideElements()};window.addEventListener("DOMContentLoaded",e)}if("loading"===document.readyState){const e=()=>{window.removeEventListener("DOMContentLoaded",e),this.start()};window.addEventListener("DOMContentLoaded",e)}else this.start()}}parseRules(e){Object.keys(e.consentomatic).forEach((t=>{this.addConsentomaticCMP(t,e.consentomatic[t])})),e.autoconsent.forEach((e=>{this.addCMP(e)}))}addCMP(e){this.rules.push(w(e))}disableCMPs(e){this.rules=this.rules.filter((t=>!e.includes(t.name)))}addConsentomaticCMP(e,t){this.rules.push(new v(`com_${e}`,t))}start(){window.requestIdleCallback?window.requestIdleCallback((()=>this._start()),{timeout:500}):this._start()}async _start(){const e=await this.findCmp(this.config.detectRetries);if(e){this.sendContentMessage({type:"cmpDetected",url:location.href,cmp:e.name});return await this.waitForPopup(e)?(this.foundCmp=e,this.sendContentMessage({type:"popupFound",cmp:e.name,url:location.href}),"optOut"===this.config.autoAction?await this.doOptOut():"optIn"!==this.config.autoAction||await this.doOptIn()):(this.config.enablePrehide&&d(),!1)}return this.config.enablePrehide&&d(),!1}async findCmp(e){let t=null;const n=[];for(const e of this.rules)try{if(!e.checkRunContext())continue;await e.detectCmp()&&(n.push(e),t||(t=e))}catch(e){}if(n.length>1){const e={msg:"Found multiple CMPs, check the detection rules.",cmps:n.map((e=>e.name))};this.sendContentMessage({type:"autoconsentError",details:e})}return!t&&e>0?new Promise((t=>{setTimeout((async()=>{const n=this.findCmp(e-1);t(n)}),500)})):t}async doOptOut(){let e;return e=!!this.foundCmp&&await this.foundCmp.optOut(),this.config.enablePrehide&&d(),this.sendContentMessage({type:"optOutResult",cmp:this.foundCmp?this.foundCmp.name:"none",result:e,scheduleSelfTest:this.foundCmp&&this.foundCmp.hasSelfTest,url:location.href}),e&&!this.foundCmp.isIntermediate&&this.sendContentMessage({type:"autoconsentDone",cmp:this.foundCmp.name,url:location.href}),e}async doOptIn(){let e;return e=!!this.foundCmp&&await this.foundCmp.optIn(),this.config.enablePrehide&&d(),this.sendContentMessage({type:"optInResult",cmp:this.foundCmp?this.foundCmp.name:"none",result:e,scheduleSelfTest:!1,url:location.href}),e&&!this.foundCmp.isIntermediate&&this.sendContentMessage({type:"autoconsentDone",cmp:this.foundCmp.name,url:location.href}),e}async doSelfTest(){let e;return e=!!this.foundCmp&&await this.foundCmp.test(),this.sendContentMessage({type:"selfTestResult",cmp:this.foundCmp?this.foundCmp.name:"none",result:e,url:location.href}),e}async waitForPopup(e,t=5,n=500){const o=await e.detectPopup();return!o&&t>0?new Promise((o=>setTimeout((()=>o(this.waitForPopup(e,t-1,n))),n))):o}prehideElements(){return function(e){return o(n("autoconsent-prehide"),e,"opacity")}(this.rules.reduce(((e,t)=>t.prehideSelectors?[...e,...t.prehideSelectors]:e),["#didomi-popup,.didomi-popup-container,.didomi-popup-notice,.didomi-consent-popup-preferences,#didomi-notice,.didomi-popup-backdrop,.didomi-screen-medium"]))}async receiveMessageCallback(e){switch(e.type){case"initResp":this.initialize(e.config,e.rules);break;case"optOut":await this.doOptOut();break;case"selfTest":await this.doSelfTest();break;case"evalResp":!function(e,n){const o=t.pending.get(e);o?(t.pending.delete(e),o.timer&&window.clearTimeout(o.timer),o.resolve(n)):console.warn("no eval #",e)}(e.id,e.result)}}}export{w as createAutoCMP,k as default,y as rules};
|