@duckduckgo/autoconsent 15.1.0 → 16.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 (89) hide show
  1. package/.github/PULL_REQUEST_TEMPLATE.md +7 -0
  2. package/.github/dependabot.yml +0 -3
  3. package/.github/labeler.yml +36 -0
  4. package/.github/workflows/release-labels.yml +110 -0
  5. package/.github/workflows/release.yml +0 -4
  6. package/AGENTS.md +3 -3
  7. package/CHANGELOG.md +33 -0
  8. package/build.sh +0 -2
  9. package/dist/addon-firefox/background.bundle.js +8 -24
  10. package/dist/addon-firefox/compact-rules.json +1 -1
  11. package/dist/addon-firefox/content.bundle.js +176 -686
  12. package/dist/addon-firefox/manifest.json +1 -1
  13. package/dist/addon-firefox/popup.bundle.js +31 -27
  14. package/dist/addon-firefox/popup.html +21 -13
  15. package/dist/addon-firefox/rule-index.json +1 -1
  16. package/dist/addon-firefox/rules.json +1 -1
  17. package/dist/addon-mv3/background.bundle.js +8 -24
  18. package/dist/addon-mv3/compact-rules.json +1 -1
  19. package/dist/addon-mv3/content.bundle.js +176 -686
  20. package/dist/addon-mv3/manifest.json +1 -1
  21. package/dist/addon-mv3/popup.bundle.js +31 -27
  22. package/dist/addon-mv3/popup.html +21 -13
  23. package/dist/addon-mv3/rule-index.json +1 -1
  24. package/dist/addon-mv3/rules.json +1 -1
  25. package/dist/autoconsent.cjs.js +176 -685
  26. package/dist/autoconsent.esm.js +176 -685
  27. package/dist/autoconsent.playwright.js +177 -689
  28. package/dist/autoconsent.standalone.js +177 -690
  29. package/dist/types/cmps/base.d.ts +3 -3
  30. package/dist/types/heuristics.d.ts +2 -2
  31. package/dist/types/types.d.ts +10 -23
  32. package/dist/types/web.d.ts +0 -9
  33. package/docs/api.md +1 -8
  34. package/docs/puppeteer.md +1 -3
  35. package/docs/release-notes.md +65 -0
  36. package/docs/rule-syntax.md +0 -17
  37. package/eslint.config.mjs +1 -1
  38. package/lib/cmps/base.ts +5 -6
  39. package/lib/heuristics.ts +15 -15
  40. package/lib/types.ts +9 -21
  41. package/lib/utils.ts +2 -4
  42. package/lib/web.ts +3 -53
  43. package/package.json +112 -18
  44. package/playwright/content.ts +1 -2
  45. package/readme.md +3 -6
  46. package/rules/autoconsent/dreamlab-cmp.json +13 -0
  47. package/rules/build.ts +1 -24
  48. package/rules/compact-rules.json +1 -1
  49. package/rules/rule-index-builder.ts +2 -7
  50. package/rules/rule-index.json +1 -1
  51. package/rules/rules.json +1 -1
  52. package/scripts/check-pr-release-labels.ts +255 -0
  53. package/standalone/content.ts +0 -2
  54. package/tests/dreamlab-cmp.spec.ts +3 -0
  55. package/tests/quantcast.spec.ts +0 -6
  56. package/tests-wtr/heuristics/get-actionable-popups.ts +13 -13
  57. package/tests-wtr/heuristics/heuristic-cmp.ts +32 -33
  58. package/tests-wtr/lifecycle/find-cmp.ts +5 -8
  59. package/tests-wtr/web/do-opt-in.test.ts +0 -1
  60. package/tests-wtr/web/do-opt-out.test.ts +0 -1
  61. package/tests-wtr/web/do-self-test.test.ts +0 -1
  62. package/tests-wtr/web/filter-cmps.test.ts +0 -1
  63. package/tests-wtr/web/receive-message-callback.test.ts +1 -2
  64. package/tests-wtr/web/update-state.test.ts +1 -3
  65. package/tsconfig.build.json +1 -1
  66. package/.github/workflows/update-filterlist.yml +0 -42
  67. package/dist/autoconsent.extra.cjs.js +0 -15717
  68. package/dist/autoconsent.extra.esm.js +0 -15649
  69. package/dist/types/cmps/consentomatic.d.ts +0 -34
  70. package/dist/types/consentomatic/index.d.ts +0 -2
  71. package/dist/types/consentomatic/tools.d.ts +0 -10
  72. package/dist/types/filterlist-engine.d.ts +0 -2
  73. package/dist/types/filterlist-utils.d.ts +0 -4
  74. package/dist/types/web-extra.d.ts +0 -11
  75. package/lib/cmps/consentomatic.ts +0 -97
  76. package/lib/consentomatic/index.ts +0 -252
  77. package/lib/consentomatic/tools.ts +0 -199
  78. package/lib/filterlist-engine.ts +0 -5
  79. package/lib/filterlist-utils.ts +0 -45
  80. package/lib/web-extra.ts +0 -116
  81. package/rules/consentomatic.json +0 -1
  82. package/rules/filterlist.txt +0 -18440
  83. package/rules/filterlists/overrides.txt +0 -4
  84. package/scripts/compile-filterlist.mjs +0 -63
  85. package/scripts/fetch-easylist.sh +0 -25
  86. package/scripts/rebuild-filterlist.mjs +0 -216
  87. package/tests/oil.spec.ts +0 -7
  88. package/tests/springer.spec.ts +0 -7
  89. package/tests/wordpressgdpr.spec.ts +0 -6
