@duckduckgo/autoconsent 8.2.0 → 9.0.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 (38) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/build.sh +1 -0
  3. package/dist/addon-firefox/background.bundle.js +45 -42
  4. package/dist/addon-firefox/content.bundle.js +468 -380
  5. package/dist/addon-firefox/manifest.json +1 -1
  6. package/dist/addon-mv3/background.bundle.js +45 -42
  7. package/dist/addon-mv3/content.bundle.js +468 -380
  8. package/dist/addon-mv3/manifest.json +1 -1
  9. package/dist/addon-mv3/popup.bundle.js +71 -33
  10. package/dist/addon-mv3/popup.html +28 -0
  11. package/dist/autoconsent.cjs.js +468 -380
  12. package/dist/autoconsent.esm.js +468 -380
  13. package/dist/autoconsent.playwright.js +1 -1
  14. package/dist/autoconsent.unit.js +10370 -0
  15. package/lib/cmps/airbnb.ts +5 -6
  16. package/lib/cmps/base.ts +97 -41
  17. package/lib/cmps/consentmanager.ts +13 -14
  18. package/lib/cmps/conversant.ts +8 -9
  19. package/lib/cmps/cookiebot.ts +8 -9
  20. package/lib/cmps/evidon.ts +7 -8
  21. package/lib/cmps/klaro.ts +13 -14
  22. package/lib/cmps/onetrust.ts +15 -16
  23. package/lib/cmps/sourcepoint-frame.ts +25 -26
  24. package/lib/cmps/tiktok.ts +7 -7
  25. package/lib/cmps/trustarc-frame.ts +27 -28
  26. package/lib/cmps/trustarc-top.ts +5 -6
  27. package/lib/cmps/uniconsent.ts +9 -10
  28. package/lib/dom-actions.ts +145 -0
  29. package/lib/types.ts +24 -1
  30. package/lib/utils.ts +32 -1
  31. package/lib/web.ts +46 -34
  32. package/package.json +4 -4
  33. package/playwright/runner.ts +11 -3
  34. package/playwright/unit.ts +15 -0
  35. package/readme.md +1 -1
  36. package/tests/{rule-executors.spec.ts → dom-actions.spec.ts} +20 -21
  37. package/lib/config.ts +0 -2
  38. package/lib/rule-executors.ts +0 -147
@@ -398,181 +398,6 @@
398
398
  });
399
399
  }
400
400
 
401
- // lib/config.ts
402
- var enableLogs = false;
403
-
404
- // lib/utils.ts
405
- function getStyleElement(styleOverrideElementId = "autoconsent-css-rules") {
406
- const styleSelector = `style#${styleOverrideElementId}`;
407
- const existingElement = document.querySelector(styleSelector);
408
- if (existingElement && existingElement instanceof HTMLStyleElement) {
409
- return existingElement;
410
- } else {
411
- const parent = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
412
- const css = document.createElement("style");
413
- css.id = styleOverrideElementId;
414
- parent.appendChild(css);
415
- return css;
416
- }
417
- }
418
- function hideElements(styleEl, selector, method = "display") {
419
- const hidingSnippet = method === "opacity" ? `opacity: 0` : `display: none`;
420
- const rule = `${selector} { ${hidingSnippet} !important; z-index: -1 !important; pointer-events: none !important; } `;
421
- if (styleEl instanceof HTMLStyleElement) {
422
- styleEl.innerText += rule;
423
- return selector.length > 0;
424
- }
425
- return false;
426
- }
427
- async function waitFor(predicate, maxTimes, interval) {
428
- const result = await predicate();
429
- if (!result && maxTimes > 0) {
430
- return new Promise((resolve) => {
431
- setTimeout(async () => {
432
- resolve(waitFor(predicate, maxTimes - 1, interval));
433
- }, interval);
434
- });
435
- }
436
- return Promise.resolve(result);
437
- }
438
- function isElementVisible(elem) {
439
- if (!elem) {
440
- return false;
441
- }
442
- if (elem.offsetParent !== null) {
443
- return true;
444
- } else {
445
- const css = window.getComputedStyle(elem);
446
- if (css.position === "fixed" && css.display !== "none") {
447
- return true;
448
- }
449
- }
450
- return false;
451
- }
452
-
453
- // lib/rule-executors.ts
454
- function click(selector, all = false) {
455
- const elem = elementSelector(selector);
456
- enableLogs && console.log("[click]", selector, all, elem);
457
- if (elem.length > 0) {
458
- if (all) {
459
- elem.forEach((e) => e.click());
460
- } else {
461
- elem[0].click();
462
- }
463
- }
464
- return elem.length > 0;
465
- }
466
- function elementExists(selector) {
467
- const exists = elementSelector(selector).length > 0;
468
- return exists;
469
- }
470
- function elementVisible(selector, check) {
471
- const elem = elementSelector(selector);
472
- const results = new Array(elem.length);
473
- elem.forEach((e, i) => {
474
- results[i] = isElementVisible(e);
475
- });
476
- if (check === "none") {
477
- return results.every((r) => !r);
478
- } else if (results.length === 0) {
479
- return false;
480
- } else if (check === "any") {
481
- return results.some((r) => r);
482
- }
483
- return results.every((r) => r);
484
- }
485
- function waitForElement(selector, timeout = 1e4) {
486
- const interval = 200;
487
- const times = Math.ceil(timeout / interval);
488
- enableLogs && console.log("[waitForElement]", selector);
489
- return waitFor(
490
- () => elementSelector(selector).length > 0,
491
- times,
492
- interval
493
- );
494
- }
495
- function waitForVisible(selector, timeout = 1e4, check = "any") {
496
- const interval = 200;
497
- const times = Math.ceil(timeout / interval);
498
- return waitFor(
499
- () => elementVisible(selector, check),
500
- times,
501
- interval
502
- );
503
- }
504
- async function waitForThenClick2(selector, timeout = 1e4, all = false) {
505
- await waitForElement(selector, timeout);
506
- return click(selector, all);
507
- }
508
- function wait(ms) {
509
- return new Promise((resolve) => {
510
- setTimeout(() => {
511
- resolve(true);
512
- }, ms);
513
- });
514
- }
515
- function hide(selector, method) {
516
- const styleEl = getStyleElement();
517
- return hideElements(styleEl, selector, method);
518
- }
519
- function prehide(selector) {
520
- const styleEl = getStyleElement("autoconsent-prehide");
521
- enableLogs && console.log("[prehide]", styleEl, location.href);
522
- return hideElements(styleEl, selector, "opacity");
523
- }
524
- function undoPrehide() {
525
- const existingElement = getStyleElement("autoconsent-prehide");
526
- enableLogs && console.log("[undoprehide]", existingElement, location.href);
527
- if (existingElement) {
528
- existingElement.remove();
529
- }
530
- return !!existingElement;
531
- }
532
- function querySingleReplySelector(selector, parent = document) {
533
- if (selector.startsWith("aria/")) {
534
- return [];
535
- }
536
- if (selector.startsWith("xpath/")) {
537
- const xpath = selector.slice(6);
538
- const result = document.evaluate(xpath, parent, null, XPathResult.ANY_TYPE, null);
539
- let node = null;
540
- const elements = [];
541
- while (node = result.iterateNext()) {
542
- elements.push(node);
543
- }
544
- return elements;
545
- }
546
- if (selector.startsWith("text/")) {
547
- return [];
548
- }
549
- if (selector.startsWith("pierce/")) {
550
- return [];
551
- }
552
- if (parent.shadowRoot) {
553
- return Array.from(parent.shadowRoot.querySelectorAll(selector));
554
- }
555
- return Array.from(parent.querySelectorAll(selector));
556
- }
557
- function querySelectorChain(selectors) {
558
- let parent = document;
559
- let matches2;
560
- for (const selector of selectors) {
561
- matches2 = querySingleReplySelector(selector, parent);
562
- if (matches2.length === 0) {
563
- return [];
564
- }
565
- parent = matches2[0];
566
- }
567
- return matches2;
568
- }
569
- function elementSelector(selector) {
570
- if (typeof selector === "string") {
571
- return querySingleReplySelector(selector);
572
- }
573
- return querySelectorChain(selector);
574
- }
575
-
576
401
  // lib/random.ts
