@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.
Files changed (187) hide show
  1. package/.eslintrc.cjs +14 -0
  2. package/.vscode/.idea/.vscode.iml +9 -0
  3. package/.vscode/.idea/modules.xml +8 -0
  4. package/.vscode/.idea/workspace.xml +28 -0
  5. package/.vscode/settings.json +7 -0
  6. package/Jenkinsfile +68 -39
  7. package/api.md +104 -0
  8. package/dist/addon-firefox/background.bundle.js +1 -0
  9. package/dist/addon-firefox/content.bundle.js +1 -0
  10. package/dist/addon-firefox/icons/cog.png +0 -0
  11. package/dist/addon-firefox/icons/cookie-idle.png +0 -0
  12. package/dist/addon-firefox/icons/cookie.png +0 -0
  13. package/dist/addon-firefox/icons/party.png +0 -0
  14. package/dist/addon-firefox/icons/tick.png +0 -0
  15. package/dist/addon-firefox/icons/verified.png +0 -0
  16. package/dist/addon-firefox/rules.json +4167 -0
  17. package/dist/addon-mv3/background.bundle.js +1 -0
  18. package/dist/addon-mv3/content.bundle.js +1 -0
  19. package/dist/addon-mv3/icons/cog.png +0 -0
  20. package/dist/addon-mv3/icons/cookie-idle.png +0 -0
  21. package/dist/addon-mv3/icons/cookie.png +0 -0
  22. package/dist/addon-mv3/icons/party.png +0 -0
  23. package/dist/addon-mv3/icons/tick.png +0 -0
  24. package/dist/addon-mv3/icons/verified.png +0 -0
  25. package/dist/addon-mv3/rules.json +4167 -0
  26. package/dist/autoconsent.cjs.js +1 -1383
  27. package/dist/autoconsent.esm.js +1 -1375
  28. package/dist/autoconsent.playwright.js +1 -0
  29. package/lib/cmps/all.ts +15 -10
  30. package/lib/cmps/base.ts +95 -90
  31. package/lib/cmps/consentmanager.ts +31 -19
  32. package/lib/cmps/consentomatic.ts +89 -0
  33. package/lib/cmps/cookiebot.ts +62 -53
  34. package/lib/cmps/evidon.ts +29 -18
  35. package/lib/cmps/onetrust.ts +32 -20
  36. package/lib/cmps/sourcepoint-frame.ts +104 -0
  37. package/lib/cmps/sourcepoint-top.ts +47 -0
  38. package/lib/cmps/trustarc-frame.ts +115 -0
  39. package/lib/cmps/trustarc-top.ts +97 -0
  40. package/lib/consentomatic/index.ts +233 -70
  41. package/lib/{web/consentomatic → consentomatic}/tools.ts +0 -0
  42. package/lib/eval-handler.ts +58 -0
  43. package/lib/index.ts +0 -2
  44. package/lib/messages.ts +100 -0
  45. package/lib/rule-executors.ts +108 -0
  46. package/lib/rules.ts +82 -0
  47. package/lib/types.ts +35 -0
  48. package/lib/utils.ts +64 -0
  49. package/lib/web.ts +288 -74
  50. package/package.json +20 -16
  51. package/playwright/content.ts +21 -0
  52. package/playwright/runner.ts +162 -0
  53. package/playwright.config.ts +7 -0
  54. package/readme.md +61 -47
  55. package/rollup.config.js +30 -16
  56. package/rules/autoconsent/192.json +17 -0
  57. package/rules/autoconsent/ausopen.json +8 -0
  58. package/rules/autoconsent/baden-wuerttemberg-de.json +7 -3
  59. package/rules/autoconsent/bing.json +14 -0
  60. package/rules/autoconsent/bundesregierung-de.json +5 -1
  61. package/rules/autoconsent/cc-banner.json +0 -1
  62. package/rules/autoconsent/cookie-law-info.json +1 -1
  63. package/rules/autoconsent/cookie-notice.json +1 -2
  64. package/rules/autoconsent/cookieconsent.json +5 -6
  65. package/rules/autoconsent/destatis-de.json +2 -2
  66. package/rules/autoconsent/dunelm.json +18 -0
  67. package/rules/autoconsent/etsy.json +4 -3
  68. package/rules/autoconsent/eu-cookie-compliance.json +0 -1
  69. package/rules/autoconsent/gov-uk.json +10 -0
  70. package/rules/autoconsent/hl-co-uk.json +8 -9
  71. package/rules/autoconsent/johnlewis.json +5 -2
  72. package/rules/autoconsent/marksandspencer.json +8 -0
  73. package/rules/autoconsent/mediamarkt-de.json +1 -1
  74. package/rules/autoconsent/microsoft.json +1 -1
  75. package/rules/autoconsent/notice-cookie.json +0 -1
  76. package/rules/autoconsent/osano.json +4 -2
  77. package/rules/autoconsent/{paypal-de.json → paypal.json} +6 -2
  78. package/rules/autoconsent/snigel.json +2 -1
  79. package/rules/autoconsent/tealium.json +4 -5
  80. package/rules/autoconsent/thefreedictionary.json +1 -1
  81. package/rules/autoconsent/uswitch.json +8 -0
  82. package/rules/autoconsent/waitrose.json +28 -0
  83. package/rules/autoconsent/wetransfer.json +7 -0
  84. package/rules/rules.json +345 -45
  85. package/tests/192.spec.ts +7 -0
  86. package/tests/arzt-auskunft.spec.ts +1 -1
  87. package/tests/asus.spec.ts +1 -1
  88. package/tests/ausopen.spec.ts +7 -0
  89. package/tests/aws.amazon.spec.ts +1 -1
  90. package/tests/baden-wuerttemberg.spec.ts +1 -1
  91. package/tests/borlabs.spec.ts +1 -1
  92. package/tests/bundesregierung.spec.ts +5 -2
  93. package/tests/ccbanner.spec.ts +1 -1
  94. package/tests/consentmanager.spec.ts +3 -3
  95. package/tests/cookiebot.spec.ts +8 -1
  96. package/tests/cookieconsent.spec.ts +1 -1
  97. package/tests/cookielawinfo.spec.ts +1 -1
  98. package/tests/cookienotice.spec.ts +1 -1
  99. package/tests/corona-in-zahlen.spec.ts +1 -1
  100. package/tests/deepl.spec.ts +1 -1
  101. package/tests/destatis.spec.ts +1 -1
  102. package/tests/didomi.spec.ts +7 -3
  103. package/tests/drupal.spec.ts +8 -0
  104. package/tests/dunelm.spec.ts +7 -0
  105. package/tests/etsy.spec.ts +1 -1
  106. package/tests/eu-cookie-compliance-banner.spec.ts +1 -1
  107. package/tests/evidon.spec.ts +7 -2
  108. package/tests/fundingchoices.spec.ts +2 -1
  109. package/tests/gov-uk.spec.ts +9 -0
  110. package/tests/hl-co-uk.spec.ts +1 -1
  111. package/tests/hubspot.spec.ts +1 -1
  112. package/tests/ionos.spec.ts +1 -1
  113. package/tests/johnlewis.spec.ts +2 -2
  114. package/tests/klaro.spec.ts +1 -1
  115. package/tests/marksandspencer.spec.ts +7 -0
  116. package/tests/mediamarkt.spec.ts +1 -1
  117. package/tests/metoffice-gov-uk.spec.ts +1 -1
  118. package/tests/microsoft.spec.ts +1 -1
  119. package/tests/moneysavingexpert.spec.ts +1 -1
  120. package/tests/motor-talk.spec.ts +1 -1
  121. package/tests/national-lottery.spec.ts +1 -1
  122. package/tests/netflix.spec.ts +1 -1
  123. package/tests/nhs.spec.ts +1 -1
  124. package/tests/notice-cookie.spec.ts +1 -1
  125. package/tests/obi.spec.ts +1 -1
  126. package/tests/oil.spec.ts +2 -2
  127. package/tests/onetrust.spec.ts +27 -2
  128. package/tests/osano.spec.ts +1 -1
  129. package/tests/otto.spec.ts +1 -1
  130. package/tests/paypal.spec.ts +8 -6
  131. package/tests/quantcast.spec.ts +5 -2
  132. package/tests/snigel.spec.ts +1 -1
  133. package/tests/sourcepoint.spec.ts +8 -8
  134. package/tests/springer.spec.ts +2 -2
  135. package/tests/steampowered.spec.ts +1 -1
  136. package/tests/tealium.spec.ts +1 -1
  137. package/tests/testcmp.spec.ts +1 -1
  138. package/tests/thalia.spec.ts +1 -1
  139. package/tests/thefreedictionary.spec.ts +1 -1
  140. package/tests/trustarc.spec.ts +26 -3
  141. package/tests/usercentrics-1.spec.ts +1 -1
  142. package/tests/uswitch.spec.ts +7 -0
  143. package/tests/vodafone.spec.ts +1 -1
  144. package/tests/waitrose.spec.ts +7 -0
  145. package/tests/wetransfer.spec.ts +7 -0
  146. package/tests/wordpressgdpr.spec.ts +2 -2
  147. package/tests/xing.spec.ts +1 -1
  148. package/tsconfig.json +2 -2
  149. package/update_version.js +10 -6
  150. package/.eslintrc +0 -12
  151. package/cosmetics/rules.json +0 -110
  152. package/dist/autoconsent.puppet.js +0 -1074
  153. package/lib/cmps/all.js +0 -19
  154. package/lib/cmps/base.js +0 -174
  155. package/lib/cmps/consentmanager.js +0 -31
  156. package/lib/cmps/cookiebot.js +0 -73
  157. package/lib/cmps/evidon.js +0 -26
  158. package/lib/cmps/onetrust.js +0 -34
  159. package/lib/cmps/sourcepoint.js +0 -82
  160. package/lib/cmps/sourcepoint.ts +0 -95
  161. package/lib/cmps/trustarc.js +0 -106
  162. package/lib/cmps/trustarc.ts +0 -147
  163. package/lib/config.js +0 -1
  164. package/lib/consentomatic/index.js +0 -52
  165. package/lib/detector.js +0 -33
  166. package/lib/detector.ts +0 -34
  167. package/lib/hider.js +0 -13
  168. package/lib/hider.ts +0 -16
  169. package/lib/index.js +0 -4
  170. package/lib/messages.d.ts +0 -61
  171. package/lib/node.js +0 -35
  172. package/lib/node.ts +0 -43
  173. package/lib/puppet/tab.js +0 -121
  174. package/lib/puppet/tab.ts +0 -146
  175. package/lib/rules.d.ts +0 -80
  176. package/lib/tabwrapper.js +0 -67
  177. package/lib/tabwrapper.ts +0 -74
  178. package/lib/types.d.ts +0 -61
  179. package/lib/web/consentomatic/index.ts +0 -249
  180. package/lib/web/content-utils.js +0 -29
  181. package/lib/web/content-utils.ts +0 -31
  182. package/lib/web/content.js +0 -89
  183. package/lib/web/content.ts +0 -80
  184. package/lib/web/tab.js +0 -112
  185. package/lib/web/tab.ts +0 -178
  186. package/lib/web.js +0 -95
  187. package/tests/runner.ts +0 -61