@@ -6,412 +6,8 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
6
6
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
7
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
8
 
9
- // lib/consentomatic/tools.ts
10
- var _Tools = class _Tools {
11
- static setBase(base) {
12
- _Tools.base = base;
13
- }
14
- static findElement(options, parent = null, multiple = false) {
15
- let possibleTargets = null;
16
- if (parent != null) {
17
- possibleTargets = Array.from(parent.querySelectorAll(options.selector));
18
- } else {
19
- if (_Tools.base != null) {
20
- possibleTargets = Array.from(
21
- _Tools.base.querySelectorAll(options.selector)
22
- );
23
- } else {
24
- possibleTargets = Array.from(
25
- document.querySelectorAll(options.selector)
26
- );
27
- }
28
- }
29
- if (options.textFilter != null) {
30
- possibleTargets = possibleTargets.filter((possibleTarget) => {
31
- const textContent = possibleTarget.textContent.toLowerCase();
32
- if (Array.isArray(options.textFilter)) {
33
- let foundText = false;
34
- for (const text of options.textFilter) {
35
- if (textContent.indexOf(text.toLowerCase()) !== -1) {
36
- foundText = true;
37
- break;
38
- }
39
- }
40
- return foundText;
41
- } else if (options.textFilter != null) {
42
- return textContent.indexOf(options.textFilter.toLowerCase()) !== -1;
43
- }
44
- return false;
45
- });
46
- }
47
- if (options.styleFilters != null) {
48
- possibleTargets = possibleTargets.filter((possibleTarget) => {
49
- const styles = window.getComputedStyle(possibleTarget);
50
- let keep = true;
51
- for (const styleFilter of options.styleFilters) {
52
- const option = styles[styleFilter.option];
53
- if (styleFilter.negated) {
54
- keep = keep && option !== styleFilter.value;
55
- } else {
56
- keep = keep && option === styleFilter.value;
57
- }
58
- }
59
- return keep;
60
- });
61
- }
62
- if (options.displayFilter != null) {
63
- possibleTargets = possibleTargets.filter((possibleTarget) => {
64
- if (options.displayFilter) {
65
- return possibleTarget.offsetHeight !== 0;
66
- } else {
67
- return possibleTarget.offsetHeight === 0;
68
- }
69
- });
70
- }
71
- if (options.iframeFilter != null) {
72
- possibleTargets = possibleTargets.filter(() => {
73
- if (options.iframeFilter) {
74
- return window.location !== window.parent.location;
75
- } else {
76
- return window.location === window.parent.location;
77
- }
78
- });
79
- }
80
- if (options.childFilter != null) {
81
- possibleTargets = possibleTargets.filter((possibleTarget) => {
82
- const oldBase = _Tools.base;
83
- _Tools.setBase(possibleTarget);
84
- const childResults = _Tools.find(options.childFilter);
85
- _Tools.setBase(oldBase);
86
- return childResults.target != null;
87
- });
88
- }
89
- if (multiple) {
90
- return possibleTargets;
91
- } else {
92
- if (possibleTargets.length > 1) {
93
- console.warn(
94
- "Multiple possible targets: ",
95
- possibleTargets,
96
- options,
97
- parent
98
- );
99
- }
100
- return possibleTargets[0];
101
- }
102
- }
103
- static find(options, multiple = false) {
104
- const results = [];
105
- if (options.parent != null) {
106
- const parent = _Tools.findElement(options.parent, null, multiple);
107
- if (parent != null) {
108
- if (parent instanceof Array) {
109
- parent.forEach((p) => {
110
- const targets = _Tools.findElement(options.target, p, multiple);
111
- if (targets instanceof Array) {
112
- targets.forEach((target) => {
113
- results.push({
114
- parent: p,
115
- target
116
- });
117
- });
118
- } else {
119
- results.push({
120
- parent: p,
121
- target: targets
122
- });
123
- }
124
- });
125
- return results;
126
- } else {
127
- const targets = _Tools.findElement(options.target, parent, multiple);
128
- if (targets instanceof Array) {
129
- targets.forEach((target) => {
130
- results.push({
131
- parent,
132
- target
133
- });
134
- });
135
- } else {
136
- results.push({
137
- parent,
138
- target: targets
139
- });
140
- }
141
- }
142
- }
143
- } else {
144
- const targets = _Tools.findElement(options.target, null, multiple);
145
- if (targets instanceof Array) {
146
- targets.forEach((target) => {
147
- results.push({
148
- parent: null,
149
- target
150
- });
151
- });
152
- } else {
153
- results.push({
154
- parent: null,
155
- target: targets
156
- });
157
- }
158
- }
159
- if (results.length === 0) {
160
- results.push({
161
- parent: null,
162
- target: null
163
- });
164
- }
165
- if (multiple) {
166
- return results;
167
- } else {
168
- if (results.length !== 1) {
169
- console.warn(
170
- "Multiple results found, even though multiple false",
171
- results
172
- );
173
- }
174
- return results[0];
175
- }
176
- }
177
- };
178
- _Tools.base = null;
179
- var Tools = _Tools;
180
-
181
- // lib/consentomatic/index.ts
182
- function matches(config) {
183
- const result = Tools.find(config);
184
- if (config.type === "css") {
185
- return !!result.target;
186
- } else if (config.type === "checkbox") {
187
- return !!result.target && result.target.checked;
188
- }
189
- }
190
- async function executeAction(config, param) {
191
- switch (config.type) {
192
- case "click":
193
- return clickAction(config);
194
- case "list":
195
- return listAction(config, param);
196
- case "consent":
197
- return consentAction(config, param);
198
- case "ifcss":
199
- return ifCssAction(config, param);
200
- case "waitcss":
201
- return waitCssAction(config);
202
- case "foreach":
203
- return forEachAction(config, param);
204
- case "hide":
205
- return hideAction(config);
206
- case "slide":
207
- return slideAction(config);
208
- case "close":
209
- return closeAction();
210
- case "wait":
211
- return waitAction(config);
212
- case "eval":
213
- return evalAction(config);
214
- default:
215
- throw new Error("Unknown action type: " + config.type);
216
- }
217
- }
218
- var STEP_TIMEOUT = 0;
219
- function waitTimeout(timeout) {
220
- return new Promise((resolve) => {
221
- setTimeout(() => {
222
- resolve();
223
- }, timeout);
224
- });
225
- }
226
- async function clickAction(config) {
227
- const result = Tools.find(config);
228
- if (result.target != null) {
229
- result.target.click();
230
- }
231
- return waitTimeout(STEP_TIMEOUT);
232
- }
233
- async function listAction(config, param) {
234
- for (const action of config.actions) {
235
- await executeAction(action, param);
236
- }
237
- }
238
- async function consentAction(config, consentTypes) {
239
- for (const consentConfig of config.consents) {
240
- const shouldEnable = consentTypes.indexOf(consentConfig.type) !== -1;
241
- if (consentConfig.matcher && consentConfig.toggleAction) {
242
- const isEnabled = matches(consentConfig.matcher);
243
- if (isEnabled !== shouldEnable) {
244
- await executeAction(consentConfig.toggleAction);
245
- }
246
- } else {
247
- if (shouldEnable) {
248
- await executeAction(consentConfig.trueAction);
249
- } else {
250
- await executeAction(consentConfig.falseAction);
251
- }
252
- }
253
- }
254
- }
255
- async function ifCssAction(config, param) {
256
- const result = Tools.find(config);
257
- if (!result.target) {
258
- if (config.trueAction) {
259
- await executeAction(config.trueAction, param);
260
- }
261
- } else {
262
- if (config.falseAction) {
263
- await executeAction(config.falseAction, param);
264
- }
265
- }
266
- }
267
- async function waitCssAction(config) {
268
- await new Promise((resolve) => {
269
- let numRetries = config.retries || 10;
270
- const waitTime = config.waitTime || 250;
271
- const checkCss = () => {
272
- const result = Tools.find(config);
273
- if (config.negated && result.target || !config.negated && !result.target) {
274
- if (numRetries > 0) {
275
- numRetries -= 1;
276
- setTimeout(checkCss, waitTime);
277
- } else {
278
- resolve();
279
- }
280
- } else {
281
- resolve();
282
- }
283
- };
284
- checkCss();
285
- });
286
- }
287
- async function forEachAction(config, param) {
288
- const results = Tools.find(config, true);
289
- const oldBase = Tools.base;
290
- for (const result of results) {
291
- if (result.target) {
292
- Tools.setBase(result.target);
293
- await executeAction(config.action, param);
294
- }
295
- }
296
- Tools.setBase(oldBase);
297
- }
298
- async function hideAction(config) {
299
- const result = Tools.find(config);
300
- if (result.target) {
301
- result.target.classList.add("Autoconsent-Hidden");
302
- }
303
- }
304
- async function slideAction(config) {
305
- const result = Tools.find(config);
306
- const dragResult = Tools.find(config.dragTarget);
307
- if (result.target) {
308
- const targetBounds = result.target.getBoundingClientRect();
309
- const dragTargetBounds = dragResult.target.getBoundingClientRect();
310
- let yDiff = dragTargetBounds.top - targetBounds.top;
311
- let xDiff = dragTargetBounds.left - targetBounds.left;
312
- if (this.config.axis.toLowerCase() === "y") {
313
- xDiff = 0;
314
- }
315
- if (this.config.axis.toLowerCase() === "x") {
316
- yDiff = 0;
317
- }
318
- const screenX = window.screenX + targetBounds.left + targetBounds.width / 2;
319
- const screenY = window.screenY + targetBounds.top + targetBounds.height / 2;
320
- const clientX = targetBounds.left + targetBounds.width / 2;
321
- const clientY = targetBounds.top + targetBounds.height / 2;
322
- const mouseDown = document.createEvent("MouseEvents");
323
- mouseDown.initMouseEvent(
324
- "mousedown",
325
- true,
326
- true,
327
- window,
328
- 0,
329
- screenX,
330
- screenY,
331
- clientX,
332
- clientY,
333
- false,
334
- false,
335
- false,
336
- false,
337
- 0,
338
- result.target
339
- );
340
- const mouseMove = document.createEvent("MouseEvents");
341
- mouseMove.initMouseEvent(
342
- "mousemove",
343
- true,
344
- true,
345
- window,
346
- 0,
347
- screenX + xDiff,
348
- screenY + yDiff,
349
- clientX + xDiff,
350
- clientY + yDiff,
351
- false,
352
- false,
353
- false,
354
- false,
355
- 0,
356
- result.target
357
- );
358
- const mouseUp = document.createEvent("MouseEvents");
359
- mouseUp.initMouseEvent(
360
- "mouseup",
361
- true,
362
- true,
363
- window,
364
- 0,
365
- screenX + xDiff,
366
- screenY + yDiff,
367
- clientX + xDiff,
368
- clientY + yDiff,
369
- false,
370
- false,
371
- false,
372
- false,
373
- 0,
374
- result.target
375
- );
376
- result.target.dispatchEvent(mouseDown);
377
- await this.waitTimeout(10);
378
- result.target.dispatchEvent(mouseMove);
379
- await this.waitTimeout(10);
380
- result.target.dispatchEvent(mouseUp);
381
- }
382
- }
383
- async function waitAction(config) {
384
- await waitTimeout(config.waitTime);
385
- }
386
- async function closeAction() {
387
- window.close();
388
- }
389
- async function evalAction(config) {
390
- console.log("eval!", config.code);
391
- return new Promise((resolve) => {
392
- try {
393
- if (config.async) {
394
- window.eval(config.code);
395
- setTimeout(() => {
396
- resolve(window.eval("window.__consentCheckResult"));
397
- }, config.timeout || 250);
398
- } else {
399
- resolve(window.eval(config.code));
400
- }
401
- } catch (e) {
402
- console.warn("eval error", e, config.code);
403
- resolve(false);
404
- }
405
- });
406
- }
407
-
408
- // lib/types.ts
409
- var PopupHandlingModes = {
410
- None: -1,
411
- Reject: 0,
412
- Tier1: 1,
413
- Tier2: 2
414
- };
9
+ // lib/rules.ts
10
+ var SUPPORTED_RULE_STEP_VERSION = 2;
415
11
 