577
402
  function getRandomID() {
578
403
  if (crypto && typeof crypto.randomUUID !== "undefined") {
@@ -782,20 +607,21 @@
782
607
  console.warn("Snippet not found", snippetId);
783
608
  return Promise.resolve(false);
784
609
  }
610
+ const logsConfig = this.autoconsent.config.logs;
785
611
  if (this.autoconsent.config.isMainWorld) {
786
- enableLogs && console.log("inline eval:", snippetId, snippet);
612
+ logsConfig.evals && console.log("inline eval:", snippetId, snippet);
787
613
  let result = false;
788
614
  try {
789
615
  result = !!snippet.call(globalThis);
790
616
  } catch (e) {
791
- enableLogs && console.error("error evaluating rule", snippetId, e);
617
+ logsConfig.evals && console.error("error evaluating rule", snippetId, e);
792
618
  }
793
619
  return Promise.resolve(result);
794
620
  }
795
621
  const snippetSrc = getFunctionBody(snippet);
796
- enableLogs && console.log("async eval:", snippetId, snippetSrc);
622
+ logsConfig.evals && console.log("async eval:", snippetId, snippetSrc);
797
623
  return requestEval(snippetSrc, snippetId).catch((e) => {
798
- enableLogs && console.error("error evaluating rule", snippetId, e);
624
+ logsConfig.evals && console.error("error evaluating rule", snippetId, e);
799
625
  return false;
800
626
  });
801
627
  }
@@ -834,93 +660,136 @@
834
660
  async test() {
835
661
  return Promise.resolve(true);
836
662
  }
663
+ // Implementing DomActionsProvider below:
664
+ click(selector, all = false) {
665
+ return this.autoconsent.domActions.click(selector, all);
666
+ }
667
+ elementExists(selector) {
668
+ return this.autoconsent.domActions.elementExists(selector);
669
+ }
670
+ elementVisible(selector, check) {
671
+ return this.autoconsent.domActions.elementVisible(selector, check);
672
+ }
673
+ waitForElement(selector, timeout) {
674
+ return this.autoconsent.domActions.waitForElement(selector, timeout);
675
+ }
676
+ waitForVisible(selector, timeout, check) {
677
+ return this.autoconsent.domActions.waitForVisible(selector, timeout, check);
678
+ }
679
+ waitForThenClick(selector, timeout, all) {
680
+ return this.autoconsent.domActions.waitForThenClick(selector, timeout, all);
681
+ }
682
+ wait(ms) {
683
+ return this.autoconsent.domActions.wait(ms);
684
+ }
685
+ hide(selector, method) {
686
+ return this.autoconsent.domActions.hide(selector, method);
687
+ }
688
+ prehide(selector) {
689
+ return this.autoconsent.domActions.prehide(selector);
690
+ }
691
+ undoPrehide() {
692
+ return this.autoconsent.domActions.undoPrehide();
693
+ }
694
+ querySingleReplySelector(selector, parent) {
695
+ return this.autoconsent.domActions.querySingleReplySelector(selector, parent);
696
+ }
697
+ querySelectorChain(selectors) {
698
+ return this.autoconsent.domActions.querySelectorChain(selectors);
699
+ }
700
+ elementSelector(selector) {
701
+ return this.autoconsent.domActions.elementSelector(selector);
702
+ }
837
703
  };