@@ -1,1074 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const enableLogs = false; // change this to enable debug logs
6
-
7
- /* eslint-disable no-restricted-syntax,no-await-in-loop,no-underscore-dangle */
8
- async function waitFor(predicate, maxTimes, interval) {
9
- let result = await predicate();
10
- if (!result && maxTimes > 0) {
11
- return new Promise((resolve) => {
12
- setTimeout(async () => {
13
- resolve(waitFor(predicate, maxTimes - 1, interval));
14
- }, interval);
15
- });
16
- }
17
- return Promise.resolve(result);
18
- }
19
- async function success(action) {
20
- const result = await action;
21
- if (!result) {
22
- throw new Error(`Action failed: ${action} ${result}`);
23
- }
24
- return result;
25
- }
26
- class AutoConsentBase {
27
- constructor(name) {
28
- this.hasSelfTest = true;
29
- this.name = name;
30
- }
31
- detectCmp(tab) {
32
- throw new Error('Not Implemented');
33
- }
34
- async detectPopup(tab) {
35
- return false;
36
- }
37
- detectFrame(tab, frame) {
38
- return false;
39
- }
40
- optOut(tab) {
41
- throw new Error('Not Implemented');
42
- }
43
- optIn(tab) {
44
- throw new Error('Not Implemented');
45
- }
46
- openCmp(tab) {
47
- throw new Error('Not Implemented');
48
- }
49
- async test(tab) {
50
- // try IAB by default
51
- return Promise.resolve(true);
52
- }
53
- }
54
- async function evaluateRule(rule, tab) {
55
- if (rule.frame && !tab.frame) {
56
- await waitFor(() => Promise.resolve(!!tab.frame), 10, 500);
57
- }
58
- const frameId = rule.frame && tab.frame ? tab.frame.id : undefined;
59
- const results = [];
60
- if (rule.exists) {
61
- results.push(tab.elementExists(rule.exists, frameId));
62
- }
63
- if (rule.visible) {
64
- results.push(tab.elementsAreVisible(rule.visible, rule.check, frameId));
65
- }
66
- if (rule.eval) {
67
- results.push(new Promise(async (resolve) => {
68
- // catch eval error silently
69
- try {
70
- resolve(await tab.eval(rule.eval, frameId));
71
- }
72
- catch (e) {
73
- resolve(false);
74
- }
75
- }));
76
- }
77
- if (rule.waitFor) {
78
- results.push(tab.waitForElement(rule.waitFor, rule.timeout || 10000, frameId));
79
- }
80
- if (rule.click) {
81
- if (rule.all === true) {
82
- results.push(tab.clickElements(rule.click, frameId));
83
- }
84
- else {
85
- results.push(tab.clickElement(rule.click, frameId));
86
- }
87
- }
88
- if (rule.waitForThenClick) {
89
- results.push(tab.waitForElement(rule.waitForThenClick, rule.timeout || 10000, frameId)
90
- .then(() => tab.clickElement(rule.waitForThenClick, frameId)));
91
- }
92
- if (rule.wait) {
93
- results.push(tab.wait(rule.wait));
94
- }
95
- if (rule.goto) {
96
- results.push(tab.goto(rule.goto));
97
- }
98
- if (rule.hide) {
99
- results.push(tab.hideElements(rule.hide, frameId));
100
- }
101
- if (rule.undoHide) {
102
- results.push(tab.undoHideElements(frameId));
103
- }
104
- if (rule.waitForFrame) {
105
- results.push(waitFor(() => !!tab.frame, 40, 500));
106
- }
107
- // boolean and of results
108
- return (await Promise.all(results)).reduce((a, b) => a && b, true);
109
- }
110
- class AutoConsent extends AutoConsentBase {
111
- constructor(config) {
112
- super(config.name);
113
- this.config = config;
114
- }
115
- get prehideSelectors() {
116
- return this.config.prehideSelectors;
117
- }
118
- get isHidingRule() {
119
- return this.config.isHidingRule;
120
- }
121
- async _runRulesParallel(tab, rules) {
122
- const detections = await Promise.all(rules.map(rule => evaluateRule(rule, tab)));
123
- return detections.every(r => !!r);
124
- }
125
- async _runRulesSequentially(tab, rules) {
126
- for (const rule of rules) {
127
- const result = await evaluateRule(rule, tab);
128
- if (!result && !rule.optional) {
129
- return false;
130
- }
131
- }
132
- return true;
133
- }
134
- async detectCmp(tab) {
135
- if (this.config.detectCmp) {
136
- return this._runRulesParallel(tab, this.config.detectCmp);
137
- }
138
- return false;
139
- }
140
- async detectPopup(tab) {
141
- if (this.config.detectPopup) {
142
- return this._runRulesParallel(tab, this.config.detectPopup);
143
- }
144
- return false;
145
- }
146
- detectFrame(tab, frame) {
147
- if (this.config.frame) {
148
- return frame.url.startsWith(this.config.frame);
149
- }
150
- return false;
151
- }
152
- async optOut(tab) {
153
- if (this.config.optOut) {
154
- return this._runRulesSequentially(tab, this.config.optOut);
155
- }
156
- return false;
157
- }
158
- async optIn(tab) {
159
- if (this.config.optIn) {
160
- return this._runRulesSequentially(tab, this.config.optIn);
161
- }
162
- return false;
163
- }
164
- async openCmp(tab) {
165
- if (this.config.openCmp) {
166
- return this._runRulesSequentially(tab, this.config.openCmp);
167
- }
168
- return false;
169
- }
170
- async test(tab) {
171
- if (this.config.test) {
172
- return this._runRulesSequentially(tab, this.config.test);
173
- }
174
- return super.test(tab);
175
- }
176
- }
177
-
178
- /**
179
- * This code is in most parts copied from https://github.com/cavi-au/Consent-O-Matic/blob/master/Extension/Tools.js
180
- * which is licened under the MIT.
181
- */
182
- class Tools {
183
- static setBase(base) {
184
- Tools.base = base;
185
- }
186
- static findElement(options, parent = null, multiple = false) {
187
- let possibleTargets = null;
188
- if (parent != null) {
189
- possibleTargets = Array.from(parent.querySelectorAll(options.selector));
190
- }
191
- else {
192
- if (Tools.base != null) {
193
- possibleTargets = Array.from(Tools.base.querySelectorAll(options.selector));
194
- }
195
- else {
196
- possibleTargets = Array.from(document.querySelectorAll(options.selector));
197
- }
198
- }
199
- if (options.textFilter != null) {
200
- possibleTargets = possibleTargets.filter(possibleTarget => {
201
- let textContent = possibleTarget.textContent.toLowerCase();
202
- if (Array.isArray(options.textFilter)) {
203
- let foundText = false;
204
- for (let text of options.textFilter) {
205
- if (textContent.indexOf(text.toLowerCase()) !== -1) {
206
- foundText = true;
207
- break;
208
- }
209
- }
210
- return foundText;
211
- }
212
- else if (options.textFilter != null) {
213
- return textContent.indexOf(options.textFilter.toLowerCase()) !== -1;
214
- }
215
- });
216
- }
217
- if (options.styleFilters != null) {
218
- possibleTargets = possibleTargets.filter(possibleTarget => {
219
- let styles = window.getComputedStyle(possibleTarget);
220
- let keep = true;
221
- for (let styleFilter of options.styleFilters) {
222
- let option = styles[styleFilter.option];
223
- if (styleFilter.negated) {
224
- keep = keep && option !== styleFilter.value;
225
- }
226
- else {
227
- keep = keep && option === styleFilter.value;
228
- }
229
- }
230
- return keep;
231
- });
232
- }
233
- if (options.displayFilter != null) {
234
- possibleTargets = possibleTargets.filter(possibleTarget => {
235
- if (options.displayFilter) {
236
- //We should be displayed
237
- return possibleTarget.offsetHeight !== 0;
238
- }
239
- else {
240
- //We should not be displayed
241
- return possibleTarget.offsetHeight === 0;
242
- }
243
- });
244
- }
245
- if (options.iframeFilter != null) {
246
- possibleTargets = possibleTargets.filter(possibleTarget => {
247
- if (options.iframeFilter) {
248
- //We should be inside an iframe
249
- return window.location !== window.parent.location;
250
- }
251
- else {
252
- //We should not be inside an iframe
253
- return window.location === window.parent.location;
254
- }
255
- });
256
- }
257
- if (options.childFilter != null) {
258
- possibleTargets = possibleTargets.filter(possibleTarget => {
259
- let oldBase = Tools.base;
260
- Tools.setBase(possibleTarget);
261
- let childResults = Tools.find(options.childFilter);
262
- Tools.setBase(oldBase);
263
- return childResults.target != null;
264
- });
265
- }
266
- if (multiple) {
267
- return possibleTargets;
268
- }
269
- else {
270
- if (possibleTargets.length > 1) {
271
- console.warn("Multiple possible targets: ", possibleTargets, options, parent);
272
- }
273
- return possibleTargets[0];
274
- }
275
- }
276
- static find(options, multiple = false) {
277
- let results = [];
278
- if (options.parent != null) {
279
- let parent = Tools.findElement(options.parent, null, multiple);
280
- if (parent != null) {
281
- if (parent instanceof Array) {
282
- parent.forEach(p => {
283
- let targets = Tools.findElement(options.target, p, multiple);
284
- if (targets instanceof Array) {
285
- targets.forEach(target => {
286
- results.push({
287
- parent: p,
288
- target: target
289
- });
290
- });
291
- }
292
- else {
293
- results.push({
294
- parent: p,
295
- target: targets
296
- });
297
- }
298
- });
299
- return results;
300
- }
301
- else {
302
- let targets = Tools.findElement(options.target, parent, multiple);
303
- if (targets instanceof Array) {
304
- targets.forEach(target => {
305
- results.push({
306
- parent: parent,
307
- target: target
308
- });
309
- });
310
- }
311
- else {
312
- results.push({
313
- parent: parent,
314
- target: targets
315
- });
316
- }
317
- }
318
- }
319
- }
320
- else {
321
- let targets = Tools.findElement(options.target, null, multiple);
322
- if (targets instanceof Array) {
323
- targets.forEach(target => {
324
- results.push({
325
- parent: null,
326
- target: target
327
- });
328
- });
329
- }
330
- else {
331
- results.push({
332
- parent: null,
333
- target: targets
334
- });
335
- }
336
- }
337
- if (results.length === 0) {
338
- results.push({
339
- parent: null,
340
- target: null
341
- });
342
- }
343
- if (multiple) {
344
- return results;
345
- }
346
- else {
347
- if (results.length !== 1) {
348
- console.warn("Multiple results found, even though multiple false", results);
349
- }
350
- return results[0];
351
- }
352
- }
353
- }
354
- Tools.base = null;
355
-
356
- function matches(config) {
357
- const result = Tools.find(config);
358
- if (config.type === "css") {
359
- return !!result.target;
360
- }
361
- else if (config.type === "checkbox") {
362
- return !!result.target && result.target.checked;
363
- }
364
- }
365
-
366
- // get or create a style container for CSS overrides
367
- function getStyleElementUtil() {
368
- const styleOverrideElementId = "autoconsent-css-rules";
369
- const styleSelector = `style#${styleOverrideElementId}`;
370
- const existingElement = document.querySelector(styleSelector);
371
- if (existingElement && existingElement instanceof HTMLStyleElement) {
372
- return existingElement;
373
- }
374
- else {
375
- const parent = document.head ||
376
- document.getElementsByTagName("head")[0] ||
377
- document.documentElement;
378
- const css = document.createElement("style");
379
- css.id = styleOverrideElementId;
380
- parent.appendChild(css);
381
- return css;
382
- }
383
- }
384
- // hide elements with a CSS rule
385
- function hideElementsUtil(selectors, method) {
386
- const hidingSnippet = method === 'display' ? `display: none` : `opacity: 0`;
387
- const rule = `${selectors.join(",")} { ${hidingSnippet} !important; z-index: -1 !important; pointer-events: none !important; } `;
388
- const styleEl = getStyleElementUtil();
389
- if (styleEl instanceof HTMLStyleElement) {
390
- styleEl.innerText += rule;
391
- return selectors.length > 0;
392
- }
393
- return false;
394
- }
395
-
396
- const DEBUG = false;
397
- class Tab {
398
- constructor(page, url, frames) {
399
- // puppeteer doesn't have tab IDs
400
- this.id = 1;
401
- this.page = page;
402
- this.url = url;
403
- this.frames = frames;
404
- this._utilsSnippet = `
405
- ${getStyleElementUtil.toString()}
406
- ${hideElementsUtil.toString()}
407
- `;
408
- }
409
- async elementExists(selector, frameId = 0) {
410
- const elements = await this.frames[frameId].$$(selector);
411
- return elements.length > 0;
412
- }
413
- async clickElement(selector, frameId = 0) {
414
- if (await this.elementExists(selector, frameId)) {
415
- try {
416
- const result = await this.frames[frameId].evaluate((s) => {
417
- try {
418
- document.querySelector(s).click();
419
- return true;
420
- }
421
- catch (e) {
422
- return e.toString();
423
- }
424
- }, selector);
425
- DEBUG && console.log('[click]', selector, result);
426
- return result;
427
- }
428
- catch (e) {
429
- return false;
430
- }
431
- }
432
- return false;
433
- }
434
- async clickElements(selector, frameId = 0) {
435
- const elements = await this.frames[frameId].$$(selector);
436
- await this.frames[frameId].evaluate((s) => {
437
- const elem = document.querySelectorAll(s);
438
- elem.forEach(e => e.click());
439
- }, selector);
440
- return true;
441
- }
442
- async elementsAreVisible(selector, check, frameId = 0) {
443
- if (!await this.elementExists(selector, frameId)) {
444
- return false;
445
- }
446
- const visible = await this.frames[frameId].$$eval(selector, (nodes) => nodes.map((n) => n.offsetParent !== null || window.getComputedStyle(n).display !== "none"));
447
- if (visible.length === 0) {
448
- return false;
449
- }
450
- else if (check === 'any') {
451
- return visible.some(r => r);
452
- }
453
- else if (check === 'none') {
454
- return visible.every(r => !r);
455
- }
456
- return visible.every(r => r);
457
- }
458
- async getAttribute(selector, attribute, frameId = 0) {
459
- const elem = await this.frames[frameId].$(selector);
460
- if (elem) {
461
- return (await elem.getProperty(attribute)).jsonValue();
462
- }
463
- }
464
- async eval(script, frameId = 0) {
465
- const result = await this.frames[frameId].evaluate(script);
466
- return result;
467
- }
468
- async waitForElement(selector, timeout, frameId = 0) {
469
- const interval = 200;
470
- const times = Math.ceil(timeout / interval);
471
- return waitFor(() => this.elementExists(selector, frameId), times, interval);
472
- }
473
- async waitForThenClick(selector, timeout, frameId = 0) {
474
- if (await this.waitForElement(selector, timeout, frameId)) {
475
- return await this.clickElement(selector, frameId);
476
- }
477
- return false;
478
- }
479
- async hideElements(selectors, frameId = 0, method = 'display') {
480
- return await this.frames[frameId].evaluate(`(() => {
481
- ${this._utilsSnippet}
482
- return hideElementsUtil(${JSON.stringify(selectors)}, '${method}');
483
- })()`);
484
- }
485
- undoHideElements(frameId) {
486
- return Promise.resolve(true);
487
- }
488
- async goto(url) {
489
- return this.page.goto(url);
490
- }
491
- wait(ms) {
492
- return new Promise((resolve) => {
493
- setTimeout(() => resolve(true), ms);
494
- });
495
- }
496
- matches(options) {
497
- const script = `(() => {
498
- const Tools = ${Tools.toString()};
499
- const matches = ${matches.toString()};
500
- return matches(${JSON.stringify(options)})
501
- })();
502
- `;
503
- return this.frames[0].evaluate(script);
504
- }
505
- executeAction(config, param) {
506
- throw new Error("Method not implemented.");
507
- }
508
- }
509
-
510
- async function detectDialog(tab, retries, rules) {
511
- let breakEarly = false;
512
- const found = await new Promise(async (resolve) => {
513
- let earlyReturn = false;
514
- await Promise.all(rules.map(async (r, index) => {
515
- try {
516
- if (await r.detectCmp(tab)) {
517
- earlyReturn = true;
518
- enableLogs && console.log(`Found CMP in [${tab.id}]: ${r.name}`);
519
- resolve(index);
520
- }
521
- }
522
- catch (e) {
523
- breakEarly = true;
524
- }
525
- }));
526
- if (!earlyReturn) {
527
- resolve(-1);
528
- }
529
- });
530
- if (found === -1 && retries > 0 && !breakEarly) {
531
- return new Promise((resolve) => {
532
- setTimeout(async () => {
533
- const result = detectDialog(tab, retries - 1, rules);
534
- resolve(result);
535
- }, 500);
536
- });
537
- }
538
- return found > -1 ? rules[found] : null;
539
- }
540
-
541
- class TabConsent {
542
- constructor(tab, ruleCheckPromise) {
543
- this.tab = tab;
544
- this.optOutStatus = null;
545
- this.checked = ruleCheckPromise;
546
- ruleCheckPromise.then(rule => this.rule = rule);
547
- }
548
- getCMPName() {
549
- if (this.rule) {
550
- return this.rule.name;
551
- }
552
- return null;
553
- }
554
- async isPopupOpen(retries = 1, interval = 1000) {
555
- const isOpen = await this.rule.detectPopup(this.tab);
556
- if (!isOpen && retries > 0) {
557
- return new Promise((resolve) => setTimeout(() => resolve(this.isPopupOpen(retries - 1, interval)), interval));
558
- }
559
- return isOpen;
560
- }
561
- async doOptOut() {
562
- try {
563
- enableLogs && console.log(`doing opt out ${this.getCMPName()} in tab ${this.tab.id}`);
564
- this.optOutStatus = await this.rule.optOut(this.tab);
565
- return this.optOutStatus;
566
- }
567
- catch (e) {
568
- console.error('error during opt out', e);
569
- this.optOutStatus = e;
570
- throw e;
571
- }
572
- finally {
573
- if (!this.rule.isHidingRule) {
574
- if (this.getCMPName().startsWith('com_')) {
575
- this.tab.wait(5000).then(() => this.tab.undoHideElements());
576
- }
577
- else {
578
- await this.tab.undoHideElements();
579
- }
580
- }
581
- }
582
- }
583
- async doOptIn() {
584
- try {
585
- return this.rule.optIn(this.tab);
586
- }
587
- finally {
588
- if (!this.rule.isHidingRule) {
589
- await this.tab.undoHideElements();
590
- }
591
- }
592
- }
593
- hasTest() {
594
- return !!this.rule.hasSelfTest;
595
- }
596
- async testOptOutWorked() {
597
- return this.rule.test(this.tab);
598
- }
599
- async applyCosmetics(selectors) {
600
- const hidden = await this.tab.hideElements(selectors);
601
- return hidden;
602
- }
603
- }
604
-
605
- // hide rules not specific to a single CMP rule
606
- const globalHidden = [
607
- "#didomi-popup,.didomi-popup-container,.didomi-popup-notice,.didomi-consent-popup-preferences,#didomi-notice,.didomi-popup-backdrop,.didomi-screen-medium",
608
- ];
609
- async function prehideElements(tab, rules) {
610
- const selectors = rules.reduce((selectorList, rule) => {
611
- if (rule.prehideSelectors) {
612
- return [...selectorList, ...rule.prehideSelectors];
613
- }
614
- return selectorList;
615
- }, globalHidden);
616
- await tab.hideElements(selectors, undefined, 'opacity');
617
- }
618
-
619
- class TrustArc extends AutoConsentBase {
620
- constructor() {
621
- super("TrustArc");
622
- this.prehideSelectors = [
623
- ".trustarc-banner-container",
624
- ".truste_popframe,.truste_overlay,.truste_box_overlay,#truste-consent-track",
625
- ];
626
- }
627
- detectFrame(_, frame) {
628
- return frame.url.startsWith("https://consent-pref.trustarc.com/?");
629
- }
630
- async detectCmp(tab) {
631
- if (tab.frame &&
632
- tab.frame.url.startsWith("https://consent-pref.trustarc.com/?")) {
633
- return true;
634
- }
635
- return tab.elementExists("#truste-show-consent");
636
- }
637
- async detectPopup(tab) {
638
- return ((await tab.elementsAreVisible("#truste-consent-content,#trustarc-banner-overlay")) ||
639
- (tab.frame &&
640
- (await tab.waitForElement("#defaultpreferencemanager", 5000, tab.frame.id))));
641
- }
642
- async openFrame(tab) {
643
- if (await tab.elementExists("#truste-show-consent")) {
644
- await tab.clickElement("#truste-show-consent");
645
- }
646
- }
647
- async navigateToSettings(tab, frameId) {
648
- // wait for it to load
649
- await waitFor(async () => {
650
- return ((await tab.elementExists(".shp", frameId)) ||
651
- (await tab.elementsAreVisible(".advance", "any", frameId)) ||
652
- tab.elementExists(".switch span:first-child", frameId));
653
- }, 10, 500);
654
- // splash screen -> hit more information
655
- if (await tab.elementExists(".shp", frameId)) {
656
- await tab.clickElement(".shp", frameId);
657
- }
658
- await tab.waitForElement(".prefPanel", 5000, frameId);
659
- // go to advanced settings if not yet shown
660
- if (await tab.elementsAreVisible(".advance", "any", frameId)) {
661
- await tab.clickElement(".advance", frameId);
662
- }
663
- // takes a while to load the opt-in/opt-out buttons
664
- return await waitFor(() => tab.elementsAreVisible(".switch span:first-child", "any", frameId), 5, 1000);
665
- }
666
- async optOut(tab) {
667
- // await tab.hideElements(['.truste_overlay', '.truste_box_overlay', '.trustarc-banner', '.truste-banner']);
668
- if (await tab.elementExists("#truste-consent-required")) {
669
- return tab.clickElement("#truste-consent-required");
670
- }
671
- if (!tab.frame) {
672
- await tab.clickElement("#truste-show-consent");
673
- await waitFor(async () => !!tab.frame &&
674
- (await tab.elementsAreVisible(".mainContent", "any", tab.frame.id)), 50, 100);
675
- }
676
- const frameId = tab.frame.id;
677
- await waitFor(() => tab.eval("document.readyState === 'complete'", frameId), 20, 100);
678
- tab.hideElements([".truste_popframe", ".truste_overlay", ".truste_box_overlay", "#truste-consent-track"]);
679
- if (await tab.elementExists('.rejectAll', frameId)) {
680
- return tab.clickElement('.rejectAll', frameId);
681
- }
682
- if (await tab.waitForElement('#catDetails0', 1000, frameId)) {
683
- await tab.clickElement("#catDetails0", frameId);
684
- return tab.clickElement(".submit", frameId);
685
- }
686
- if (await tab.elementExists(".required", frameId)) {
687
- await tab.clickElement(".required", frameId);
688
- }
689
- else {
690
- await this.navigateToSettings(tab, frameId);
691
- await tab.clickElements(".switch span:nth-child(1):not(.active)", frameId);
692
- await tab.clickElement(".submit", frameId);
693
- }
694
- try {
695
- await tab.waitForThenClick("#gwt-debug-close_id", 20000, tab.frame.id);
696
- }
697
- catch (e) {
698
- // ignore frame disappearing
699
- }
700
- return true;
701
- }
702
- async optIn(tab) {
703
- if (!tab.frame) {
704
- await this.openFrame(tab);
705
- await waitFor(() => !!tab.frame, 10, 200);
706
- }
707
- const frameId = tab.frame.id;
708
- await this.navigateToSettings(tab, frameId);
709
- await tab.clickElements(".switch span:nth-child(2)", frameId);
710
- await tab.clickElement(".submit", frameId);
711
- await waitFor(() => tab.elementExists("#gwt-debug-close_id", frameId), 300, 1000);
712
- await tab.clickElement("#gwt-debug-close_id", frameId);
713
- return true;
714
- }
715
- async openCmp(tab) {
716
- await tab.eval("truste.eu.clickListener()");
717
- return true;
718
- }
719
- async test() {
720
- // TODO: find out how to test TrustArc
721
- return true;
722
- }
723
- }
724
-
725
- class Cookiebot extends AutoConsentBase {
726
- constructor() {
727
- super('Cybotcookiebot');
728
- this.prehideSelectors = ["#CybotCookiebotDialog,#dtcookie-container,#cookiebanner"];
729
- }
730
- async detectCmp(tab) {
731
- try {
732
- return await tab.eval('typeof window.CookieConsent === "object" && typeof window.CookieConsent.name === "string"');
733
- }
734
- catch (e) {
735
- return false;
736
- }
737
- }
738
- detectPopup(tab) {
739
- return tab.elementExists('#CybotCookiebotDialog,#dtcookie-container,#cookiebanner');
740
- }
741
- async optOut(tab) {
742
- if (await tab.elementExists('.cookie-alert-extended-detail-link')) {
743
- await tab.clickElement('.cookie-alert-extended-detail-link');
744
- await tab.waitForElement('.cookie-alert-configuration', 1000);
745
- await tab.clickElements('.cookie-alert-configuration-input:checked');
746
- return tab.clickElement('.cookie-alert-extended-button-secondary');
747
- }
748
- if (await tab.elementExists('#dtcookie-container')) {
749
- return tab.clickElement('.h-dtcookie-decline');
750
- }
751
- if (await tab.elementExists('.cookiebot__button--settings')) {
752
- await tab.clickElement('.cookiebot__button--settings');
753
- }
754
- if (await tab.elementsAreVisible('#CybotCookiebotDialogBodyButtonDecline', 'all')) {
755
- return await tab.clickElement('#CybotCookiebotDialogBodyButtonDecline');
756
- }
757
- if (await tab.elementExists('.cookiebanner__link--details')) {
758
- await tab.clickElement('.cookiebanner__link--details');
759
- }
760
- await tab.clickElements('.CybotCookiebotDialogBodyLevelButton:checked:enabled,input[id*="CybotCookiebotDialogBodyLevelButton"]:checked:enabled');
761
- if (await tab.elementExists('#CybotCookiebotDialogBodyButtonDecline')) {
762
- await tab.clickElement('#CybotCookiebotDialogBodyButtonDecline');
763
- }
764
- if (await tab.elementExists('input[id^=CybotCookiebotDialogBodyLevelButton]:checked')) {
765
- await tab.clickElements('input[id^=CybotCookiebotDialogBodyLevelButton]:checked');
766
- }
767
- if (await tab.elementExists('#CybotCookiebotDialogBodyButtonAcceptSelected')) {
768
- await tab.clickElement('#CybotCookiebotDialogBodyButtonAcceptSelected');
769
- }
770
- else {
771
- await tab.clickElements('#CybotCookiebotDialogBodyLevelButtonAccept,#CybotCookiebotDialogBodyButtonAccept,#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowallSelection');
772
- }
773
- // some sites have custom submit buttons with no obvious selectors. In this case we just call the submitConsent API.
774
- if (await tab.eval('CookieConsent.hasResponse !== true')) {
775
- await tab.eval('Cookiebot.dialog.submitConsent() || true');
776
- await tab.wait(500);
777
- }
778
- return true;
779
- }
780
- async optIn(tab) {
781
- if (await tab.elementExists('#dtcookie-container')) {
782
- return tab.clickElement('.h-dtcookie-accept');
783
- }
784
- await tab.clickElements('.CybotCookiebotDialogBodyLevelButton:not(:checked):enabled');
785
- await tab.clickElement('#CybotCookiebotDialogBodyLevelButtonAccept');
786
- await tab.clickElement('#CybotCookiebotDialogBodyButtonAccept');
787
- return true;
788
- }
789
- async openCmp(tab) {
790
- await tab.eval('CookieConsent.renew() || true');
791
- return tab.waitForElement('#CybotCookiebotDialog', 10000);
792
- }
793
- async test(tab) {
794
- return tab.eval('CookieConsent.declined === true');
795
- }
796
- }
797
-
798
- class SourcePoint extends AutoConsentBase {
799
- constructor() {
800
- super("Sourcepoint");
801
- this.ccpaMode = false;
802
- this.prehideSelectors = ["div[id^='sp_message_container_'],.message-overlay"];
803
- }
804
- detectFrame(_, frame) {
805
- try {
806
- const url = new URL(frame.url);
807
- if (url.searchParams.has('message_id') && url.hostname === 'ccpa-notice.sp-prod.net') {
808
- this.ccpaMode = true;
809
- return true;
810
- }
811
- return (url.pathname === '/index.html' || url.pathname === '/privacy-manager/index.html')
812
- && url.searchParams.has('message_id') && url.searchParams.has('requestUUID');
813
- }
814
- catch (e) {
815
- return false;
816
- }
817
- }
818
- async detectCmp(tab) {
819
- return await tab.elementExists("div[id^='sp_message_container_']") || !!tab.frame;
820
- }
821
- async detectPopup(tab) {
822
- return await tab.elementsAreVisible("div[id^='sp_message_container_']");
823
- }
824
- async optIn(tab) {
825
- return tab.clickElement(".sp_choice_type_11", tab.frame.id);
826
- }
827
- isManagerOpen(tab) {
828
- return tab.frame && new URL(tab.frame.url).pathname === "/privacy-manager/index.html";
829
- }
830
- async optOut(tab) {
831
- try {
832
- tab.hideElements(["div[id^='sp_message_container_']"]);
833
- if (!this.isManagerOpen(tab)) {
834
- if (!await waitFor(() => !!tab.frame, 30, 100)) {
835
- throw "Frame never opened";
836
- }
837
- if (!await tab.elementExists("button.sp_choice_type_12", tab.frame.id)) {
838
- // do not sell button
839
- return tab.clickElement('button.sp_choice_type_13', tab.frame.id);
840
- }
841
- await success(tab.clickElement("button.sp_choice_type_12", tab.frame.id));
842
- await waitFor(() => new URL(tab.frame.url).pathname === "/privacy-manager/index.html", 200, 100);
843
- }
844
- await tab.waitForElement('.type-modal', 20000, tab.frame.id);
845
- // reject all button is offered by some sites
846
- try {
847
- const path = await Promise.race([
848
- tab.waitForElement('.sp_choice_type_REJECT_ALL', 2000, tab.frame.id).then(r => 0),
849
- tab.waitForElement('.reject-toggle', 2000, tab.frame.id).then(() => 1),
850
- tab.waitForElement('.pm-features', 2000, tab.frame.id).then(r => 2),
851
- ]);
852
- if (path === 0) {
853
- await tab.wait(1000);
854
- return await success(tab.clickElement('.sp_choice_type_REJECT_ALL', tab.frame.id));
855
- }
856
- else if (path === 1) {
857
- await tab.clickElement('.reject-toggle', tab.frame.id);
858
- }
859
- else {
860
- await tab.waitForElement('.pm-features', 10000, tab.frame.id);
861
- await tab.clickElements('.checked > span', tab.frame.id);
862
- if (await tab.elementExists('.chevron', tab.frame.id)) {
863
- await tab.clickElement('.chevron', tab.frame.id);
864
- }
865
- }
866
- }
867
- catch (e) { }
868
- return await tab.clickElement('.sp_choice_type_SAVE_AND_EXIT', tab.frame.id);
869
- }
870
- finally {
871
- tab.undoHideElements();
872
- }
873
- }
874
- async test(tab) {
875
- await tab.eval("__tcfapi('getTCData', 2, r => window.__rcsResult = r)");
876
- return tab.eval("Object.values(window.__rcsResult.purpose.consents).every(c => !c)");
877
- }
878
- }
879
-
880
- // Note: JS API is also available:
881
- // https://help.consentmanager.net/books/cmp/page/javascript-api
882
- class ConsentManager extends AutoConsentBase {
883
- constructor() {
884
- super("consentmanager.net");
885
- this.prehideSelectors = ["#cmpbox,#cmpbox2"];
886
- }
887
- detectCmp(tab) {
888
- return tab.elementExists("#cmpbox");
889
- }
890
- detectPopup(tab) {
891
- return tab.elementsAreVisible("#cmpbox .cmpmore", "any");
892
- }
893
- async optOut(tab) {
894
- if (await tab.elementExists(".cmpboxbtnno")) {
895
- return tab.clickElement(".cmpboxbtnno");
896
- }
897
- if (await tab.elementExists(".cmpwelcomeprpsbtn")) {
898
- await tab.clickElements(".cmpwelcomeprpsbtn > a[aria-checked=true]");
899
- return await tab.clickElement(".cmpboxbtnsave");
900
- }
901
- await tab.clickElement(".cmpboxbtncustom");
902
- await tab.waitForElement(".cmptblbox", 2000);
903
- await tab.clickElements(".cmptdchoice > a[aria-checked=true]");
904
- return tab.clickElement(".cmpboxbtnyescustomchoices");
905
- }
906
- async optIn(tab) {
907
- return tab.clickElement(".cmpboxbtnyes");
908
- }
909
- }
910
-
911
- // Note: JS API is also available:
912
- // https://help.consentmanager.net/books/cmp/page/javascript-api
913
- class Evidon extends AutoConsentBase {
914
- constructor() {
915
- super("Evidon");
916
- }
917
- detectCmp(tab) {
918
- return tab.elementExists("#_evidon_banner");
919
- }
920
- detectPopup(tab) {
921
- return tab.elementsAreVisible("#_evidon_banner");
922
- }
923
- async optOut(tab) {
924
- if (await tab.elementExists("#_evidon-decline-button")) {
925
- return tab.clickElement("#_evidon-decline-button");
926
- }
927
- tab.hideElements(["#evidon-prefdiag-overlay", "#evidon-prefdiag-background"]);
928
- await tab.clickElement("#_evidon-option-button");
929
- await tab.waitForElement("#evidon-prefdiag-overlay", 5000);
930
- return tab.clickElement("#evidon-prefdiag-decline");
931
- }
932
- async optIn(tab) {
933
- return tab.clickElement("#_evidon-accept-button");
934
- }
935
- }
936
-
937
- class Onetrust extends AutoConsentBase {
938
- constructor() {
939
- super("Onetrust");
940
- this.prehideSelectors = ["#onetrust-banner-sdk,#onetrust-consent-sdk,.optanon-alert-box-wrapper,.onetrust-pc-dark-filter,.js-consent-banner"];
941
- }
942
- detectCmp(tab) {
943
- return tab.elementExists("#onetrust-banner-sdk,.optanon-alert-box-wrapper");
944
- }
945
- detectPopup(tab) {
946
- return tab.elementsAreVisible("#onetrust-banner-sdk,.optanon-alert-box-wrapper");
947
- }
948
- async optOut(tab) {
949
- if (await tab.elementExists("#onetrust-pc-btn-handler")) { // "show purposes" button inside a popup
950
- await success(tab.clickElement("#onetrust-pc-btn-handler"));
951
- }
952
- else { // otherwise look for a generic "show settings" button
953
- await success(tab.clickElement(".ot-sdk-show-settings,button.js-cookie-settings"));
954
- }
955
- await success(tab.waitForElement("#onetrust-consent-sdk", 2000));
956
- await success(tab.wait(1000));
957
- await tab.clickElements("#onetrust-consent-sdk input.category-switch-handler:checked,.js-editor-toggle-state:checked"); // optional step
958
- await success(tab.waitForThenClick(".save-preference-btn-handler,.js-consent-save", 1000));
959
- // popup doesn't disappear immediately
960
- await waitFor(async () => !(await tab.elementsAreVisible("#onetrust-banner-sdk")), 10, 500);
961
- return true;
962
- }
963
- async optIn(tab) {
964
- return tab.clickElement("onetrust-accept-btn-handler,js-accept-cookies");
965
- }
966
- async test(tab) {
967
- return tab.eval("window.OnetrustActiveGroups.split(',').filter(s => s.length > 0).length <= 1");
968
- }
969
- }
970
-
971
- const rules = [
972
- new TrustArc(),
973
- new Cookiebot(),
974
- new SourcePoint(),
975
- new ConsentManager(),
976
- new Evidon(),
977
- new Onetrust(),
978
- ];
979
- function createAutoCMP(config) {
980
- return new AutoConsent(config);
981
- }
982
-
983
- const rules$1 = rules;
984
-
985
- class ConsentOMaticCMP {
986
- constructor(name, config) {
987
- this.name = name;
988
- this.config = config;
989
- this.methods = new Map();
990
- config.methods.forEach(methodConfig => {
991
- if (methodConfig.action) {
992
- this.methods.set(methodConfig.name, methodConfig.action);
993
- }
994
- });
995
- this.hasSelfTest = this.methods.has("TEST_CONSENT");
996
- }
997
- async detectCmp(tab) {
998
- return (await Promise.all(this.config.detectors.map(detectorConfig => tab.matches(detectorConfig.presentMatcher)))).some(matched => matched);
999
- }
1000
- async detectPopup(tab) {
1001
- return (await Promise.all(this.config.detectors.map(detectorConfig => tab.matches(detectorConfig.showingMatcher)))).some(matched => matched);
1002
- }
1003
- async executeAction(tab, method, param) {
1004
- if (this.methods.has(method)) {
1005
- return tab.executeAction(this.methods.get(method), param);
1006
- }
1007
- return true;
1008
- }
1009
- async optOut(tab) {
1010
- await this.executeAction(tab, "HIDE_CMP");
1011
- await this.executeAction(tab, "OPEN_OPTIONS");
1012
- await this.executeAction(tab, "HIDE_CMP");
1013
- await this.executeAction(tab, "DO_CONSENT", []);
1014
- await this.executeAction(tab, "SAVE_CONSENT");
1015
- return true;
1016
- }
1017
- async optIn(tab) {
1018
- await this.executeAction(tab, "HIDE_CMP");
1019
- await this.executeAction(tab, "OPEN_OPTIONS");
1020
- await this.executeAction(tab, "HIDE_CMP");
1021
- await this.executeAction(tab, "DO_CONSENT", ['D', 'A', 'B', 'E', 'F', 'X']);
1022
- await this.executeAction(tab, "SAVE_CONSENT");
1023
- return true;
1024
- }
1025
- async openCmp(tab) {
1026
- await this.executeAction(tab, "HIDE_CMP");
1027
- await this.executeAction(tab, "OPEN_OPTIONS");
1028
- return true;
1029
- }
1030
- test(tab) {
1031
- return this.executeAction(tab, "TEST_CONSENT");
1032
- }
1033
- detectFrame(tab, frame) {
1034
- return false;
1035
- }
1036
- }
1037
-
1038
- function attachToPage(page, url, rules, retries = 1, prehide = true) {
1039
- const frames = {
1040
- 0: page.mainFrame(),
1041
- };
1042
- const tab = new Tab(page, url, frames);
1043
- async function onFrame(frame) {
1044
- const allFrames = await page.frames();
1045
- allFrames.forEach((frame, frameId) => {
1046
- const frameMatch = rules.findIndex(r => r.detectFrame(tab, {
1047
- url: frame.url(),
1048
- }));
1049
- if (frameMatch > -1) {
1050
- tab.frame = {
1051
- type: rules[frameMatch].name,
1052
- url: frame.url(),
1053
- id: frameId,
1054
- };
1055
- frames[frameId] = frame;
1056
- }
1057
- });
1058
- }
1059
- page.on('framenavigated', onFrame);
1060
- page.frames().forEach(onFrame);
1061
- if (prehide) {
1062
- prehideElements(tab, rules);
1063
- }
1064
- return new TabConsent(tab, detectDialog(tab, retries, rules));
1065
- }
1066
-
1067
- exports.ConsentOMaticCMP = ConsentOMaticCMP;
1068
- exports.Tab = Tab;
1069
- exports.TabConsent = TabConsent;
1070
- exports.attachToPage = attachToPage;
1071
- exports.createAutoCMP = createAutoCMP;
1072
- exports.detectDialog = detectDialog;
1073
- exports.rules = rules$1;
1074
- exports.waitFor = waitFor;