416
12
  // lib/random.ts
417
13
  function getRandomID() {
@@ -464,6 +60,155 @@ function resolveEval(id, value) {
464
60
  }
465
61
  }
466
62
 
63
+ // lib/utils.ts
64
+ function getStyleElement(styleOverrideElementId = "autoconsent-css-rules") {
65
+ const styleSelector = `style#${styleOverrideElementId}`;
66
+ const existingElement = document.querySelector(styleSelector);
67
+ if (existingElement && existingElement instanceof HTMLStyleElement) {
68
+ return existingElement;
69
+ } else {
70
+ const parent = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
71
+ const css = document.createElement("style");
72
+ css.id = styleOverrideElementId;
73
+ parent.appendChild(css);
74
+ return css;
75
+ }
76
+ }
77
+ function getHidingStyle(method) {
78
+ const hidingSnippet = method === "opacity" ? `opacity: 0` : `display: none`;
79
+ return `${hidingSnippet} !important; z-index: -1 !important; pointer-events: none !important;`;
80
+ }
81
+ function hideElements(styleEl, selector, method = "display") {
82
+ const rule = `${selector} { ${getHidingStyle(method)} } `;
83
+ if (styleEl instanceof HTMLStyleElement) {
84
+ styleEl.innerText += rule;
85
+ return selector.length > 0;
86
+ }
87
+ return false;
88
+ }
89
+ async function waitFor(predicate, maxTimes, interval) {
90
+ const result = await predicate();
91
+ if (!result && maxTimes > 0) {
92
+ return new Promise((resolve) => {
93
+ setTimeout(async () => {
94
+ resolve(waitFor(predicate, maxTimes - 1, interval));
95
+ }, interval);
96
+ });
97
+ }
98
+ return Promise.resolve(result);
99
+ }
100
+ function isElementVisible(elem) {
101
+ if (!elem) {
102
+ return false;
103
+ }
104
+ if (elem.offsetParent !== null) {
105
+ return true;
106
+ } else {
107
+ const css = window.getComputedStyle(elem);
108
+ if (css.position === "fixed" && css.display !== "none") {
109
+ return true;
110
+ }
111
+ }
112
+ return false;
113
+ }
114
+ function copyObject(data) {
115
+ if (globalThis.structuredClone) {
116
+ return structuredClone(data);
117
+ }
118
+ return JSON.parse(JSON.stringify(data));
119
+ }
120
+ function normalizeConfig(providedConfig) {
121
+ const defaultConfig = {
122
+ enabled: true,
123
+ autoAction: "optOut",
124
+ // if falsy, the extension will wait for an explicit user signal before opting in/out
125
+ disabledCmps: [],
126
+ enablePrehide: true,
127
+ enableCosmeticRules: true,
128
+ enableGeneratedRules: true,
129
+ enableHeuristicDetection: false,
130
+ enablePopupMutationObserver: false,
131
+ detectRetries: 20,
132
+ isMainWorld: false,
133
+ prehideTimeout: 2e3,
134
+ visualTest: false,
135
+ logs: {
136
+ lifecycle: false,
137
+ rulesteps: false,
138
+ detectionsteps: false,
139
+ evals: false,
140
+ errors: true,
141
+ messages: false,
142
+ waits: false
143
+ },
144
+ performanceLoggingEnabled: false,
145
+ heuristicPopupSearchTimeout: 100,
146
+ heuristicMode: "off"
147
+ // heuristic disabled by default
148
+ };
149
+ const updatedConfig = copyObject(defaultConfig);
150
+ for (const key of Object.keys(defaultConfig)) {
151
+ if (typeof providedConfig[key] !== "undefined") {
152
+ updatedConfig[key] = providedConfig[key];
153
+ }
154
+ }
155
+ return updatedConfig;
156
+ }
157
+ function scheduleWhenIdle(callback, timeout = 500) {
158
+ if (globalThis.requestIdleCallback) {
159
+ requestIdleCallback(callback, { timeout });
160
+ } else {
161
+ setTimeout(callback, 0);
162
+ }
163
+ }
164
+ function highlightNode(node) {
165
+ const highlightedNode = node;
166
+ if (!node.style) return;
167
+ if (highlightedNode.__oldStyles !== void 0) {
168
+ return;
169
+ }
170
+ if (node.hasAttribute("style")) {
171
+ highlightedNode.__oldStyles = node.style.cssText;
172
+ }
173
+ node.style.animation = "pulsate .5s infinite";
174
+ node.style.outline = "solid red";
175
+ let styleTag = document.querySelector("style#autoconsent-debug-styles");
176
+ if (!styleTag) {
177
+ styleTag = document.createElement("style");
178
+ styleTag.id = "autoconsent-debug-styles";
179
+ }
180
+ styleTag.textContent = `
181
+ @keyframes pulsate {
182
+ 0% {
183
+ outline-width: 8px;
184
+ outline-offset: -4px;
185
+ }
186
+ 50% {
187
+ outline-width: 4px;
188
+ outline-offset: -2px;
189
+ }
190
+ 100% {
191
+ outline-width: 8px;
192
+ outline-offset: -4px;
193
+ }
194
+ }
195
+ `;
196
+ document.head.appendChild(styleTag);
197
+ }
198
+ function unhighlightNode(node) {
199
+ const highlightedNode = node;
200
+ if (!node.style || !node.hasAttribute("style")) return;
201
+ if (highlightedNode.__oldStyles !== void 0) {
202
+ node.style.cssText = highlightedNode.__oldStyles;
203
+ delete highlightedNode.__oldStyles;
204
+ } else {
205
+ node.removeAttribute("style");
206
+ }
207
+ }
208
+ function isTopFrame() {
209
+ return window.top === window && (!globalThis.location.ancestorOrigins || globalThis.location.ancestorOrigins.length === 0);
210
+ }
211
+
467
212
  // lib/eval-snippets.ts