838
704
  var AutoConsentCMP = class extends AutoConsentCMPBase {
839
- constructor(config, autoconsentInstance) {
705
+ constructor(rule, autoconsentInstance) {
840
706
  super(autoconsentInstance);
841
- this.config = config;
842
- this.name = config.name;
843
- this.runContext = config.runContext || defaultRunContext;
707
+ this.rule = rule;
708
+ this.name = rule.name;
709
+ this.runContext = rule.runContext || defaultRunContext;
844
710
  }
845
711
  get hasSelfTest() {
846
- return !!this.config.test;
712
+ return !!this.rule.test;
847
713
  }
848
714
  get isIntermediate() {
849
- return !!this.config.intermediate;
715
+ return !!this.rule.intermediate;
850
716
  }
851
717
  get isCosmetic() {
852
- return !!this.config.cosmetic;
718
+ return !!this.rule.cosmetic;
853
719
  }
854
720
  get prehideSelectors() {
855
- return this.config.prehideSelectors;
721
+ return this.rule.prehideSelectors;
856
722
  }
857
723
  async detectCmp() {
858
- if (this.config.detectCmp) {
859
- return this._runRulesParallel(this.config.detectCmp);
724
+ if (this.rule.detectCmp) {
725
+ return this._runRulesParallel(this.rule.detectCmp);
860
726
  }
861
727
  return false;
862
728
  }
863
729
  async detectPopup() {
864
- if (this.config.detectPopup) {
865
- return this._runRulesSequentially(this.config.detectPopup);
730
+ if (this.rule.detectPopup) {
731
+ return this._runRulesSequentially(this.rule.detectPopup);
866
732
  }
867
733
  return false;
868
734
  }
869
735
  async optOut() {
870
- if (this.config.optOut) {
871
- enableLogs && console.log("Initiated optOut()", this.config.optOut);
872
- return this._runRulesSequentially(this.config.optOut);
736
+ const logsConfig = this.autoconsent.config.logs;
737
+ if (this.rule.optOut) {
738
+ logsConfig.lifecycle && console.log("Initiated optOut()", this.rule.optOut);
739
+ return this._runRulesSequentially(this.rule.optOut);
873
740
  }
874
741
  return false;
875
742
  }
876
743
  async optIn() {
877
- if (this.config.optIn) {
878
- enableLogs && console.log("Initiated optIn()", this.config.optIn);
879
- return this._runRulesSequentially(this.config.optIn);
744
+ const logsConfig = this.autoconsent.config.logs;
745
+ if (this.rule.optIn) {
746
+ logsConfig.lifecycle && console.log("Initiated optIn()", this.rule.optIn);
747
+ return this._runRulesSequentially(this.rule.optIn);
880
748
  }
881
749
  return false;
882
750
  }
883
751
  async openCmp() {
884
- if (this.config.openCmp) {
885
- return this._runRulesSequentially(this.config.openCmp);
752
+ if (this.rule.openCmp) {
753
+ return this._runRulesSequentially(this.rule.openCmp);
886
754
  }
887
755
  return false;
888
756
  }
889
757
  async test() {
890
758
  if (this.hasSelfTest) {
891
- return this._runRulesSequentially(this.config.test);
759
+ return this._runRulesSequentially(this.rule.test);
892
760
  }
893
761
  return super.test();
894
762
  }
895
763
  async evaluateRuleStep(rule) {
896
764
  const results = [];
765
+ const logsConfig = this.autoconsent.config.logs;
897
766
  if (rule.exists) {
898
- results.push(elementExists(rule.exists));
767
+ results.push(this.elementExists(rule.exists));
899
768
  }
900
769
  if (rule.visible) {
901
- results.push(elementVisible(rule.visible, rule.check));
770
+ results.push(this.elementVisible(rule.visible, rule.check));
902
771
  }
903
772
  if (rule.eval) {
904
773
  const res = this.mainWorldEval(rule.eval);
905
774
  results.push(res);
906
775
  }
907
776
  if (rule.waitFor) {
908
- results.push(waitForElement(rule.waitFor, rule.timeout));
777
+ results.push(this.waitForElement(rule.waitFor, rule.timeout));
909
778
  }
910
779
  if (rule.waitForVisible) {
911
- results.push(waitForVisible(rule.waitForVisible, rule.timeout, rule.check));
780
+ results.push(this.waitForVisible(rule.waitForVisible, rule.timeout, rule.check));
912
781
  }
913
782
  if (rule.click) {
914
- results.push(click(rule.click, rule.all));
783
+ results.push(this.click(rule.click, rule.all));
915
784
  }
916
785
  if (rule.waitForThenClick) {
917
- results.push(waitForThenClick2(rule.waitForThenClick, rule.timeout, rule.all));
786
+ results.push(this.waitForThenClick(rule.waitForThenClick, rule.timeout, rule.all));
918
787
  }
919
788
  if (rule.wait) {
920
- results.push(wait(rule.wait));
789
+ results.push(this.wait(rule.wait));
921
790
  }
922
791
  if (rule.hide) {
923
- results.push(hide(rule.hide, rule.method));
792
+ results.push(this.hide(rule.hide, rule.method));
924
793
  }
925
794
  if (rule.if) {
926
795
  if (!rule.if.exists && !rule.if.visible) {
@@ -928,7 +797,7 @@
928
797
  return false;
929
798
  }
930
799
  const condition = await this.evaluateRuleStep(rule.if);
931
- enableLogs && console.log("Condition is", condition);
800
+ logsConfig.rulesteps && console.log("Condition is", condition);
932
801
  if (condition) {
933
802
  results.push(this._runRulesSequentially(rule.then));
934
803
  } else if (rule.else) {
@@ -944,7 +813,7 @@
944
813
  return false;
945
814
  }
946
815
  if (results.length === 0) {
947
- enableLogs && console.warn("Unrecognized rule", rule);
816
+ logsConfig.errors && console.warn("Unrecognized rule", rule);
948
817
  return false;
949
818
  }
950
819
  const all = await Promise.all(results);
@@ -956,10 +825,11 @@
956
825
  return detections.every((r) => !!r);
957
826
  }
958
827
  async _runRulesSequentially(rules) {
828
+ const logsConfig = this.autoconsent.config.logs;
959
829
  for (const rule of rules) {
960
- enableLogs && console.log("Running rule...", rule);
830
+ logsConfig.rulesteps && console.log("Running rule...", rule);
961
831
  const result = await this.evaluateRuleStep(rule);
962
- enableLogs && console.log("...rule result", result);
832
+ logsConfig.rulesteps && console.log("...rule result", result);
963
833
  if (!result && !rule.optional) {
964
834
  return false;
965
835
  }
@@ -1033,6 +903,82 @@
1033
903
  }
1034
904
  };
1035
905
 
906
+ // lib/utils.ts
907
+ function getStyleElement(styleOverrideElementId = "autoconsent-css-rules") {
908
+ const styleSelector = `style#${styleOverrideElementId}`;
909
+ const existingElement = document.querySelector(styleSelector);
910
+ if (existingElement && existingElement instanceof HTMLStyleElement) {
911
+ return existingElement;
912
+ } else {
913
+ const parent = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
914
+ const css = document.createElement("style");
915
+ css.id = styleOverrideElementId;
916
+ parent.appendChild(css);
917
+ return css;
918
+ }
919
+ }
920
+ function hideElements(styleEl, selector, method = "display") {
921
+ const hidingSnippet = method === "opacity" ? `opacity: 0` : `display: none`;
922
+ const rule = `${selector} { ${hidingSnippet} !important; z-index: -1 !important; pointer-events: none !important; } `;
923
+ if (styleEl instanceof HTMLStyleElement) {
924
+ styleEl.innerText += rule;
925
+ return selector.length > 0;
926
+ }
927
+ return false;
928
+ }
929
+ async function waitFor(predicate, maxTimes, interval) {
930
+ const result = await predicate();
931
+ if (!result && maxTimes > 0) {
932
+ return new Promise((resolve) => {
933
+ setTimeout(async () => {
934
+ resolve(waitFor(predicate, maxTimes - 1, interval));
935
+ }, interval);
936
+ });
937
+ }
938
+ return Promise.resolve(result);
939
+ }
940
+ function isElementVisible(elem) {
941
+ if (!elem) {
942
+ return false;
943
+ }
944
+ if (elem.offsetParent !== null) {
945
+ return true;
946
+ } else {
947
+ const css = window.getComputedStyle(elem);
948
+ if (css.position === "fixed" && css.display !== "none") {
949
+ return true;
950
+ }
951
+ }
952
+ return false;
953
+ }
954
+ function normalizeConfig(providedConfig) {
955
+ const defaultConfig = {
956
+ enabled: true,
957
+ autoAction: "optOut",
958
+ // if falsy, the extension will wait for an explicit user signal before opting in/out
959
+ disabledCmps: [],
960
+ enablePrehide: true,
961
+ enableCosmeticRules: true,
962
+ detectRetries: 20,
963
+ isMainWorld: false,
964
+ prehideTimeout: 2e3,
965
+ logs: {
966
+ lifecycle: false,
967
+ rulesteps: false,
968
+ evals: false,
969
+ errors: true,
970
+ messages: false
971
+ }
972
+ };
973
+ const updatedConfig = structuredClone(defaultConfig);
974
+ for (const key of Object.keys(defaultConfig)) {
975
+ if (typeof providedConfig[key] !== "undefined") {
976
+ updatedConfig[key] = providedConfig[key];
977
+ }
978
+ }
979
+ return updatedConfig;
980
+ }
981
+
1036
982
  // lib/cmps/trustarc-top.ts
1037
983
  var cookieSettingsButton = "#truste-show-consent";
1038
984
  var shortcutOptOut = "#truste-consent-required";
@@ -1068,17 +1014,17 @@
1068
1014
  return false;
1069
1015
  }
1070
1016
  async detectCmp() {
1071
- const result = elementExists(`${cookieSettingsButton},${bannerContainer}`);
1017
+ const result = this.elementExists(`${cookieSettingsButton},${bannerContainer}`);
1072
1018
  if (result) {
1073
1019
  this._shortcutButton = document.querySelector(shortcutOptOut);
1074
1020
  }
1075
1021
  return result;
1076
1022
  }
1077
1023
  async detectPopup() {
1078
- return elementVisible(`${popupContent},${bannerOverlay},${bannerContainer}`, "all");
1024
+ return this.elementVisible(`${popupContent},${bannerOverlay},${bannerContainer}`, "all");
1079
1025
  }
1080
1026
  openFrame() {
1081
- click(cookieSettingsButton);
1027
+ this.click(cookieSettingsButton);
1082
1028
  }
1083
1029
  async optOut() {
1084
1030
  if (this._shortcutButton) {
@@ -1089,7 +1035,7 @@
1089
1035
  getStyleElement(),
1090
1036
  `.truste_popframe, .truste_overlay, .truste_box_overlay, ${bannerContainer}`
1091
1037
  );
1092
- click(cookieSettingsButton);
1038
+ this.click(cookieSettingsButton);
1093
1039
  setTimeout(() => {
1094
1040
  getStyleElement().remove();
1095
1041
  }, 1e4);
@@ -1097,7 +1043,7 @@
1097
1043
  }
1098
1044
  async optIn() {
1099
1045
  this._optInDone = true;
1100
- return click(shortcutOptIn);
1046
+ return this.click(shortcutOptIn);
1101
1047
  }
1102
1048
  async openCmp() {
1103
1049
  return true;
@@ -1131,62 +1077,62 @@
1131
1077
  return true;
1132
1078
  }
1133
1079
  async detectPopup() {
1134
- return elementVisible("#defaultpreferencemanager", "any") && elementVisible(".mainContent", "any");
1080
+ return this.elementVisible("#defaultpreferencemanager", "any") && this.elementVisible(".mainContent", "any");
1135
1081
  }
1136
1082
  async navigateToSettings() {
1137
1083
  await waitFor(
1138
1084
  async () => {
1139
- return elementExists(".shp") || elementVisible(".advance", "any") || elementExists(".switch span:first-child");
1085
+ return this.elementExists(".shp") || this.elementVisible(".advance", "any") || this.elementExists(".switch span:first-child");
1140
1086
  },
1141
1087
  10,
1142
1088
  500
1143
1089
  );
1144
- if (elementExists(".shp")) {
1145
- click(".shp");
1090
+ if (this.elementExists(".shp")) {
1091
+ this.click(".shp");
1146
1092
  }
1147
- await waitForElement(".prefPanel", 5e3);
1148
- if (elementVisible(".advance", "any")) {
1149
- click(".advance");
1093
+ await this.waitForElement(".prefPanel", 5e3);
1094
+ if (this.elementVisible(".advance", "any")) {
1095
+ this.click(".advance");
1150
1096
  }
1151
1097
  return await waitFor(
1152
- () => elementVisible(".switch span:first-child", "any"),
1098
+ () => this.elementVisible(".switch span:first-child", "any"),
1153
1099
  5,
1154
1100
  1e3
1155
1101
  );
1156
1102
  }
1157
1103
  async optOut() {
1158
1104
  await waitFor(() => document.readyState === "complete", 20, 100);
1159
- await waitForElement(".mainContent[aria-hidden=false]", 5e3);
1160
- if (click(".rejectAll")) {
1105
+ await this.waitForElement(".mainContent[aria-hidden=false]", 5e3);
1106
+ if (this.click(".rejectAll")) {
1161
1107
  return true;
1162
1108
  }
1163
- if (elementExists(".prefPanel")) {
1164
- await waitForElement('.prefPanel[style="visibility: visible;"]', 3e3);
1109
+ if (this.elementExists(".prefPanel")) {
1110
+ await this.waitForElement('.prefPanel[style="visibility: visible;"]', 3e3);
1165
1111
  }
1166
- if (click("#catDetails0")) {
1167
- click(".submit");
1168
- waitForThenClick("#gwt-debug-close_id", 5e3);
1112
+ if (this.click("#catDetails0")) {
1113
+ this.click(".submit");
1114
+ this.waitForThenClick("#gwt-debug-close_id", 5e3);
1169
1115
  return true;
1170
1116
  }
1171
- if (click(".required")) {
1172
- waitForThenClick("#gwt-debug-close_id", 5e3);
1117
+ if (this.click(".required")) {
1118
+ this.waitForThenClick("#gwt-debug-close_id", 5e3);
1173
1119
  return true;
1174
1120
  }
1175
1121
  await this.navigateToSettings();
1176
- click(".switch span:nth-child(1):not(.active)", true);
1177
- click(".submit");
1178
- waitForThenClick("#gwt-debug-close_id", 3e5);
1122
+ this.click(".switch span:nth-child(1):not(.active)", true);
1123
+ this.click(".submit");
1124
+ this.waitForThenClick("#gwt-debug-close_id", 3e5);
1179
1125
  return true;
1180
1126
  }
1181
1127
  async optIn() {
1182
- if (click(".call")) {
1128
+ if (this.click(".call")) {
1183
1129
  return true;
1184
1130
  }
1185
1131
  await this.navigateToSettings();
1186
- click(".switch span:nth-child(2)", true);
1187
- click(".submit");
1188
- waitForElement("#gwt-debug-close_id", 3e5).then(() => {
1189
- click("#gwt-debug-close_id");
1132
+ this.click(".switch span:nth-child(2)", true);
1133
+ this.click(".submit");
1134
+ this.waitForElement("#gwt-debug-close_id", 3e5).then(() => {
1135
+ this.click("#gwt-debug-close_id");
1190
1136
  });
1191
1137
  return true;
1192
1138
  }
@@ -1215,23 +1161,23 @@
1215
1161
  return this.mainWorldEval("EVAL_COOKIEBOT_2");
1216
1162
  }
1217
1163
  async optOut() {
1218
- await wait(500);
1164
+ await this.wait(500);
1219
1165
  let res = await this.mainWorldEval("EVAL_COOKIEBOT_3");
1220
- await wait(500);
1166
+ await this.wait(500);
1221
1167
  res = res && await this.mainWorldEval("EVAL_COOKIEBOT_4");
1222
1168
  return res;
1223
1169
  }
1224
1170
  async optIn() {
1225
- if (elementExists("#dtcookie-container")) {
1226
- return click(".h-dtcookie-accept");
1171
+ if (this.elementExists("#dtcookie-container")) {
1172
+ return this.click(".h-dtcookie-accept");
1227
1173
  }
1228
- click(".CybotCookiebotDialogBodyLevelButton:not(:checked):enabled", true);
1229
- click("#CybotCookiebotDialogBodyLevelButtonAccept");
1230
- click("#CybotCookiebotDialogBodyButtonAccept");
1174
+ this.click(".CybotCookiebotDialogBodyLevelButton:not(:checked):enabled", true);
1175
+ this.click("#CybotCookiebotDialogBodyLevelButtonAccept");
1176
+ this.click("#CybotCookiebotDialogBodyButtonAccept");
1231
1177
  return true;
1232
1178
  }
1233
1179
  async test() {
1234
- await wait(500);
1180
+ await this.wait(500);
1235
1181
  return await this.mainWorldEval("EVAL_COOKIEBOT_5");
1236
1182
  }
1237
1183
  };
@@ -1275,17 +1221,17 @@
1275
1221
  return true;
1276
1222
  }
1277
1223
  if (this.ccpaPopup) {
1278
- return await waitForElement(".priv-save-btn", 2e3);
1224
+ return await this.waitForElement(".priv-save-btn", 2e3);
1279
1225
  }
1280
- await waitForElement(".sp_choice_type_11,.sp_choice_type_12,.sp_choice_type_13,.sp_choice_type_ACCEPT_ALL,.sp_choice_type_SAVE_AND_EXIT", 2e3);
1281
- return !elementExists(".sp_choice_type_9");
1226
+ await this.waitForElement(".sp_choice_type_11,.sp_choice_type_12,.sp_choice_type_13,.sp_choice_type_ACCEPT_ALL,.sp_choice_type_SAVE_AND_EXIT", 2e3);
1227
+ return !this.elementExists(".sp_choice_type_9");
1282
1228
  }
1283
1229
  async optIn() {
1284
- await waitForElement(".sp_choice_type_11,.sp_choice_type_ACCEPT_ALL", 2e3);
1285
- if (click(".sp_choice_type_11")) {
1230
+ await this.waitForElement(".sp_choice_type_11,.sp_choice_type_ACCEPT_ALL", 2e3);
1231
+ if (this.click(".sp_choice_type_11")) {
1286
1232
  return true;
1287
1233
  }
1288
- if (click(".sp_choice_type_ACCEPT_ALL")) {
1234
+ if (this.click(".sp_choice_type_ACCEPT_ALL")) {
1289
1235
  return true;
1290
1236
  }
1291
1237
  return false;
@@ -1294,6 +1240,7 @@
1294
1240
  return location.pathname === "/privacy-manager/index.html" || location.pathname === "/ccpa_pm/index.html";
1295
1241
  }
1296
1242
  async optOut() {
1243
+ const logsConfig = this.autoconsent.config.logs;
1297
1244
  if (this.ccpaPopup) {
1298
1245
  const toggles = document.querySelectorAll(".priv-purpose-container .sp-switch-arrow-block a.neutral.on .right");
1299
1246
  for (const t of toggles) {
@@ -1303,47 +1250,47 @@
1303
1250
  for (const t of switches) {
1304
1251
  t.click();
1305
1252
  }
1306
- return click(".priv-save-btn");
1253
+ return this.click(".priv-save-btn");
1307
1254
  }
1308
1255
  if (!this.isManagerOpen()) {
1309
- const actionable = await waitForElement(".sp_choice_type_12,.sp_choice_type_13");
1256
+ const actionable = await this.waitForElement(".sp_choice_type_12,.sp_choice_type_13");
1310
1257
  if (!actionable) {
1311
1258
  return false;
1312
1259
  }
1313
- if (!elementExists(".sp_choice_type_12")) {
1314
- return click(".sp_choice_type_13");
1260
+ if (!this.elementExists(".sp_choice_type_12")) {
1261
+ return this.click(".sp_choice_type_13");
1315
1262
  }
1316
- click(".sp_choice_type_12");
1263
+ this.click(".sp_choice_type_12");
1317
1264
  await waitFor(
1318
1265
  () => this.isManagerOpen(),
1319
1266
  200,
1320
1267
  100
1321
1268
  );
1322
1269
  }
1323
- await waitForElement(".type-modal", 2e4);
1324
- waitForThenClick2(".ccpa-stack .pm-switch[aria-checked=true] .slider", 500, true);
1270
+ await this.waitForElement(".type-modal", 2e4);
1271
+ this.waitForThenClick(".ccpa-stack .pm-switch[aria-checked=true] .slider", 500, true);
1325
1272
  try {
1326
1273
  const rejectSelector1 = ".sp_choice_type_REJECT_ALL";
1327
1274
  const rejectSelector2 = ".reject-toggle";
1328
1275
  const path = await Promise.race([
1329
- waitForElement(rejectSelector1, 2e3).then((success) => success ? 0 : -1),
1330
- waitForElement(rejectSelector2, 2e3).then((success) => success ? 1 : -1),
1331
- waitForElement(".pm-features", 2e3).then((success) => success ? 2 : -1)
1276
+ this.waitForElement(rejectSelector1, 2e3).then((success) => success ? 0 : -1),
1277
+ this.waitForElement(rejectSelector2, 2e3).then((success) => success ? 1 : -1),
1278
+ this.waitForElement(".pm-features", 2e3).then((success) => success ? 2 : -1)
1332
1279
  ]);
1333
1280
  if (path === 0) {
1334
- await wait(1e3);
1335
- return click(rejectSelector1);
1281
+ await this.wait(1e3);
1282
+ return this.click(rejectSelector1);
1336
1283
  } else if (path === 1) {
1337
- click(rejectSelector2);
1284
+ this.click(rejectSelector2);
1338
1285
  } else if (path === 2) {
1339
- await waitForElement(".pm-features", 1e4);
1340
- click(".checked > span", true);
1341
- click(".chevron");
1286
+ await this.waitForElement(".pm-features", 1e4);
1287
+ this.click(".checked > span", true);
1288
+ this.click(".chevron");
1342
1289
  }
1343
1290
  } catch (e) {
1344
- enableLogs && console.warn(e);
1291
+ logsConfig.errors && console.warn(e);
1345
1292
  }
1346
- return click(".sp_choice_type_SAVE_AND_EXIT");
1293
+ return this.click(".sp_choice_type_SAVE_AND_EXIT");
1347
1294
  }
1348
1295
  };
1349
1296
 
@@ -1367,42 +1314,42 @@
1367
1314
  async detectCmp() {
1368
1315
  this.apiAvailable = await this.mainWorldEval("EVAL_CONSENTMANAGER_1");
1369
1316
  if (!this.apiAvailable) {
1370
- return elementExists("#cmpbox");
1317
+ return this.elementExists("#cmpbox");
1371
1318
  } else {
1372
1319
  return true;
1373
1320
  }
1374
1321
  }
1375
1322
  async detectPopup() {
1376
1323
  if (this.apiAvailable) {
1377
- await wait(500);
1324
+ await this.wait(500);
1378
1325
  return await this.mainWorldEval("EVAL_CONSENTMANAGER_2");
1379
1326
  }
1380
- return elementVisible("#cmpbox .cmpmore", "any");
1327
+ return this.elementVisible("#cmpbox .cmpmore", "any");
1381
1328
  }
1382
1329
  async optOut() {
1383
- await wait(500);
1330
+ await this.wait(500);
1384
1331
  if (this.apiAvailable) {
1385
1332
  return await this.mainWorldEval("EVAL_CONSENTMANAGER_3");
1386
1333
  }
1387
- if (click(".cmpboxbtnno")) {
1334
+ if (this.click(".cmpboxbtnno")) {
1388
1335
  return true;
1389
1336
  }
1390
- if (elementExists(".cmpwelcomeprpsbtn")) {
1391
- click(".cmpwelcomeprpsbtn > a[aria-checked=true]", true);
1392
- click(".cmpboxbtnsave");
1337
+ if (this.elementExists(".cmpwelcomeprpsbtn")) {
1338
+ this.click(".cmpwelcomeprpsbtn > a[aria-checked=true]", true);
1339
+ this.click(".cmpboxbtnsave");
1393
1340
  return true;
1394
1341
  }
1395
- click(".cmpboxbtncustom");
1396
- await waitForElement(".cmptblbox", 2e3);
1397
- click(".cmptdchoice > a[aria-checked=true]", true);
1398
- click(".cmpboxbtnyescustomchoices");
1342
+ this.click(".cmpboxbtncustom");
1343
+ await this.waitForElement(".cmptblbox", 2e3);
1344
+ this.click(".cmptdchoice > a[aria-checked=true]", true);
1345
+ this.click(".cmpboxbtnyescustomchoices");
1399
1346
  return true;
1400
1347
  }
1401
1348
  async optIn() {
1402
1349
  if (this.apiAvailable) {
1403
1350
  return await this.mainWorldEval("EVAL_CONSENTMANAGER_4");
1404
1351
  }
1405
- return click(".cmpboxbtnyes");
1352
+ return this.click(".cmpboxbtnyes");
1406
1353
  }
1407
1354
  async test() {
1408
1355
  if (this.apiAvailable) {
@@ -1427,23 +1374,23 @@
1427
1374
  return false;
1428
1375
  }
1429
1376
  async detectCmp() {
1430
- return elementExists("#_evidon_banner");
1377
+ return this.elementExists("#_evidon_banner");
1431
1378
  }
1432
1379
  async detectPopup() {
1433
- return elementVisible("#_evidon_banner", "any");
1380
+ return this.elementVisible("#_evidon_banner", "any");
1434
1381
  }
1435
1382
  async optOut() {
1436
- if (click("#_evidon-decline-button")) {
1383
+ if (this.click("#_evidon-decline-button")) {
1437
1384
  return true;
1438
1385
  }
1439
1386
  hideElements(getStyleElement(), "#evidon-prefdiag-overlay,#evidon-prefdiag-background");
1440
- click("#_evidon-option-button");
1441
- await waitForElement("#evidon-prefdiag-overlay", 5e3);
1442
- click("#evidon-prefdiag-decline");
1387
+ this.click("#_evidon-option-button");
1388
+ await this.waitForElement("#evidon-prefdiag-overlay", 5e3);
1389
+ this.click("#evidon-prefdiag-decline");
1443
1390
  return true;
1444
1391
  }
1445
1392
  async optIn() {
1446
- return click("#_evidon-accept-button");
1393
+ return this.click("#_evidon-accept-button");
1447
1394
  }
1448
1395
  };
1449
1396
 
@@ -1467,31 +1414,31 @@
1467
1414
  return false;
1468
1415
  }
1469
1416
  async detectCmp() {
1470
- return elementExists("#onetrust-banner-sdk");
1417
+ return this.elementExists("#onetrust-banner-sdk");
1471
1418
  }
1472
1419
  async detectPopup() {
1473
- return elementVisible("#onetrust-banner-sdk", "all");
1420
+ return this.elementVisible("#onetrust-banner-sdk", "all");
1474
1421
  }
1475
1422
  async optOut() {
1476
- if (elementVisible("#onetrust-reject-all-handler,.js-reject-cookies", "any")) {
1477
- return click("#onetrust-reject-all-handler,.js-reject-cookies");
1423
+ if (this.elementVisible("#onetrust-reject-all-handler,.js-reject-cookies", "any")) {
1424
+ return this.click("#onetrust-reject-all-handler,.js-reject-cookies");
1478
1425
  }
1479
- if (elementExists("#onetrust-pc-btn-handler")) {
1480
- click("#onetrust-pc-btn-handler");
1426
+ if (this.elementExists("#onetrust-pc-btn-handler")) {
1427
+ this.click("#onetrust-pc-btn-handler");
1481
1428
  } else {
1482
- click(".ot-sdk-show-settings,button.js-cookie-settings");
1483
- }
1484
- await waitForElement("#onetrust-consent-sdk", 2e3);
1485
- await wait(1e3);
1486
- click("#onetrust-consent-sdk input.category-switch-handler:checked,.js-editor-toggle-state:checked", true);
1487
- await wait(1e3);
1488
- await waitForElement(".save-preference-btn-handler,.js-consent-save", 2e3);
1489
- click(".save-preference-btn-handler,.js-consent-save");
1490
- await waitForVisible("#onetrust-banner-sdk", 5e3, "none");
1429
+ this.click(".ot-sdk-show-settings,button.js-cookie-settings");
1430
+ }
1431
+ await this.waitForElement("#onetrust-consent-sdk", 2e3);
1432
+ await this.wait(1e3);
1433
+ this.click("#onetrust-consent-sdk input.category-switch-handler:checked,.js-editor-toggle-state:checked", true);
1434
+ await this.wait(1e3);
1435
+ await this.waitForElement(".save-preference-btn-handler,.js-consent-save", 2e3);
1436
+ this.click(".save-preference-btn-handler,.js-consent-save");
1437
+ await this.waitForVisible("#onetrust-banner-sdk", 5e3, "none");
1491
1438
  return true;
1492
1439
  }
1493
1440
  async optIn() {
1494
- return click("#onetrust-accept-btn-handler,.js-accept-cookies");
1441
+ return this.click("#onetrust-accept-btn-handler,.js-accept-cookies");
1495
1442
  }
1496
1443
  async test() {
1497
1444
  return await waitFor(
@@ -1520,39 +1467,39 @@
1520
1467
  return false;
1521
1468
  }
1522
1469
  async detectCmp() {
1523
- if (elementExists(".klaro > .cookie-modal")) {
1470
+ if (this.elementExists(".klaro > .cookie-modal")) {
1524
1471
  this.settingsOpen = true;
1525
1472
  return true;
1526
1473
  }
1527
- return elementExists(".klaro > .cookie-notice");
1474
+ return this.elementExists(".klaro > .cookie-notice");
1528
1475
  }
1529
1476
  async detectPopup() {
1530
- return elementVisible(".klaro > .cookie-notice,.klaro > .cookie-modal", "any");
1477
+ return this.elementVisible(".klaro > .cookie-notice,.klaro > .cookie-modal", "any");
1531
1478
  }
1532
1479
  async optOut() {
1533
- if (click(".klaro .cn-decline")) {
1480
+ if (this.click(".klaro .cn-decline")) {
1534
1481
  return true;
1535
1482
  }
1536
1483
  if (!this.settingsOpen) {
1537
- click(".klaro .cn-learn-more,.klaro .cm-button-manage");
1538
- await waitForElement(".klaro > .cookie-modal", 2e3);
1484
+ this.click(".klaro .cn-learn-more,.klaro .cm-button-manage");
1485
+ await this.waitForElement(".klaro > .cookie-modal", 2e3);
1539
1486
  this.settingsOpen = true;
1540
1487
  }
1541
- if (click(".klaro .cn-decline")) {
1488
+ if (this.click(".klaro .cn-decline")) {
1542
1489
  return true;
1543
1490
  }
1544
- click(".cm-purpose:not(.cm-toggle-all) > input:not(.half-checked,.required,.only-required),.cm-purpose:not(.cm-toggle-all) > div > input:not(.half-checked,.required,.only-required)", true);
1545
- return click(".cm-btn-accept,.cm-button");
1491
+ this.click(".cm-purpose:not(.cm-toggle-all) > input:not(.half-checked,.required,.only-required),.cm-purpose:not(.cm-toggle-all) > div > input:not(.half-checked,.required,.only-required)", true);
1492
+ return this.click(".cm-btn-accept,.cm-button");
1546
1493
  }
1547
1494
  async optIn() {
1548
- if (click(".klaro .cm-btn-accept-all")) {
1495
+ if (this.click(".klaro .cm-btn-accept-all")) {
1549
1496
  return true;
1550
1497
  }
1551
1498
  if (this.settingsOpen) {
1552
- click(".cm-purpose:not(.cm-toggle-all) > input.half-checked", true);
1553
- return click(".cm-btn-accept");
1499
+ this.click(".cm-purpose:not(.cm-toggle-all) > input.half-checked", true);
1500
+ return this.click(".cm-btn-accept");
1554
1501
  }
1555
- return click(".klaro .cookie-notice .cm-btn-success");
1502
+ return this.click(".klaro .cookie-notice .cm-btn-success");
1556
1503
  }
1557
1504
  async test() {
1558
1505
  return await this.mainWorldEval("EVAL_KLARO_1");
@@ -1578,21 +1525,21 @@
1578
1525
  return false;
1579
1526
  }
1580
1527
  async detectCmp() {
1581
- return elementExists(".unic .unic-box,.unic .unic-bar");
1528
+ return this.elementExists(".unic .unic-box,.unic .unic-bar");
1582
1529
  }
1583
1530
  async detectPopup() {
1584
- return elementVisible(".unic .unic-box,.unic .unic-bar", "any");
1531
+ return this.elementVisible(".unic .unic-box,.unic .unic-bar", "any");
1585
1532
  }
1586
1533
  async optOut() {
1587
- await waitForElement(".unic button", 1e3);
1534
+ await this.waitForElement(".unic button", 1e3);
1588
1535
  document.querySelectorAll(".unic button").forEach((button) => {
1589
1536
  const text = button.textContent;
1590
1537
  if (text.includes("Manage Options") || text.includes("Optionen verwalten")) {
1591
1538
  button.click();
1592
1539
  }
1593
1540
  });
1594
- if (await waitForElement(".unic input[type=checkbox]", 1e3)) {
1595
- await waitForElement(".unic button", 1e3);
1541
+ if (await this.waitForElement(".unic input[type=checkbox]", 1e3)) {
1542
+ await this.waitForElement(".unic button", 1e3);
1596
1543
  document.querySelectorAll(".unic input[type=checkbox]").forEach((c) => {
1597
1544
  if (c.checked) {
1598
1545
  c.click();
@@ -1603,7 +1550,7 @@
1603
1550
  for (const pattern of ["Confirm Choices", "Save Choices", "Auswahl speichern"]) {
1604
1551
  if (text.includes(pattern)) {
1605
1552
  b.click();
1606
- await wait(500);
1553
+ await this.wait(500);
1607
1554
  return true;
1608
1555
  }
1609
1556
  }
@@ -1612,11 +1559,11 @@
1612
1559
  return false;
1613
1560
  }
1614
1561
  async optIn() {
1615
- return waitForThenClick2(".unic #unic-agree");
1562
+ return this.waitForThenClick(".unic #unic-agree");
1616
1563
  }
1617
1564
  async test() {
1618
- await wait(1e3);
1619
- const res = elementExists(".unic .unic-box,.unic .unic-bar");
1565
+ await this.wait(1e3);
1566
+ const res = this.elementExists(".unic .unic-box,.unic .unic-bar");
1620
1567
  return !res;
1621
1568
  }
1622
1569
  };
@@ -1638,20 +1585,20 @@
1638
1585
  return false;
1639
1586
  }
1640
1587
  async detectCmp() {
1641
- return elementExists(".cmp-root .cmp-receptacle");
1588
+ return this.elementExists(".cmp-root .cmp-receptacle");
1642
1589
  }
1643
1590
  async detectPopup() {
1644
- return elementVisible(".cmp-root .cmp-receptacle", "any");
1591
+ return this.elementVisible(".cmp-root .cmp-receptacle", "any");
1645
1592
  }
1646
1593
  async optOut() {
1647
- if (!await waitForThenClick2(".cmp-main-button:not(.cmp-main-button--primary)")) {
1594
+ if (!await this.waitForThenClick(".cmp-main-button:not(.cmp-main-button--primary)")) {
1648
1595
  return false;
1649
1596
  }
1650
- if (!await waitForElement(".cmp-view-tab-tabs")) {
1597
+ if (!await this.waitForElement(".cmp-view-tab-tabs")) {
1651
1598
  return false;
1652
1599
  }
1653
- await waitForThenClick2(".cmp-view-tab-tabs > :first-child");
1654
- await waitForThenClick2(".cmp-view-tab-tabs > .cmp-view-tab--active:first-child");
1600
+ await this.waitForThenClick(".cmp-view-tab-tabs > :first-child");
1601
+ await this.waitForThenClick(".cmp-view-tab-tabs > .cmp-view-tab--active:first-child");
1655
1602
  for (const item of Array.from(document.querySelectorAll(".cmp-accordion-item"))) {
1656
1603
  item.querySelector(".cmp-accordion-item-title").click();
1657
1604
  await waitFor(() => !!item.querySelector(".cmp-accordion-item-content.cmp-active"), 10, 50);
@@ -1659,11 +1606,11 @@
1659
1606
  content.querySelectorAll(".cmp-toggle-actions .cmp-toggle-deny:not(.cmp-toggle-deny--active)").forEach((e) => e.click());
1660
1607
  content.querySelectorAll(".cmp-toggle-actions .cmp-toggle-checkbox:not(.cmp-toggle-checkbox--active)").forEach((e) => e.click());
1661
1608
  }
1662
- await click(".cmp-main-button:not(.cmp-main-button--primary)");
1609
+ await this.click(".cmp-main-button:not(.cmp-main-button--primary)");
1663
1610
  return true;
1664
1611
  }
1665
1612
  async optIn() {
1666
- return waitForThenClick2(".cmp-main-button.cmp-main-button--primary");
1613
+ return this.waitForThenClick(".cmp-main-button.cmp-main-button--primary");
1667
1614
  }
1668
1615
  async test() {
1669
1616
  return document.cookie.includes("cmp-data=0");
@@ -1696,31 +1643,33 @@
1696
1643
  return container.shadowRoot;
1697
1644
  }
1698
1645
  async detectCmp() {
1699
- return elementExists("tiktok-cookie-banner");
1646
+ return this.elementExists("tiktok-cookie-banner");
1700
1647
  }
1701
1648
  async detectPopup() {
1702
1649
  const banner = this.getShadowRoot().querySelector(".tiktok-cookie-banner");
1703
1650
  return isElementVisible(banner);
1704
1651
  }
1705
1652
  async optOut() {
1653
+ const logsConfig = this.autoconsent.config.logs;
1706
1654
  const declineButton = this.getShadowRoot().querySelector(".button-wrapper button:first-child");
1707
1655
  if (declineButton) {
1708
- enableLogs && console.log("[clicking]", declineButton);
1656
+ logsConfig.rulesteps && console.log("[clicking]", declineButton);
1709
1657
  declineButton.click();
1710
1658
  return true;
1711
1659
  } else {
1712
- enableLogs && console.log("no decline button found");
1660
+ logsConfig.errors && console.log("no decline button found");
1713
1661
  return false;
1714
1662
  }
1715
1663
  }
1716
1664
  async optIn() {
1665
+ const logsConfig = this.autoconsent.config.logs;
1717
1666
  const acceptButton = this.getShadowRoot().querySelector(".button-wrapper button:last-child");
1718
1667
  if (acceptButton) {
1719
- enableLogs && console.log("[clicking]", acceptButton);
1668
+ logsConfig.rulesteps && console.log("[clicking]", acceptButton);
1720
1669
  acceptButton.click();
1721
1670
  return true;
1722
1671
  } else {
1723
- enableLogs && console.log("no accept button found");
1672
+ logsConfig.errors && console.log("no accept button found");
1724
1673
  return false;
1725
1674
  }
1726
1675
  }
@@ -1756,21 +1705,21 @@
1756
1705
  return false;
1757
1706
  }
1758
1707
  async detectCmp() {
1759
- return elementExists("div[data-testid=main-cookies-banner-container]");
1708
+ return this.elementExists("div[data-testid=main-cookies-banner-container]");
1760
1709
  }
1761
1710
  async detectPopup() {
1762
- return elementVisible("div[data-testid=main-cookies-banner-container", "any");
1711
+ return this.elementVisible("div[data-testid=main-cookies-banner-container", "any");
1763
1712
  }
1764
1713
  async optOut() {
1765
- await waitForThenClick2("div[data-testid=main-cookies-banner-container] button._snbhip0");
1714
+ await this.waitForThenClick("div[data-testid=main-cookies-banner-container] button._snbhip0");
1766
1715
  let check;
1767
1716
  while (check = document.querySelector("[data-testid=modal-container] button[aria-checked=true]:not([disabled])")) {
1768
1717
  check.click();
1769
1718
  }
1770
- return waitForThenClick2("button[data-testid=save-btn]");
1719
+ return this.waitForThenClick("button[data-testid=save-btn]");
1771
1720
  }
1772
1721
  async optIn() {
1773
- return waitForThenClick2("div[data-testid=main-cookies-banner-container] button._148dgdpk");
1722
+ return this.waitForThenClick("div[data-testid=main-cookies-banner-container] button._148dgdpk");
1774
1723
  }
1775
1724
  async test() {
1776
1725
  return await waitFor(
@@ -1797,6 +1746,134 @@
1797
1746
  Airbnb
1798
1747
  ];
1799
1748
 
1749
+ // lib/dom-actions.ts
1750
+ var DomActions = class {
1751
+ constructor(autoconsentInstance) {
1752
+ this.autoconsentInstance = autoconsentInstance;
1753
+ }
1754
+ click(selector, all = false) {
1755
+ const elem = this.elementSelector(selector);
1756
+ this.autoconsentInstance.config.logs.rulesteps && console.log("[click]", selector, all, elem);
1757
+ if (elem.length > 0) {
1758
+ if (all) {
1759
+ elem.forEach((e) => e.click());
1760
+ } else {
1761
+ elem[0].click();
1762
+ }
1763
+ }
1764
+ return elem.length > 0;
1765
+ }
1766
+ elementExists(selector) {
1767
+ const exists = this.elementSelector(selector).length > 0;
1768
+ return exists;
1769
+ }
1770
+ elementVisible(selector, check) {
1771
+ const elem = this.elementSelector(selector);
1772
+ const results = new Array(elem.length);
1773
+ elem.forEach((e, i) => {
1774
+ results[i] = isElementVisible(e);
1775
+ });
1776
+ if (check === "none") {
1777
+ return results.every((r) => !r);
1778
+ } else if (results.length === 0) {
1779
+ return false;
1780
+ } else if (check === "any") {
1781
+ return results.some((r) => r);
1782
+ }
1783
+ return results.every((r) => r);
1784
+ }
1785
+ waitForElement(selector, timeout = 1e4) {
1786
+ const interval = 200;
1787
+ const times = Math.ceil(timeout / interval);
1788
+ this.autoconsentInstance.config.logs.rulesteps && console.log("[waitForElement]", selector);
1789
+ return waitFor(
1790
+ () => this.elementSelector(selector).length > 0,
1791
+ times,
1792
+ interval
1793
+ );
1794
+ }
1795
+ waitForVisible(selector, timeout = 1e4, check = "any") {
1796
+ const interval = 200;
1797
+ const times = Math.ceil(timeout / interval);
1798
+ return waitFor(
1799
+ () => this.elementVisible(selector, check),
1800
+ times,
1801
+ interval
1802
+ );
1803
+ }
1804
+ async waitForThenClick(selector, timeout = 1e4, all = false) {
1805
+ await this.waitForElement(selector, timeout);
1806
+ return this.click(selector, all);
1807
+ }
1808
+ wait(ms) {
1809
+ return new Promise((resolve) => {
1810
+ setTimeout(() => {
1811
+ resolve(true);
1812
+ }, ms);
1813
+ });
1814
+ }
1815
+ hide(selector, method) {
1816
+ const styleEl = getStyleElement();
1817
+ return hideElements(styleEl, selector, method);
1818
+ }
1819
+ prehide(selector) {
1820
+ const styleEl = getStyleElement("autoconsent-prehide");
1821
+ this.autoconsentInstance.config.logs.lifecycle && console.log("[prehide]", styleEl, location.href);
1822
+ return hideElements(styleEl, selector, "opacity");
1823
+ }
1824
+ undoPrehide() {
1825
+ const existingElement = getStyleElement("autoconsent-prehide");
1826
+ this.autoconsentInstance.config.logs.lifecycle && console.log("[undoprehide]", existingElement, location.href);
1827
+ if (existingElement) {
1828
+ existingElement.remove();
1829
+ }
1830
+ return !!existingElement;
1831
+ }
1832
+ querySingleReplySelector(selector, parent = document) {
1833
+ if (selector.startsWith("aria/")) {
1834
+ return [];
1835
+ }
1836
+ if (selector.startsWith("xpath/")) {
1837
+ const xpath = selector.slice(6);
1838
+ const result = document.evaluate(xpath, parent, null, XPathResult.ANY_TYPE, null);
1839
+ let node = null;
1840
+ const elements = [];
1841
+ while (node = result.iterateNext()) {
1842
+ elements.push(node);
1843
+ }
1844
+ return elements;
1845
+ }
1846
+ if (selector.startsWith("text/")) {
1847
+ return [];
1848
+ }
1849
+ if (selector.startsWith("pierce/")) {
1850
+ return [];
1851
+ }
1852
+ if (parent.shadowRoot) {
1853
+ return Array.from(parent.shadowRoot.querySelectorAll(selector));
1854
+ }
1855
+ return Array.from(parent.querySelectorAll(selector));
1856
+ }
1857
+ querySelectorChain(selectors) {
1858
+ let parent = document;
1859
+ let matches2;
1860
+ for (const selector of selectors) {
1861
+ matches2 = this.querySingleReplySelector(selector, parent);
1862
+ if (matches2.length === 0) {
1863
+ return [];
1864
+ }
1865
+ parent = matches2[0];
1866
+ }
1867
+ return matches2;
1868
+ }
1869
+ elementSelector(selector) {
1870
+ if (typeof selector === "string") {
1871
+ return this.querySingleReplySelector(selector);
1872
+ }
1873
+ return this.querySelectorChain(selector);
1874
+ }
1875
+ };
1876
+
1800
1877
  // lib/web.ts
1801
1878
  function filterCMPs(rules, config) {
1802
1879
  return rules.filter((cmp) => {
@@ -1819,7 +1896,6 @@
1819
1896
  evalState.sendContentMessage = sendContentMessage;
1820
1897
  this.sendContentMessage = sendContentMessage;
1821
1898
  this.rules = [];
1822
- enableLogs && console.log("autoconsent init", window.location.href);
1823
1899
  this.updateState({ lifecycle: "loading" });
1824
1900
  this.addDynamicRules();
1825
1901
  if (config) {
@@ -1835,17 +1911,20 @@
1835
1911
  sendContentMessage(initMsg);
1836
1912
  this.updateState({ lifecycle: "waitingForInitResponse" });
1837
1913
  }
1914
+ this.domActions = new DomActions(this);
1838
1915
  }
1839
1916
  initialize(config, declarativeRules) {
1840
- this.config = config;
1841
- if (!config.enabled) {
1842
- enableLogs && console.log("autoconsent is disabled");
1917
+ const normalizedConfig = normalizeConfig(config);
1918
+ normalizedConfig.logs.lifecycle && console.log("autoconsent init", window.location.href);
1919
+ this.config = normalizedConfig;
1920
+ if (!normalizedConfig.enabled) {
1921
+ normalizedConfig.logs.lifecycle && console.log("autoconsent is disabled");
1843
1922
  return;
1844
1923
  }
1845
1924
  if (declarativeRules) {
1846
1925
  this.parseDeclarativeRules(declarativeRules);
1847
1926
  }
1848
- this.rules = filterCMPs(this.rules, config);
1927
+ this.rules = filterCMPs(this.rules, normalizedConfig);
1849
1928
  if (config.enablePrehide) {
1850
1929
  if (document.documentElement) {
1851
1930
  this.prehideElements();
@@ -1896,12 +1975,13 @@
1896
1975
  }
1897
1976
  }
1898
1977
  async _start() {
1899
- enableLogs && console.log(`Detecting CMPs on ${window.location.href}`);
1978
+ const logsConfig = this.config.logs;
1979
+ logsConfig.lifecycle && console.log(`Detecting CMPs on ${window.location.href}`);
1900
1980
  this.updateState({ lifecycle: "started" });
1901
1981
  const foundCmps = await this.findCmp(this.config.detectRetries);
1902
1982
  this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
1903
1983
  if (foundCmps.length === 0) {
1904
- enableLogs && console.log("no CMP found", location.href);
1984
+ logsConfig.lifecycle && console.log("no CMP found", location.href);
1905
1985
  if (this.config.enablePrehide) {
1906
1986
  this.undoPrehide();
1907
1987
  }
@@ -1914,7 +1994,7 @@
1914
1994
  foundPopups = await this.detectPopups(foundCmps.filter((r) => r.isCosmetic));
1915
1995
  }
1916
1996
  if (foundPopups.length === 0) {
1917
- enableLogs && console.log("no popup found");
1997
+ logsConfig.lifecycle && console.log("no popup found");
1918
1998
  if (this.config.enablePrehide) {
1919
1999
  this.undoPrehide();
1920
2000
  }
@@ -1929,7 +2009,7 @@
1929
2009
  msg: `Found multiple CMPs, check the detection rules.`,
1930
2010
  cmps: foundPopups.map((cmp) => cmp.name)
1931
2011
  };
1932
- enableLogs && console.warn(errorDetails.msg, errorDetails.cmps);
2012
+ logsConfig.errors && console.warn(errorDetails.msg, errorDetails.cmps);
1933
2013
  this.sendContentMessage({
1934
2014
  type: "autoconsentError",
1935
2015
  details: errorDetails
@@ -1941,11 +2021,12 @@
1941
2021
  } else if (this.config.autoAction === "optIn") {
1942
2022
  return await this.doOptIn();
1943
2023
  } else {
1944
- enableLogs && console.log("waiting for opt-out signal...", location.href);
2024
+ logsConfig.lifecycle && console.log("waiting for opt-out signal...", location.href);
1945
2025
  return true;
1946
2026
  }
1947
2027
  }
1948
2028
  async findCmp(retries) {
2029
+ const logsConfig = this.config.logs;
1949
2030
  this.updateState({ findCmpAttempts: this.state.findCmpAttempts + 1 });
1950
2031
  const foundCMPs = [];
1951
2032
  for (const cmp of this.rules) {
@@ -1955,7 +2036,7 @@
1955
2036
  }
1956
2037
  const result = await cmp.detectCmp();
1957
2038
  if (result) {
1958
- enableLogs && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
2039
+ logsConfig.lifecycle && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
1959
2040
  this.sendContentMessage({
1960
2041
  type: "cmpDetected",
1961
2042
  url: location.href,
@@ -1964,16 +2045,17 @@
1964
2045
  foundCMPs.push(cmp);
1965
2046
  }
1966
2047
  } catch (e) {
1967
- enableLogs && console.warn(`error detecting ${cmp.name}`, e);
2048
+ logsConfig.errors && console.warn(`error detecting ${cmp.name}`, e);
1968
2049
  }
1969
2050
  }
1970
2051
  if (foundCMPs.length === 0 && retries > 0) {
1971
- await wait(500);
2052
+ await this.domActions.wait(500);
1972
2053
  return this.findCmp(retries - 1);
1973
2054
  }
1974
2055
  return foundCMPs;
1975
2056
  }
1976
2057
  async detectPopups(cmps) {
2058
+ const logsConfig = this.config.logs;
1977
2059
  const result = [];
1978
2060
  const popupLookups = cmps.map((cmp) => this.waitForPopup(cmp).then((isOpen) => {
1979
2061
  if (isOpen) {
@@ -1986,22 +2068,23 @@
1986
2068
  result.push(cmp);
1987
2069
  }
1988
2070
  }).catch((e) => {
1989
- enableLogs && console.warn(`error waiting for a popup for ${cmp.name}`, e);
2071
+ logsConfig.errors && console.warn(`error waiting for a popup for ${cmp.name}`, e);
1990
2072
  return null;
1991
2073
  }));
1992
2074
  await Promise.all(popupLookups);
1993
2075
  return result;
1994
2076
  }
1995
2077
  async doOptOut() {
2078
+ const logsConfig = this.config.logs;
1996
2079
  this.updateState({ lifecycle: "runningOptOut" });
1997
2080
  let optOutResult;
1998
2081
  if (!this.foundCmp) {
1999
- enableLogs && console.log("no CMP to opt out");
2082
+ logsConfig.errors && console.log("no CMP to opt out");
2000
2083
  optOutResult = false;
2001
2084
  } else {
2002
- enableLogs && console.log(`CMP ${this.foundCmp.name}: opt out on ${window.location.href}`);
2085
+ logsConfig.lifecycle && console.log(`CMP ${this.foundCmp.name}: opt out on ${window.location.href}`);
2003
2086
  optOutResult = await this.foundCmp.optOut();
2004
- enableLogs && console.log(`${this.foundCmp.name}: opt out result ${optOutResult}`);
2087
+ logsConfig.lifecycle && console.log(`${this.foundCmp.name}: opt out result ${optOutResult}`);
2005
2088
  }
2006
2089
  if (this.config.enablePrehide) {
2007
2090
  this.undoPrehide();
@@ -2027,15 +2110,16 @@
2027
2110
  return optOutResult;
2028
2111
  }
2029
2112
  async doOptIn() {
2113
+ const logsConfig = this.config.logs;
2030
2114
  this.updateState({ lifecycle: "runningOptIn" });
2031
2115
  let optInResult;
2032
2116
  if (!this.foundCmp) {
2033
- enableLogs && console.log("no CMP to opt in");
2117
+ logsConfig.errors && console.log("no CMP to opt in");
2034
2118
  optInResult = false;
2035
2119
  } else {
2036
- enableLogs && console.log(`CMP ${this.foundCmp.name}: opt in on ${window.location.href}`);
2120
+ logsConfig.lifecycle && console.log(`CMP ${this.foundCmp.name}: opt in on ${window.location.href}`);
2037
2121
  optInResult = await this.foundCmp.optIn();
2038
- enableLogs && console.log(`${this.foundCmp.name}: opt in result ${optInResult}`);
2122
+ logsConfig.lifecycle && console.log(`${this.foundCmp.name}: opt in result ${optInResult}`);
2039
2123
  }
2040
2124
  if (this.config.enablePrehide) {
2041
2125
  this.undoPrehide();
@@ -2062,12 +2146,13 @@
2062
2146
  return optInResult;
2063
2147
  }
2064
2148
  async doSelfTest() {
2149
+ const logsConfig = this.config.logs;
2065
2150
  let selfTestResult;
2066
2151
  if (!this.foundCmp) {
2067
- enableLogs && console.log("no CMP to self test");
2152
+ logsConfig.errors && console.log("no CMP to self test");
2068
2153
  selfTestResult = false;
2069
2154
  } else {
2070
- enableLogs && console.log(`CMP ${this.foundCmp.name}: self-test on ${window.location.href}`);
2155
+ logsConfig.lifecycle && console.log(`CMP ${this.foundCmp.name}: self-test on ${window.location.href}`);
2071
2156
  selfTestResult = await this.foundCmp.test();
2072
2157
  }
2073
2158
  this.sendContentMessage({
@@ -2080,19 +2165,21 @@
2080
2165
  return selfTestResult;
2081
2166
  }
2082
2167
  async waitForPopup(cmp, retries = 5, interval = 500) {
2083
- enableLogs && console.log("checking if popup is open...", cmp.name);
2168
+ const logsConfig = this.config.logs;
2169
+ logsConfig.lifecycle && console.log("checking if popup is open...", cmp.name);
2084
2170
  const isOpen = await cmp.detectPopup().catch((e) => {
2085
- enableLogs && console.warn(`error detecting popup for ${cmp.name}`, e);
2171
+ logsConfig.errors && console.warn(`error detecting popup for ${cmp.name}`, e);
2086
2172
  return false;
2087
2173
  });
2088
2174
  if (!isOpen && retries > 0) {
2089
- await wait(interval);
2175
+ await this.domActions.wait(interval);
2090
2176
  return this.waitForPopup(cmp, retries - 1, interval);
2091
2177
  }
2092
- enableLogs && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
2178
+ logsConfig.lifecycle && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
2093
2179
  return isOpen;
2094
2180
  }
2095
2181
  prehideElements() {
2182
+ const logsConfig = this.config.logs;
2096
2183
  const globalHidden = [
2097
2184
  "#didomi-popup,.didomi-popup-container,.didomi-popup-notice,.didomi-consent-popup-preferences,#didomi-notice,.didomi-popup-backdrop,.didomi-screen-medium"
2098
2185
  ];
@@ -2105,15 +2192,15 @@
2105
2192
  this.updateState({ prehideOn: true });
2106
2193
  setTimeout(() => {
2107
2194
  if (this.config.enablePrehide && this.state.prehideOn && !["runningOptOut", "runningOptIn"].includes(this.state.lifecycle)) {
2108
- enableLogs && console.log("Process is taking too long, unhiding elements");
2195
+ logsConfig.lifecycle && console.log("Process is taking too long, unhiding elements");
2109
2196
  this.undoPrehide();
2110
2197
  }
2111
2198
  }, this.config.prehideTimeout || 2e3);
2112
- return prehide(selectors.join(","));
2199
+ return this.domActions.prehide(selectors.join(","));
2113
2200
  }
2114
2201
  undoPrehide() {
2115
2202
  this.updateState({ prehideOn: false });
2116
- return undoPrehide();
2203
+ return this.domActions.undoPrehide();
2117
2204
  }
2118
2205
  updateState(change) {
2119
2206
  Object.assign(this.state, change);
@@ -2126,7 +2213,8 @@
2126
2213
  });
2127
2214
  }
2128
2215
  async receiveMessageCallback(message) {
2129
- if (enableLogs && !["evalResp", "report"].includes(message.type)) {
2216
+ const logsConfig = this.config?.logs;
2217
+ if (logsConfig?.messages) {
2130
2218
  console.log("received from background", message, window.location.href);
2131
2219
  }
2132
2220
  switch (message.type) {