468
213
  var snippets = {
469
214
  // code-based rules
@@ -641,156 +386,6 @@ function getFunctionBody(snippetFunc) {
641
386
  return `(${snippetStr})()`;
642
387
  }
643
388
 
644
- // lib/utils.ts
645
- function getStyleElement(styleOverrideElementId = "autoconsent-css-rules") {
646
- const styleSelector = `style#${styleOverrideElementId}`;
647
- const existingElement = document.querySelector(styleSelector);
648
- if (existingElement && existingElement instanceof HTMLStyleElement) {
649
- return existingElement;
650
- } else {
651
- const parent = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
652
- const css = document.createElement("style");
653
- css.id = styleOverrideElementId;
654
- parent.appendChild(css);
655
- return css;
656
- }
657
- }
658
- function getHidingStyle(method) {
659
- const hidingSnippet = method === "opacity" ? `opacity: 0` : `display: none`;
660
- return `${hidingSnippet} !important; z-index: -1 !important; pointer-events: none !important;`;
661
- }
662
- function hideElements(styleEl, selector, method = "display") {
663
- const rule = `${selector} { ${getHidingStyle(method)} } `;
664
- if (styleEl instanceof HTMLStyleElement) {
665
- styleEl.innerText += rule;
666
- return selector.length > 0;
667
- }
668
- return false;
669
- }
670
- async function waitFor(predicate, maxTimes, interval) {
671
- const result = await predicate();
672
- if (!result && maxTimes > 0) {
673
- return new Promise((resolve) => {
674
- setTimeout(async () => {
675
- resolve(waitFor(predicate, maxTimes - 1, interval));
676
- }, interval);
677
- });
678
- }
679
- return Promise.resolve(result);
680
- }
681
- function isElementVisible(elem) {
682
- if (!elem) {
683
- return false;
684
- }
685
- if (elem.offsetParent !== null) {
686
- return true;
687
- } else {
688
- const css = window.getComputedStyle(elem);
689
- if (css.position === "fixed" && css.display !== "none") {
690
- return true;
691
- }
692
- }
693
- return false;
694
- }
695
- function copyObject(data) {
696
- if (globalThis.structuredClone) {
697
- return structuredClone(data);
698
- }
699
- return JSON.parse(JSON.stringify(data));
700
- }
701
- function normalizeConfig(providedConfig) {
702
- const defaultConfig = {
703
- enabled: true,
704
- autoAction: "optOut",
705
- // if falsy, the extension will wait for an explicit user signal before opting in/out
706
- disabledCmps: [],
707
- enablePrehide: true,
708
- enableCosmeticRules: true,
709
- enableGeneratedRules: true,
710
- enableHeuristicDetection: false,
711
- enableHeuristicAction: false,
712
- enablePopupMutationObserver: false,
713
- detectRetries: 20,
714
- isMainWorld: false,
715
- prehideTimeout: 2e3,
716
- enableFilterList: false,
717
- visualTest: false,
718
- logs: {
719
- lifecycle: false,
720
- rulesteps: false,
721
- detectionsteps: false,
722
- evals: false,
723
- errors: true,
724
- messages: false,
725
- waits: false
726
- },
727
- performanceLoggingEnabled: false,
728
- heuristicPopupSearchTimeout: 100,
729
- heuristicMode: PopupHandlingModes.Reject
730
- };
731
- const updatedConfig = copyObject(defaultConfig);
732
- for (const key of Object.keys(defaultConfig)) {
733
- if (typeof providedConfig[key] !== "undefined") {
734
- updatedConfig[key] = providedConfig[key];
735
- }
736
- }
737
- return updatedConfig;
738
- }
739
- function scheduleWhenIdle(callback, timeout = 500) {
740
- if (globalThis.requestIdleCallback) {
741
- requestIdleCallback(callback, { timeout });
742
- } else {
743
- setTimeout(callback, 0);
744
- }
745
- }
746
- function highlightNode(node) {
747
- const highlightedNode = node;
748
- if (!node.style) return;
749
- if (highlightedNode.__oldStyles !== void 0) {
750
- return;
751
- }
752
- if (node.hasAttribute("style")) {
753
- highlightedNode.__oldStyles = node.style.cssText;
754
- }
755
- node.style.animation = "pulsate .5s infinite";
756
- node.style.outline = "solid red";
757
- let styleTag = document.querySelector("style#autoconsent-debug-styles");
758
- if (!styleTag) {
759
- styleTag = document.createElement("style");
760
- styleTag.id = "autoconsent-debug-styles";
761
- }
762
- styleTag.textContent = `
763
- @keyframes pulsate {
764
- 0% {
765
- outline-width: 8px;
766
- outline-offset: -4px;
767
- }
768
- 50% {
769
- outline-width: 4px;
770
- outline-offset: -2px;
771
- }
772
- 100% {
773
- outline-width: 8px;
774
- outline-offset: -4px;
775
- }
776
- }
777
- `;
778
- document.head.appendChild(styleTag);
779
- }
780
- function unhighlightNode(node) {
781
- const highlightedNode = node;
782
- if (!node.style || !node.hasAttribute("style")) return;
783
- if (highlightedNode.__oldStyles !== void 0) {
784
- node.style.cssText = highlightedNode.__oldStyles;
785
- delete highlightedNode.__oldStyles;
786
- } else {
787
- node.removeAttribute("style");
788
- }
789
- }
790
- function isTopFrame() {
791
- return window.top === window && (!globalThis.location.ancestorOrigins || globalThis.location.ancestorOrigins.length === 0);
792
- }
793
-
794
389
  // lib/heuristic-patterns.ts
795
390
  var DETECT_PATTERNS = [
796
391
  /accept cookies/gi,
@@ -1549,15 +1144,19 @@ function checkHeuristicPatterns(allText, detectPatterns = DETECT_PATTERNS) {
1549
1144
  const patterns = [];
1550
1145
  const snippets2 = [];
1551
1146
  for (const p of detectPatterns) {
1552
- const matches2 = allText?.match(p);
1553
- if (matches2) {
1147
+ const matches = allText?.match(p);
1148
+ if (matches) {
1554
1149
  patterns.push(p.toString());
1555
- snippets2.push(...matches2.map((m) => m.substring(0, 200)));
1150
+ snippets2.push(...matches.map((m) => m.substring(0, 200)));
1556
1151
  }
1557
1152
  }
1558
1153
  return { patterns, snippets: snippets2 };
1559
1154
  }
1560
- function getActionablePopups(mode = PopupHandlingModes.Reject, timeout = POPUP_SEARCH_MAX_TIME) {
1155
+ function getActionablePopups(mode = "reject", timeout = POPUP_SEARCH_MAX_TIME) {
1156
+ const acceptedLevels = mode === "tier2" ? ["reject", "tier1", "tier2"] : mode === "tier1" ? ["reject", "tier1"] : ["reject"];
1157
+ if (acceptedLevels.length === 0) {
1158
+ return [];
1159
+ }
1561
1160
  const popups = getPotentialPopups(timeout);
1562
1161
  const result = popups.reduce((acc, popup) => {
1563
1162
  const popupText = popup.text?.trim();
@@ -1573,9 +1172,7 @@ function getActionablePopups(mode = PopupHandlingModes.Reject, timeout = POPUP_S
1573
1172
  }
1574
1173
  return acc;
1575
1174
  }, []);
1576
- return result.filter(
1577
- (popup) => popup.regexClassification !== void 0 && popup.regexClassification !== PopupHandlingModes.None && popup.regexClassification <= mode
1578
- ).sort((a, b) => (a.regexClassification ?? 0) - (b.regexClassification ?? 0));
1175
+ return result.filter((popup) => popup.regexClassification !== void 0 && acceptedLevels.includes(popup.regexClassification)).sort((a, b) => (a.regexClassification ?? "") > (b.regexClassification ?? "") ? 1 : -1);
1579
1176
  }
1580
1177
  function classifyButtons(buttons) {
1581
1178
  for (const button of buttons) {
@@ -1593,18 +1190,18 @@ function classifyPopup(buttons) {
1593
1190
  { reject: 0, settings: 0, accept: 0, acknowledge: 0 }
1594
1191
  );
1595
1192
  if (reject > 0) {
1596
- return PopupHandlingModes.Reject;
1193
+ return "reject";
1597
1194
  }
1598
1195
  if (settings > 0) {
1599
- return PopupHandlingModes.None;
1196
+ return "none";
1600
1197
  }
1601
1198
  if (acknowledge > 0) {
1602
- return PopupHandlingModes.Tier1;
1199
+ return "tier1";
1603
1200
  }
1604
1201
  if (accept > 0) {
1605
- return accept === 1 ? PopupHandlingModes.Tier2 : PopupHandlingModes.None;
1202
+ return accept === 1 ? "tier2" : "none";
1606
1203
  }
1607
- return PopupHandlingModes.None;
1204
+ return "none";
1608
1205
  }
1609
1206
  function testButtonMatches(buttonText, matchPatterns, neverMatchPatterns) {
1610
1207
  if (!buttonText) {
@@ -2085,7 +1682,7 @@ var AutoConsentCMP = class extends AutoConsentCMPBase {
2085
1682
  }
2086
1683
  };
2087
1684
  var AutoConsentHeuristicCMP = class extends AutoConsentCMPBase {
2088
- constructor(autoconsentInstance, mode = PopupHandlingModes.Reject) {
1685
+ constructor(autoconsentInstance, mode = "reject") {
2089
1686
  super(autoconsentInstance);
2090
1687
  this.popups = [];
2091
1688
  this.name = "HEURISTIC";
@@ -2112,7 +1709,7 @@ var AutoConsentHeuristicCMP = class extends AutoConsentCMPBase {
2112
1709
  this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorEnd");
2113
1710
  this.autoconsent.config.performanceLoggingEnabled && performance.measure("heuristicDetector", "heuristicDetectorStart", "heuristicDetectorEnd");
2114
1711
  if (this.popups.length > 0) {
2115
- this.name = `HEURISTIC-TIER${this.popups[0].regexClassification}`;
1712
+ this.name = `HEURISTIC-${this.popups[0].regexClassification?.toUpperCase()}`;
2116
1713
  return Promise.resolve(true);
2117
1714
  }
2118
1715
  return Promise.resolve(false);
@@ -2130,7 +1727,7 @@ var AutoConsentHeuristicCMP = class extends AutoConsentCMPBase {
2130
1727
  const popup = this.popups[0];
2131
1728
  const level = popup.regexClassification;
2132
1729
  const buttons = popup.buttons;
2133
- const targetButtonType = level === PopupHandlingModes.Reject ? "reject" : level === PopupHandlingModes.Tier1 ? "acknowledge" : "accept";
1730
+ const targetButtonType = level === "reject" ? "reject" : level === "tier1" ? "acknowledge" : "accept";
2134
1731
  return buttons.find((button) => button.regexClassification === targetButtonType);
2135
1732
  }
2136
1733
  optOut() {
@@ -2156,76 +1753,6 @@ var AutoConsentHeuristicCMP = class extends AutoConsentCMPBase {
2156
1753
  }
2157
1754
  };
2158
1755
 
2159
- // lib/cmps/consentomatic.ts
2160
- var ConsentOMaticCMP = class {
2161
- constructor(name, config) {
2162
- this.name = name;
2163
- this.config = config;
2164
- this.methods = /* @__PURE__ */ new Map();
2165
- this.runContext = defaultRunContext;
2166
- this.isCosmetic = false;
2167
- config.methods.forEach((methodConfig) => {
2168
- if (methodConfig.action) {
2169
- this.methods.set(methodConfig.name, methodConfig.action);
2170
- }
2171
- });
2172
- this.hasSelfTest = false;
2173
- }
2174
- get isIntermediate() {
2175
- return false;
2176
- }
2177
- checkRunContext() {
2178
- return true;
2179
- }
2180
- checkFrameContext(isTop) {
2181
- return true;
2182
- }
2183
- hasMatchingUrlPattern() {
2184
- return false;
2185
- }
2186
- async detectCmp() {
2187
- const matchResults = this.config.detectors.map((detectorConfig) => matches(detectorConfig.presentMatcher));
2188
- return matchResults.some((r) => !!r);
2189
- }
2190
- async detectPopup() {
2191
- const matchResults = this.config.detectors.map((detectorConfig) => matches(detectorConfig.showingMatcher));
2192
- return matchResults.some((r) => !!r);
2193
- }
2194
- async executeAction(method, param) {
2195
- if (this.methods.has(method)) {
2196
- return executeAction(this.methods.get(method), param);
2197
- }
2198
- return true;
2199
- }
2200
- async optOut() {
2201
- await this.executeAction("HIDE_CMP");
2202
- await this.executeAction("OPEN_OPTIONS");
2203
- await this.executeAction("HIDE_CMP");
2204
- await this.executeAction("DO_CONSENT", []);
2205
- await this.executeAction("SAVE_CONSENT");
2206
- return true;
2207
- }
2208
- async optIn() {
2209
- await this.executeAction("HIDE_CMP");
2210
- await this.executeAction("OPEN_OPTIONS");
2211
- await this.executeAction("HIDE_CMP");
2212
- await this.executeAction("DO_CONSENT", ["D", "A", "B", "E", "F", "X"]);
2213
- await this.executeAction("SAVE_CONSENT");
2214
- return true;
2215
- }
2216
- async openCmp() {
2217
- await this.executeAction("HIDE_CMP");
2218
- await this.executeAction("OPEN_OPTIONS");
2219
- return true;
2220
- }
2221
- async test() {
2222
- return true;
2223
- }
2224
- };
2225
-
2226
- // lib/rules.ts
2227
- var SUPPORTED_RULE_STEP_VERSION = 2;
2228
-
2229
1756
  // lib/cmps/trustarc-top.ts
2230
1757
  var cookieSettingsButton = "#truste-show-consent";
2231
1758
  var shortcutOptOut = "#truste-consent-required";
@@ -3253,15 +2780,15 @@ var DomActions = class {
3253
2780
  }
3254
2781
  querySelectorChain(selectors) {
3255
2782
  let parent = document;
3256
- let matches2 = [];
2783
+ let matches = [];
3257
2784
  for (const selector of selectors) {
3258
- matches2 = this.querySingleReplySelector(selector, parent);
3259
- if (matches2.length === 0) {
2785
+ matches = this.querySingleReplySelector(selector, parent);
2786
+ if (matches.length === 0) {
3260
2787
  return [];
3261
2788
  }
3262
- parent = matches2[0];
2789
+ parent = matches[0];
3263
2790
  }
3264
- return matches2;
2791
+ return matches;
3265
2792
  }
3266
2793
  elementSelector(selector) {
3267
2794
  if (typeof selector === "string") {
@@ -3640,8 +3167,6 @@ var AutoConsent = class {
3640
3167
  this.rules = [];
3641
3168
  __privateAdd(this, _config);
3642
3169
  this.state = {
3643
- cosmeticFiltersOn: false,
3644
- filterListReported: false,
3645
3170
  lifecycle: "loading",
3646
3171
  prehideOn: false,
3647
3172
  findCmpAttempts: 0,
@@ -3691,9 +3216,6 @@ var AutoConsent = class {
3691
3216
  if (declarativeRules) {
3692
3217
  this.parseDeclarativeRules(declarativeRules);
3693
3218
  }
3694
- if (config.enableFilterList) {
3695
- this.initializeFilterList();
3696
- }
3697
3219
  this.rules = filterCMPs(this.rules, normalizedConfig);
3698
3220
  if (this.shouldPrehide) {
3699
3221
  if (document.documentElement) {
@@ -3717,8 +3239,6 @@ var AutoConsent = class {
3717
3239
  }
3718
3240
  this.updateState({ lifecycle: "initialized" });
3719
3241
  }
3720
- initializeFilterList() {
3721
- }
3722
3242
  get shouldPrehide() {
3723
3243
  return this.config.enablePrehide && !this.config.visualTest;
3724
3244
  }
@@ -3747,11 +3267,6 @@ var AutoConsent = class {
3747
3267
  parseDeclarativeRules(declarativeRules) {
3748
3268
  const perfEnabled = __privateGet(this, _config)?.performanceLoggingEnabled;
3749
3269
  perfEnabled && performance.mark("parseDeclarativeRulesStart");
3750
- if (declarativeRules.consentomatic) {
3751
- for (const [name, rule] of Object.entries(declarativeRules.consentomatic)) {
3752
- this.addConsentomaticCMP(name, rule);
3753
- }
3754
- }
3755
3270
  if (declarativeRules.autoconsent) {
3756
3271
  declarativeRules.autoconsent.forEach((ruleset) => {
3757
3272
  this.addDeclarativeCMP(ruleset);
@@ -3773,9 +3288,6 @@ var AutoConsent = class {
3773
3288
  this.rules.push(new AutoConsentCMP(ruleset, this));
3774
3289
  }
3775
3290
  }
3776
- addConsentomaticCMP(name, config) {
3777
- this.rules.push(new ConsentOMaticCMP(`com_${name}`, config));
3778
- }
3779
3291
  // start the detection process, possibly with a delay
3780
3292
  start() {
3781
3293
  scheduleWhenIdle(() => this._start());
@@ -3794,7 +3306,8 @@ var AutoConsent = class {
3794
3306
  if (this.shouldPrehide) {
3795
3307
  this.undoPrehide();
3796
3308
  }
3797
- return this.filterListFallback();
3309
+ this.updateState({ lifecycle: "nothingDetected" });
3310
+ return false;
3798
3311
  }
3799
3312
  this.updateState({ lifecycle: "cmpDetected" });
3800
3313
  const staticCmps = [];
@@ -3852,7 +3365,7 @@ var AutoConsent = class {
3852
3365
  }
3853
3366
  }
3854
3367
  });
3855
- const heuristicRules = isTop && this.config.enableHeuristicAction && this.state.findCmpAttempts % 2 === 0 ? [new AutoConsentHeuristicCMP(this, this.config.heuristicMode)] : [];
3368
+ const heuristicRules = isTop && this.config.heuristicMode !== "off" && this.state.findCmpAttempts % 2 === 0 ? [new AutoConsentHeuristicCMP(this, this.config.heuristicMode)] : [];
3856
3369
  const rulesPriorityStages = [
3857
3370
  ["site-specific", siteSpecificRules],
3858
3371
  ["generic", genericRules],
@@ -3960,9 +3473,6 @@ var AutoConsent = class {
3960
3473
  if (this.shouldPrehide && !this.state.prehideOn) {
3961
3474
  this.prehideElements();
3962
3475
  }
3963
- if (this.state.cosmeticFiltersOn) {
3964
- this.undoCosmetics();
3965
- }
3966
3476
  this.foundCmp = cmp;
3967
3477
  if (this.config.autoAction === "optOut") {
3968
3478
  return await this.doOptOut();
@@ -4126,25 +3636,6 @@ var AutoConsent = class {
4126
3636
  this.updateState({ prehideOn: false });
4127
3637
  this.domActions.undoPrehide();
4128
3638
  }
4129
- undoCosmetics() {
4130
- }
4131
- reportFilterlist() {
4132
- this.sendContentMessage({
4133
- type: "cmpDetected",
4134
- url: location.href,
4135
- cmp: "filterList"
4136
- });
4137
- this.sendContentMessage({
4138
- type: "popupFound",
4139
- cmp: "filterList",
4140
- url: location.href
4141
- });
4142
- this.updateState({ filterListReported: true });
4143
- }
4144
- filterListFallback() {
4145
- this.updateState({ lifecycle: "nothingDetected" });
4146
- return false;
4147
- }
4148
3639
  updateState(change) {
4149
3640
  Object.assign(this.state, change);
4150
3641
  this.sendContentMessage({