@duckduckgo/autoconsent 8.1.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 (40) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/build.sh +1 -0
  3. package/dist/addon-firefox/background.bundle.js +60 -43
  4. package/dist/addon-firefox/content.bundle.js +484 -382
  5. package/dist/addon-firefox/manifest.json +1 -1
  6. package/dist/addon-mv3/background.bundle.js +60 -43
  7. package/dist/addon-mv3/content.bundle.js +484 -382
  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 +484 -382
  12. package/dist/autoconsent.esm.js +484 -382
  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/eval-snippets.ts +17 -2
  30. package/lib/types.ts +24 -1
  31. package/lib/utils.ts +32 -1
  32. package/lib/web.ts +46 -34
  33. package/package.json +4 -4
  34. package/playwright/runner.ts +11 -3
  35. package/playwright/unit.ts +15 -0
  36. package/readme.md +1 -1
  37. package/tests/{rule-executors.spec.ts → dom-actions.spec.ts} +20 -21
  38. package/tests/klaro.spec.ts +1 -0
  39. package/lib/config.ts +0 -2
  40. 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") {
@@ -635,7 +460,21 @@
635
460
  EVAL_COOKIEBOT_3: () => window.Cookiebot.withdraw() || true,
636
461
  EVAL_COOKIEBOT_4: () => window.Cookiebot.hide() || true,
637
462
  EVAL_COOKIEBOT_5: () => window.Cookiebot.declined === true,
638
- EVAL_KLARO_1: () => klaro.getManager().config.services.every((c) => c.required || !klaro.getManager().consents[c.name]),
463
+ EVAL_KLARO_1: () => {
464
+ const config = globalThis.klaroConfig || globalThis.klaro?.getManager && globalThis.klaro.getManager().config;
465
+ if (!config) {
466
+ return true;
467
+ }
468
+ const optionalServices = (config.services || config.apps).filter((s) => !s.required).map((s) => s.name);
469
+ if (klaro && klaro.getManager) {
470
+ const manager = klaro.getManager();
471
+ return optionalServices.every((name) => !manager.consents[name]);
472
+ } else if (klaroConfig && klaroConfig.storageMethod === "cookie") {
473
+ const cookieName = klaroConfig.cookieName || klaroConfig.storageName;
474
+ const consents = JSON.parse(decodeURIComponent(document.cookie.split(";").find((c) => c.trim().startsWith(cookieName)).split("=")[1]));
475
+ return Object.keys(consents).filter((k) => optionalServices.includes(k)).every((k) => consents[k] === false);
476
+ }
477
+ },
639
478
  EVAL_ONETRUST_1: () => window.OnetrustActiveGroups.split(",").filter((s) => s.length > 0).length <= 1,
640
479
  EVAL_TRUSTARC_TOP: () => window && window.truste && window.truste.eu.bindMap.prefCookie === "0",
641
480
  // declarative rules
@@ -739,7 +578,7 @@
739
578
  };
740
579
  function getFunctionBody(snippetFunc) {
741
580
  const snippetStr = snippetFunc.toString();
742
- return snippetStr.substring(snippetStr.indexOf("=>") + 2);
581
+ return `(${snippetStr})()`;
743
582
  }
744
583
 
745
584
  // lib/cmps/base.ts
@@ -768,20 +607,21 @@
768
607
  console.warn("Snippet not found", snippetId);
769
608
  return Promise.resolve(false);
770
609
  }
610
+ const logsConfig = this.autoconsent.config.logs;
771
611
  if (this.autoconsent.config.isMainWorld) {
772
- enableLogs && console.log("inline eval:", snippetId, snippet);
612
+ logsConfig.evals && console.log("inline eval:", snippetId, snippet);
773
613
  let result = false;
774
614
  try {
775
615
  result = !!snippet.call(globalThis);
776
616
  } catch (e) {
777
- enableLogs && console.error("error evaluating rule", snippetId, e);
617
+ logsConfig.evals && console.error("error evaluating rule", snippetId, e);
778
618
  }
779
619
  return Promise.resolve(result);
780
620
  }
781
621
  const snippetSrc = getFunctionBody(snippet);
782
- enableLogs && console.log("async eval:", snippetId, snippetSrc);
622
+ logsConfig.evals && console.log("async eval:", snippetId, snippetSrc);
783
623
  return requestEval(snippetSrc, snippetId).catch((e) => {
784
- enableLogs && console.error("error evaluating rule", snippetId, e);
624
+ logsConfig.evals && console.error("error evaluating rule", snippetId, e);
785
625
  return false;
786
626
  });
787
627
  }
@@ -820,93 +660,136 @@
820
660
  async test() {
821
661
  return Promise.resolve(true);
822
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
+ }
823
703
  };
824
704
  var AutoConsentCMP = class extends AutoConsentCMPBase {
825
- constructor(config, autoconsentInstance) {
705
+ constructor(rule, autoconsentInstance) {
826
706
  super(autoconsentInstance);
827
- this.config = config;
828
- this.name = config.name;
829
- this.runContext = config.runContext || defaultRunContext;
707
+ this.rule = rule;
708
+ this.name = rule.name;
709
+ this.runContext = rule.runContext || defaultRunContext;
830
710
  }
831
711
  get hasSelfTest() {
832
- return !!this.config.test;
712
+ return !!this.rule.test;
833
713
  }
834
714
  get isIntermediate() {
835
- return !!this.config.intermediate;
715
+ return !!this.rule.intermediate;
836
716
  }
837
717
  get isCosmetic() {
838
- return !!this.config.cosmetic;
718
+ return !!this.rule.cosmetic;
839
719
  }
840
720
  get prehideSelectors() {
841
- return this.config.prehideSelectors;
721
+ return this.rule.prehideSelectors;
842
722
  }
843
723
  async detectCmp() {
844
- if (this.config.detectCmp) {
845
- return this._runRulesParallel(this.config.detectCmp);
724
+ if (this.rule.detectCmp) {
725
+ return this._runRulesParallel(this.rule.detectCmp);
846
726
  }
847
727
  return false;
848
728
  }
849
729
  async detectPopup() {
850
- if (this.config.detectPopup) {
851
- return this._runRulesSequentially(this.config.detectPopup);
730
+ if (this.rule.detectPopup) {
731
+ return this._runRulesSequentially(this.rule.detectPopup);
852
732
  }
853
733
  return false;
854
734
  }
855
735
  async optOut() {
856
- if (this.config.optOut) {
857
- enableLogs && console.log("Initiated optOut()", this.config.optOut);
858
- 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);
859
740
  }
860
741
  return false;
861
742
  }
862
743
  async optIn() {
863
- if (this.config.optIn) {
864
- enableLogs && console.log("Initiated optIn()", this.config.optIn);
865
- 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);
866
748
  }
867
749
  return false;
868
750
  }
869
751
  async openCmp() {
870
- if (this.config.openCmp) {
871
- return this._runRulesSequentially(this.config.openCmp);
752
+ if (this.rule.openCmp) {
753
+ return this._runRulesSequentially(this.rule.openCmp);
872
754
  }
873
755
  return false;
874
756
  }
875
757
  async test() {
876
758
  if (this.hasSelfTest) {
877
- return this._runRulesSequentially(this.config.test);
759
+ return this._runRulesSequentially(this.rule.test);
878
760
  }
879
761
  return super.test();
880
762
  }
881
763
  async evaluateRuleStep(rule) {
882
764
  const results = [];
765
+ const logsConfig = this.autoconsent.config.logs;
883
766
  if (rule.exists) {
884
- results.push(elementExists(rule.exists));
767
+ results.push(this.elementExists(rule.exists));
885
768
  }
886
769
  if (rule.visible) {
887
- results.push(elementVisible(rule.visible, rule.check));
770
+ results.push(this.elementVisible(rule.visible, rule.check));
888
771
  }
889
772
  if (rule.eval) {
890
773
  const res = this.mainWorldEval(rule.eval);
891
774
  results.push(res);
892
775
  }
893
776
  if (rule.waitFor) {
894
- results.push(waitForElement(rule.waitFor, rule.timeout));
777
+ results.push(this.waitForElement(rule.waitFor, rule.timeout));
895
778
  }
896
779
  if (rule.waitForVisible) {
897
- results.push(waitForVisible(rule.waitForVisible, rule.timeout, rule.check));
780
+ results.push(this.waitForVisible(rule.waitForVisible, rule.timeout, rule.check));
898
781
  }
899
782
  if (rule.click) {
900
- results.push(click(rule.click, rule.all));
783
+ results.push(this.click(rule.click, rule.all));
901
784
  }
902
785
  if (rule.waitForThenClick) {
903
- results.push(waitForThenClick2(rule.waitForThenClick, rule.timeout, rule.all));
786
+ results.push(this.waitForThenClick(rule.waitForThenClick, rule.timeout, rule.all));
904
787
  }
905
788
  if (rule.wait) {
906
- results.push(wait(rule.wait));
789
+ results.push(this.wait(rule.wait));
907
790
  }
908
791
  if (rule.hide) {
909
- results.push(hide(rule.hide, rule.method));
792
+ results.push(this.hide(rule.hide, rule.method));
910
793
  }
911
794
  if (rule.if) {
912
795
  if (!rule.if.exists && !rule.if.visible) {
@@ -914,7 +797,7 @@
914
797
  return false;
915
798
  }
916
799
  const condition = await this.evaluateRuleStep(rule.if);
917
- enableLogs && console.log("Condition is", condition);
800
+ logsConfig.rulesteps && console.log("Condition is", condition);
918
801
  if (condition) {
919
802
  results.push(this._runRulesSequentially(rule.then));
920
803
  } else if (rule.else) {
@@ -930,7 +813,7 @@
930
813
  return false;
931
814
  }
932
815
  if (results.length === 0) {
933
- enableLogs && console.warn("Unrecognized rule", rule);
816
+ logsConfig.errors && console.warn("Unrecognized rule", rule);
934
817
  return false;
935
818
  }
936
819
  const all = await Promise.all(results);
@@ -942,10 +825,11 @@
942
825
  return detections.every((r) => !!r);
943
826
  }
944
827
  async _runRulesSequentially(rules) {
828
+ const logsConfig = this.autoconsent.config.logs;
945
829
  for (const rule of rules) {
946
- enableLogs && console.log("Running rule...", rule);
830
+ logsConfig.rulesteps && console.log("Running rule...", rule);
947
831
  const result = await this.evaluateRuleStep(rule);
948
- enableLogs && console.log("...rule result", result);
832
+ logsConfig.rulesteps && console.log("...rule result", result);
949
833
  if (!result && !rule.optional) {
950
834
  return false;
951
835
  }
@@ -1019,6 +903,82 @@
1019
903
  }
1020
904
  };
1021
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
+
1022
982
  // lib/cmps/trustarc-top.ts
1023
983
  var cookieSettingsButton = "#truste-show-consent";
1024
984
  var shortcutOptOut = "#truste-consent-required";
@@ -1054,17 +1014,17 @@
1054
1014
  return false;
1055
1015
  }
1056
1016
  async detectCmp() {
1057
- const result = elementExists(`${cookieSettingsButton},${bannerContainer}`);
1017
+ const result = this.elementExists(`${cookieSettingsButton},${bannerContainer}`);
1058
1018
  if (result) {
1059
1019
  this._shortcutButton = document.querySelector(shortcutOptOut);
1060
1020
  }
1061
1021
  return result;
1062
1022
  }
1063
1023
  async detectPopup() {
1064
- return elementVisible(`${popupContent},${bannerOverlay},${bannerContainer}`, "all");
1024
+ return this.elementVisible(`${popupContent},${bannerOverlay},${bannerContainer}`, "all");
1065
1025
  }
1066
1026
  openFrame() {
1067
- click(cookieSettingsButton);
1027
+ this.click(cookieSettingsButton);
1068
1028
  }
1069
1029
  async optOut() {
1070
1030
  if (this._shortcutButton) {
@@ -1075,7 +1035,7 @@
1075
1035
  getStyleElement(),
1076
1036
  `.truste_popframe, .truste_overlay, .truste_box_overlay, ${bannerContainer}`
1077
1037
  );
1078
- click(cookieSettingsButton);
1038
+ this.click(cookieSettingsButton);
1079
1039
  setTimeout(() => {
1080
1040
  getStyleElement().remove();
1081
1041
  }, 1e4);
@@ -1083,7 +1043,7 @@
1083
1043
  }
1084
1044
  async optIn() {
1085
1045
  this._optInDone = true;
1086
- return click(shortcutOptIn);
1046
+ return this.click(shortcutOptIn);
1087
1047
  }
1088
1048
  async openCmp() {
1089
1049
  return true;
@@ -1117,62 +1077,62 @@
1117
1077
  return true;
1118
1078
  }
1119
1079
  async detectPopup() {
1120
- return elementVisible("#defaultpreferencemanager", "any") && elementVisible(".mainContent", "any");
1080
+ return this.elementVisible("#defaultpreferencemanager", "any") && this.elementVisible(".mainContent", "any");
1121
1081
  }
1122
1082
  async navigateToSettings() {
1123
1083
  await waitFor(
1124
1084
  async () => {
1125
- 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");
1126
1086
  },
1127
1087
  10,
1128
1088
  500
1129
1089
  );
1130
- if (elementExists(".shp")) {
1131
- click(".shp");
1090
+ if (this.elementExists(".shp")) {
1091
+ this.click(".shp");
1132
1092
  }
1133
- await waitForElement(".prefPanel", 5e3);
1134
- if (elementVisible(".advance", "any")) {
1135
- click(".advance");
1093
+ await this.waitForElement(".prefPanel", 5e3);
1094
+ if (this.elementVisible(".advance", "any")) {
1095
+ this.click(".advance");
1136
1096
  }
1137
1097
  return await waitFor(
1138
- () => elementVisible(".switch span:first-child", "any"),
1098
+ () => this.elementVisible(".switch span:first-child", "any"),
1139
1099
  5,
1140
1100
  1e3
1141
1101
  );
1142
1102
  }
1143
1103
  async optOut() {
1144
1104
  await waitFor(() => document.readyState === "complete", 20, 100);
1145
- await waitForElement(".mainContent[aria-hidden=false]", 5e3);
1146
- if (click(".rejectAll")) {
1105
+ await this.waitForElement(".mainContent[aria-hidden=false]", 5e3);
1106
+ if (this.click(".rejectAll")) {
1147
1107
  return true;
1148
1108
  }
1149
- if (elementExists(".prefPanel")) {
1150
- await waitForElement('.prefPanel[style="visibility: visible;"]', 3e3);
1109
+ if (this.elementExists(".prefPanel")) {
1110
+ await this.waitForElement('.prefPanel[style="visibility: visible;"]', 3e3);
1151
1111
  }
1152
- if (click("#catDetails0")) {
1153
- click(".submit");
1154
- waitForThenClick("#gwt-debug-close_id", 5e3);
1112
+ if (this.click("#catDetails0")) {
1113
+ this.click(".submit");
1114
+ this.waitForThenClick("#gwt-debug-close_id", 5e3);
1155
1115
  return true;
1156
1116
  }
1157
- if (click(".required")) {
1158
- waitForThenClick("#gwt-debug-close_id", 5e3);
1117
+ if (this.click(".required")) {
1118
+ this.waitForThenClick("#gwt-debug-close_id", 5e3);
1159
1119
  return true;
1160
1120
  }
1161
1121
  await this.navigateToSettings();
1162
- click(".switch span:nth-child(1):not(.active)", true);
1163
- click(".submit");
1164
- 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);
1165
1125
  return true;
1166
1126
  }
1167
1127
  async optIn() {
1168
- if (click(".call")) {
1128
+ if (this.click(".call")) {
1169
1129
  return true;
1170
1130
  }
1171
1131
  await this.navigateToSettings();
1172
- click(".switch span:nth-child(2)", true);
1173
- click(".submit");
1174
- waitForElement("#gwt-debug-close_id", 3e5).then(() => {
1175
- 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");
1176
1136
  });
1177
1137
  return true;
1178
1138
  }
@@ -1201,23 +1161,23 @@
1201
1161
  return this.mainWorldEval("EVAL_COOKIEBOT_2");
1202
1162
  }
1203
1163
  async optOut() {
1204
- await wait(500);
1164
+ await this.wait(500);
1205
1165
  let res = await this.mainWorldEval("EVAL_COOKIEBOT_3");
1206
- await wait(500);
1166
+ await this.wait(500);
1207
1167
  res = res && await this.mainWorldEval("EVAL_COOKIEBOT_4");
1208
1168
  return res;
1209
1169
  }
1210
1170
  async optIn() {
1211
- if (elementExists("#dtcookie-container")) {
1212
- return click(".h-dtcookie-accept");
1171
+ if (this.elementExists("#dtcookie-container")) {
1172
+ return this.click(".h-dtcookie-accept");
1213
1173
  }
1214
- click(".CybotCookiebotDialogBodyLevelButton:not(:checked):enabled", true);
1215
- click("#CybotCookiebotDialogBodyLevelButtonAccept");
1216
- click("#CybotCookiebotDialogBodyButtonAccept");
1174
+ this.click(".CybotCookiebotDialogBodyLevelButton:not(:checked):enabled", true);
1175
+ this.click("#CybotCookiebotDialogBodyLevelButtonAccept");
1176
+ this.click("#CybotCookiebotDialogBodyButtonAccept");
1217
1177
  return true;
1218
1178
  }
1219
1179
  async test() {
1220
- await wait(500);
1180
+ await this.wait(500);
1221
1181
  return await this.mainWorldEval("EVAL_COOKIEBOT_5");
1222
1182
  }
1223
1183
  };
@@ -1261,17 +1221,17 @@
1261
1221
  return true;
1262
1222
  }
1263
1223
  if (this.ccpaPopup) {
1264
- return await waitForElement(".priv-save-btn", 2e3);
1224
+ return await this.waitForElement(".priv-save-btn", 2e3);
1265
1225
  }
1266
- 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);
1267
- 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");
1268
1228
  }
1269
1229
  async optIn() {
1270
- await waitForElement(".sp_choice_type_11,.sp_choice_type_ACCEPT_ALL", 2e3);
1271
- 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")) {
1272
1232
  return true;
1273
1233
  }
1274
- if (click(".sp_choice_type_ACCEPT_ALL")) {
1234
+ if (this.click(".sp_choice_type_ACCEPT_ALL")) {
1275
1235
  return true;
1276
1236
  }
1277
1237
  return false;
@@ -1280,6 +1240,7 @@
1280
1240
  return location.pathname === "/privacy-manager/index.html" || location.pathname === "/ccpa_pm/index.html";
1281
1241
  }
1282
1242
  async optOut() {
1243
+ const logsConfig = this.autoconsent.config.logs;
1283
1244
  if (this.ccpaPopup) {
1284
1245
  const toggles = document.querySelectorAll(".priv-purpose-container .sp-switch-arrow-block a.neutral.on .right");
1285
1246
  for (const t of toggles) {
@@ -1289,47 +1250,47 @@
1289
1250
  for (const t of switches) {
1290
1251
  t.click();
1291
1252
  }
1292
- return click(".priv-save-btn");
1253
+ return this.click(".priv-save-btn");
1293
1254
  }
1294
1255
  if (!this.isManagerOpen()) {
1295
- 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");
1296
1257
  if (!actionable) {
1297
1258
  return false;
1298
1259
  }
1299
- if (!elementExists(".sp_choice_type_12")) {
1300
- return click(".sp_choice_type_13");
1260
+ if (!this.elementExists(".sp_choice_type_12")) {
1261
+ return this.click(".sp_choice_type_13");
1301
1262
  }
1302
- click(".sp_choice_type_12");
1263
+ this.click(".sp_choice_type_12");
1303
1264
  await waitFor(
1304
1265
  () => this.isManagerOpen(),
1305
1266
  200,
1306
1267
  100
1307
1268
  );
1308
1269
  }
1309
- await waitForElement(".type-modal", 2e4);
1310
- 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);
1311
1272
  try {
1312
1273
  const rejectSelector1 = ".sp_choice_type_REJECT_ALL";
1313
1274
  const rejectSelector2 = ".reject-toggle";
1314
1275
  const path = await Promise.race([
1315
- waitForElement(rejectSelector1, 2e3).then((success) => success ? 0 : -1),
1316
- waitForElement(rejectSelector2, 2e3).then((success) => success ? 1 : -1),
1317
- 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)
1318
1279
  ]);
1319
1280
  if (path === 0) {
1320
- await wait(1e3);
1321
- return click(rejectSelector1);
1281
+ await this.wait(1e3);
1282
+ return this.click(rejectSelector1);
1322
1283
  } else if (path === 1) {
1323
- click(rejectSelector2);
1284
+ this.click(rejectSelector2);
1324
1285
  } else if (path === 2) {
1325
- await waitForElement(".pm-features", 1e4);
1326
- click(".checked > span", true);
1327
- click(".chevron");
1286
+ await this.waitForElement(".pm-features", 1e4);
1287
+ this.click(".checked > span", true);
1288
+ this.click(".chevron");
1328
1289
  }
1329
1290
  } catch (e) {
1330
- enableLogs && console.warn(e);
1291
+ logsConfig.errors && console.warn(e);
1331
1292
  }
1332
- return click(".sp_choice_type_SAVE_AND_EXIT");
1293
+ return this.click(".sp_choice_type_SAVE_AND_EXIT");
1333
1294
  }
1334
1295
  };
1335
1296
 
@@ -1353,42 +1314,42 @@
1353
1314
  async detectCmp() {
1354
1315
  this.apiAvailable = await this.mainWorldEval("EVAL_CONSENTMANAGER_1");
1355
1316
  if (!this.apiAvailable) {
1356
- return elementExists("#cmpbox");
1317
+ return this.elementExists("#cmpbox");
1357
1318
  } else {
1358
1319
  return true;
1359
1320
  }
1360
1321
  }
1361
1322
  async detectPopup() {
1362
1323
  if (this.apiAvailable) {
1363
- await wait(500);
1324
+ await this.wait(500);
1364
1325
  return await this.mainWorldEval("EVAL_CONSENTMANAGER_2");
1365
1326
  }
1366
- return elementVisible("#cmpbox .cmpmore", "any");
1327
+ return this.elementVisible("#cmpbox .cmpmore", "any");
1367
1328
  }
1368
1329
  async optOut() {
1369
- await wait(500);
1330
+ await this.wait(500);
1370
1331
  if (this.apiAvailable) {
1371
1332
  return await this.mainWorldEval("EVAL_CONSENTMANAGER_3");
1372
1333
  }
1373
- if (click(".cmpboxbtnno")) {
1334
+ if (this.click(".cmpboxbtnno")) {
1374
1335
  return true;
1375
1336
  }
1376
- if (elementExists(".cmpwelcomeprpsbtn")) {
1377
- click(".cmpwelcomeprpsbtn > a[aria-checked=true]", true);
1378
- click(".cmpboxbtnsave");
1337
+ if (this.elementExists(".cmpwelcomeprpsbtn")) {
1338
+ this.click(".cmpwelcomeprpsbtn > a[aria-checked=true]", true);
1339
+ this.click(".cmpboxbtnsave");
1379
1340
  return true;
1380
1341
  }
1381
- click(".cmpboxbtncustom");
1382
- await waitForElement(".cmptblbox", 2e3);
1383
- click(".cmptdchoice > a[aria-checked=true]", true);
1384
- 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");
1385
1346
  return true;
1386
1347
  }
1387
1348
  async optIn() {
1388
1349
  if (this.apiAvailable) {
1389
1350
  return await this.mainWorldEval("EVAL_CONSENTMANAGER_4");
1390
1351
  }
1391
- return click(".cmpboxbtnyes");
1352
+ return this.click(".cmpboxbtnyes");
1392
1353
  }
1393
1354
  async test() {
1394
1355
  if (this.apiAvailable) {
@@ -1413,23 +1374,23 @@
1413
1374
  return false;
1414
1375
  }
1415
1376
  async detectCmp() {
1416
- return elementExists("#_evidon_banner");
1377
+ return this.elementExists("#_evidon_banner");
1417
1378
  }
1418
1379
  async detectPopup() {
1419
- return elementVisible("#_evidon_banner", "any");
1380
+ return this.elementVisible("#_evidon_banner", "any");
1420
1381
  }
1421
1382
  async optOut() {
1422
- if (click("#_evidon-decline-button")) {
1383
+ if (this.click("#_evidon-decline-button")) {
1423
1384
  return true;
1424
1385
  }
1425
1386
  hideElements(getStyleElement(), "#evidon-prefdiag-overlay,#evidon-prefdiag-background");
1426
- click("#_evidon-option-button");
1427
- await waitForElement("#evidon-prefdiag-overlay", 5e3);
1428
- click("#evidon-prefdiag-decline");
1387
+ this.click("#_evidon-option-button");
1388
+ await this.waitForElement("#evidon-prefdiag-overlay", 5e3);
1389
+ this.click("#evidon-prefdiag-decline");
1429
1390
  return true;
1430
1391
  }
1431
1392
  async optIn() {
1432
- return click("#_evidon-accept-button");
1393
+ return this.click("#_evidon-accept-button");
1433
1394
  }
1434
1395
  };
1435
1396
 
@@ -1453,31 +1414,31 @@
1453
1414
  return false;
1454
1415
  }
1455
1416
  async detectCmp() {
1456
- return elementExists("#onetrust-banner-sdk");
1417
+ return this.elementExists("#onetrust-banner-sdk");
1457
1418
  }
1458
1419
  async detectPopup() {
1459
- return elementVisible("#onetrust-banner-sdk", "all");
1420
+ return this.elementVisible("#onetrust-banner-sdk", "all");
1460
1421
  }
1461
1422
  async optOut() {
1462
- if (elementVisible("#onetrust-reject-all-handler,.js-reject-cookies", "any")) {
1463
- 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");
1464
1425
  }
1465
- if (elementExists("#onetrust-pc-btn-handler")) {
1466
- click("#onetrust-pc-btn-handler");
1426
+ if (this.elementExists("#onetrust-pc-btn-handler")) {
1427
+ this.click("#onetrust-pc-btn-handler");
1467
1428
  } else {
1468
- click(".ot-sdk-show-settings,button.js-cookie-settings");
1469
- }
1470
- await waitForElement("#onetrust-consent-sdk", 2e3);
1471
- await wait(1e3);
1472
- click("#onetrust-consent-sdk input.category-switch-handler:checked,.js-editor-toggle-state:checked", true);
1473
- await wait(1e3);
1474
- await waitForElement(".save-preference-btn-handler,.js-consent-save", 2e3);
1475
- click(".save-preference-btn-handler,.js-consent-save");
1476
- 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");
1477
1438
  return true;
1478
1439
  }
1479
1440
  async optIn() {
1480
- return click("#onetrust-accept-btn-handler,.js-accept-cookies");
1441
+ return this.click("#onetrust-accept-btn-handler,.js-accept-cookies");
1481
1442
  }
1482
1443
  async test() {
1483
1444
  return await waitFor(
@@ -1506,39 +1467,39 @@
1506
1467
  return false;
1507
1468
  }
1508
1469
  async detectCmp() {
1509
- if (elementExists(".klaro > .cookie-modal")) {
1470
+ if (this.elementExists(".klaro > .cookie-modal")) {
1510
1471
  this.settingsOpen = true;
1511
1472
  return true;
1512
1473
  }
1513
- return elementExists(".klaro > .cookie-notice");
1474
+ return this.elementExists(".klaro > .cookie-notice");
1514
1475
  }
1515
1476
  async detectPopup() {
1516
- return elementVisible(".klaro > .cookie-notice,.klaro > .cookie-modal", "any");
1477
+ return this.elementVisible(".klaro > .cookie-notice,.klaro > .cookie-modal", "any");
1517
1478
  }
1518
1479
  async optOut() {
1519
- if (click(".klaro .cn-decline")) {
1480
+ if (this.click(".klaro .cn-decline")) {
1520
1481
  return true;
1521
1482
  }
1522
1483
  if (!this.settingsOpen) {
1523
- click(".klaro .cn-learn-more");
1524
- 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);
1525
1486
  this.settingsOpen = true;
1526
1487
  }
1527
- if (click(".klaro .cn-decline")) {
1488
+ if (this.click(".klaro .cn-decline")) {
1528
1489
  return true;
1529
1490
  }
1530
- click(".cm-purpose:not(.cm-toggle-all) > input:not(.half-checked)", true);
1531
- return click(".cm-btn-accept");
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");
1532
1493
  }
1533
1494
  async optIn() {
1534
- if (click(".klaro .cm-btn-accept-all")) {
1495
+ if (this.click(".klaro .cm-btn-accept-all")) {
1535
1496
  return true;
1536
1497
  }
1537
1498
  if (this.settingsOpen) {
1538
- click(".cm-purpose:not(.cm-toggle-all) > input.half-checked", true);
1539
- 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");
1540
1501
  }
1541
- return click(".klaro .cookie-notice .cm-btn-success");
1502
+ return this.click(".klaro .cookie-notice .cm-btn-success");
1542
1503
  }
1543
1504
  async test() {
1544
1505
  return await this.mainWorldEval("EVAL_KLARO_1");
@@ -1564,21 +1525,21 @@
1564
1525
  return false;
1565
1526
  }
1566
1527
  async detectCmp() {
1567
- return elementExists(".unic .unic-box,.unic .unic-bar");
1528
+ return this.elementExists(".unic .unic-box,.unic .unic-bar");
1568
1529
  }
1569
1530
  async detectPopup() {
1570
- return elementVisible(".unic .unic-box,.unic .unic-bar", "any");
1531
+ return this.elementVisible(".unic .unic-box,.unic .unic-bar", "any");
1571
1532
  }
1572
1533
  async optOut() {
1573
- await waitForElement(".unic button", 1e3);
1534
+ await this.waitForElement(".unic button", 1e3);
1574
1535
  document.querySelectorAll(".unic button").forEach((button) => {
1575
1536
  const text = button.textContent;
1576
1537
  if (text.includes("Manage Options") || text.includes("Optionen verwalten")) {
1577
1538
  button.click();
1578
1539
  }
1579
1540
  });
1580
- if (await waitForElement(".unic input[type=checkbox]", 1e3)) {
1581
- await waitForElement(".unic button", 1e3);
1541
+ if (await this.waitForElement(".unic input[type=checkbox]", 1e3)) {
1542
+ await this.waitForElement(".unic button", 1e3);
1582
1543
  document.querySelectorAll(".unic input[type=checkbox]").forEach((c) => {
1583
1544
  if (c.checked) {
1584
1545
  c.click();
@@ -1589,7 +1550,7 @@
1589
1550
  for (const pattern of ["Confirm Choices", "Save Choices", "Auswahl speichern"]) {
1590
1551
  if (text.includes(pattern)) {
1591
1552
  b.click();
1592
- await wait(500);
1553
+ await this.wait(500);
1593
1554
  return true;
1594
1555
  }
1595
1556
  }
@@ -1598,11 +1559,11 @@
1598
1559
  return false;
1599
1560
  }
1600
1561
  async optIn() {
1601
- return waitForThenClick2(".unic #unic-agree");
1562
+ return this.waitForThenClick(".unic #unic-agree");
1602
1563
  }
1603
1564
  async test() {
1604
- await wait(1e3);
1605
- 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");
1606
1567
  return !res;
1607
1568
  }
1608
1569
  };
@@ -1624,20 +1585,20 @@
1624
1585
  return false;
1625
1586
  }
1626
1587
  async detectCmp() {
1627
- return elementExists(".cmp-root .cmp-receptacle");
1588
+ return this.elementExists(".cmp-root .cmp-receptacle");
1628
1589
  }
1629
1590
  async detectPopup() {
1630
- return elementVisible(".cmp-root .cmp-receptacle", "any");
1591
+ return this.elementVisible(".cmp-root .cmp-receptacle", "any");
1631
1592
  }
1632
1593
  async optOut() {
1633
- if (!await waitForThenClick2(".cmp-main-button:not(.cmp-main-button--primary)")) {
1594
+ if (!await this.waitForThenClick(".cmp-main-button:not(.cmp-main-button--primary)")) {
1634
1595
  return false;
1635
1596
  }
1636
- if (!await waitForElement(".cmp-view-tab-tabs")) {
1597
+ if (!await this.waitForElement(".cmp-view-tab-tabs")) {
1637
1598
  return false;
1638
1599
  }
1639
- await waitForThenClick2(".cmp-view-tab-tabs > :first-child");
1640
- 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");
1641
1602
  for (const item of Array.from(document.querySelectorAll(".cmp-accordion-item"))) {
1642
1603
  item.querySelector(".cmp-accordion-item-title").click();
1643
1604
  await waitFor(() => !!item.querySelector(".cmp-accordion-item-content.cmp-active"), 10, 50);
@@ -1645,11 +1606,11 @@
1645
1606
  content.querySelectorAll(".cmp-toggle-actions .cmp-toggle-deny:not(.cmp-toggle-deny--active)").forEach((e) => e.click());
1646
1607
  content.querySelectorAll(".cmp-toggle-actions .cmp-toggle-checkbox:not(.cmp-toggle-checkbox--active)").forEach((e) => e.click());
1647
1608
  }
1648
- await click(".cmp-main-button:not(.cmp-main-button--primary)");
1609
+ await this.click(".cmp-main-button:not(.cmp-main-button--primary)");
1649
1610
  return true;
1650
1611
  }
1651
1612
  async optIn() {
1652
- return waitForThenClick2(".cmp-main-button.cmp-main-button--primary");
1613
+ return this.waitForThenClick(".cmp-main-button.cmp-main-button--primary");
1653
1614
  }
1654
1615
  async test() {
1655
1616
  return document.cookie.includes("cmp-data=0");
@@ -1682,31 +1643,33 @@
1682
1643
  return container.shadowRoot;
1683
1644
  }
1684
1645
  async detectCmp() {
1685
- return elementExists("tiktok-cookie-banner");
1646
+ return this.elementExists("tiktok-cookie-banner");
1686
1647
  }
1687
1648
  async detectPopup() {
1688
1649
  const banner = this.getShadowRoot().querySelector(".tiktok-cookie-banner");
1689
1650
  return isElementVisible(banner);
1690
1651
  }
1691
1652
  async optOut() {
1653
+ const logsConfig = this.autoconsent.config.logs;
1692
1654
  const declineButton = this.getShadowRoot().querySelector(".button-wrapper button:first-child");
1693
1655
  if (declineButton) {
1694
- enableLogs && console.log("[clicking]", declineButton);
1656
+ logsConfig.rulesteps && console.log("[clicking]", declineButton);
1695
1657
  declineButton.click();
1696
1658
  return true;
1697
1659
  } else {
1698
- enableLogs && console.log("no decline button found");
1660
+ logsConfig.errors && console.log("no decline button found");
1699
1661
  return false;
1700
1662
  }
1701
1663
  }
1702
1664
  async optIn() {
1665
+ const logsConfig = this.autoconsent.config.logs;
1703
1666
  const acceptButton = this.getShadowRoot().querySelector(".button-wrapper button:last-child");
1704
1667
  if (acceptButton) {
1705
- enableLogs && console.log("[clicking]", acceptButton);
1668
+ logsConfig.rulesteps && console.log("[clicking]", acceptButton);
1706
1669
  acceptButton.click();
1707
1670
  return true;
1708
1671
  } else {
1709
- enableLogs && console.log("no accept button found");
1672
+ logsConfig.errors && console.log("no accept button found");
1710
1673
  return false;
1711
1674
  }
1712
1675
  }
@@ -1742,21 +1705,21 @@
1742
1705
  return false;
1743
1706
  }
1744
1707
  async detectCmp() {
1745
- return elementExists("div[data-testid=main-cookies-banner-container]");
1708
+ return this.elementExists("div[data-testid=main-cookies-banner-container]");
1746
1709
  }
1747
1710
  async detectPopup() {
1748
- return elementVisible("div[data-testid=main-cookies-banner-container", "any");
1711
+ return this.elementVisible("div[data-testid=main-cookies-banner-container", "any");
1749
1712
  }
1750
1713
  async optOut() {
1751
- await waitForThenClick2("div[data-testid=main-cookies-banner-container] button._snbhip0");
1714
+ await this.waitForThenClick("div[data-testid=main-cookies-banner-container] button._snbhip0");
1752
1715
  let check;
1753
1716
  while (check = document.querySelector("[data-testid=modal-container] button[aria-checked=true]:not([disabled])")) {
1754
1717
  check.click();
1755
1718
  }
1756
- return waitForThenClick2("button[data-testid=save-btn]");
1719
+ return this.waitForThenClick("button[data-testid=save-btn]");
1757
1720
  }
1758
1721
  async optIn() {
1759
- return waitForThenClick2("div[data-testid=main-cookies-banner-container] button._148dgdpk");
1722
+ return this.waitForThenClick("div[data-testid=main-cookies-banner-container] button._148dgdpk");
1760
1723
  }
1761
1724
  async test() {
1762
1725
  return await waitFor(
@@ -1783,6 +1746,134 @@
1783
1746
  Airbnb
1784
1747
  ];
1785
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
+
1786
1877
  // lib/web.ts
1787
1878
  function filterCMPs(rules, config) {
1788
1879
  return rules.filter((cmp) => {
@@ -1805,7 +1896,6 @@
1805
1896
  evalState.sendContentMessage = sendContentMessage;
1806
1897
  this.sendContentMessage = sendContentMessage;
1807
1898
  this.rules = [];
1808
- enableLogs && console.log("autoconsent init", window.location.href);
1809
1899
  this.updateState({ lifecycle: "loading" });
1810
1900
  this.addDynamicRules();
1811
1901
  if (config) {
@@ -1821,17 +1911,20 @@
1821
1911
  sendContentMessage(initMsg);
1822
1912
  this.updateState({ lifecycle: "waitingForInitResponse" });
1823
1913
  }
1914
+ this.domActions = new DomActions(this);
1824
1915
  }
1825
1916
  initialize(config, declarativeRules) {
1826
- this.config = config;
1827
- if (!config.enabled) {
1828
- 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");
1829
1922
  return;
1830
1923
  }
1831
1924
  if (declarativeRules) {
1832
1925
  this.parseDeclarativeRules(declarativeRules);
1833
1926
  }
1834
- this.rules = filterCMPs(this.rules, config);
1927
+ this.rules = filterCMPs(this.rules, normalizedConfig);
1835
1928
  if (config.enablePrehide) {
1836
1929
  if (document.documentElement) {
1837
1930
  this.prehideElements();
@@ -1882,12 +1975,13 @@
1882
1975
  }
1883
1976
  }
1884
1977
  async _start() {
1885
- 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}`);
1886
1980
  this.updateState({ lifecycle: "started" });
1887
1981
  const foundCmps = await this.findCmp(this.config.detectRetries);
1888
1982
  this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
1889
1983
  if (foundCmps.length === 0) {
1890
- enableLogs && console.log("no CMP found", location.href);
1984
+ logsConfig.lifecycle && console.log("no CMP found", location.href);
1891
1985
  if (this.config.enablePrehide) {
1892
1986
  this.undoPrehide();
1893
1987
  }
@@ -1900,7 +1994,7 @@
1900
1994
  foundPopups = await this.detectPopups(foundCmps.filter((r) => r.isCosmetic));
1901
1995
  }
1902
1996
  if (foundPopups.length === 0) {
1903
- enableLogs && console.log("no popup found");
1997
+ logsConfig.lifecycle && console.log("no popup found");
1904
1998
  if (this.config.enablePrehide) {
1905
1999
  this.undoPrehide();
1906
2000
  }
@@ -1915,7 +2009,7 @@
1915
2009
  msg: `Found multiple CMPs, check the detection rules.`,
1916
2010
  cmps: foundPopups.map((cmp) => cmp.name)
1917
2011
  };
1918
- enableLogs && console.warn(errorDetails.msg, errorDetails.cmps);
2012
+ logsConfig.errors && console.warn(errorDetails.msg, errorDetails.cmps);
1919
2013
  this.sendContentMessage({
1920
2014
  type: "autoconsentError",
1921
2015
  details: errorDetails
@@ -1927,11 +2021,12 @@
1927
2021
  } else if (this.config.autoAction === "optIn") {
1928
2022
  return await this.doOptIn();
1929
2023
  } else {
1930
- enableLogs && console.log("waiting for opt-out signal...", location.href);
2024
+ logsConfig.lifecycle && console.log("waiting for opt-out signal...", location.href);
1931
2025
  return true;
1932
2026
  }
1933
2027
  }
1934
2028
  async findCmp(retries) {
2029
+ const logsConfig = this.config.logs;
1935
2030
  this.updateState({ findCmpAttempts: this.state.findCmpAttempts + 1 });
1936
2031
  const foundCMPs = [];
1937
2032
  for (const cmp of this.rules) {
@@ -1941,7 +2036,7 @@
1941
2036
  }
1942
2037
  const result = await cmp.detectCmp();
1943
2038
  if (result) {
1944
- enableLogs && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
2039
+ logsConfig.lifecycle && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
1945
2040
  this.sendContentMessage({
1946
2041
  type: "cmpDetected",
1947
2042
  url: location.href,
@@ -1950,16 +2045,17 @@
1950
2045
  foundCMPs.push(cmp);
1951
2046
  }
1952
2047
  } catch (e) {
1953
- enableLogs && console.warn(`error detecting ${cmp.name}`, e);
2048
+ logsConfig.errors && console.warn(`error detecting ${cmp.name}`, e);
1954
2049
  }
1955
2050
  }
1956
2051
  if (foundCMPs.length === 0 && retries > 0) {
1957
- await wait(500);
2052
+ await this.domActions.wait(500);
1958
2053
  return this.findCmp(retries - 1);
1959
2054
  }
1960
2055
  return foundCMPs;
1961
2056
  }
1962
2057
  async detectPopups(cmps) {
2058
+ const logsConfig = this.config.logs;
1963
2059
  const result = [];
1964
2060
  const popupLookups = cmps.map((cmp) => this.waitForPopup(cmp).then((isOpen) => {
1965
2061
  if (isOpen) {
@@ -1972,22 +2068,23 @@
1972
2068
  result.push(cmp);
1973
2069
  }
1974
2070
  }).catch((e) => {
1975
- 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);
1976
2072
  return null;
1977
2073
  }));
1978
2074
  await Promise.all(popupLookups);
1979
2075
  return result;
1980
2076
  }
1981
2077
  async doOptOut() {
2078
+ const logsConfig = this.config.logs;
1982
2079
  this.updateState({ lifecycle: "runningOptOut" });
1983
2080
  let optOutResult;
1984
2081
  if (!this.foundCmp) {
1985
- enableLogs && console.log("no CMP to opt out");
2082
+ logsConfig.errors && console.log("no CMP to opt out");
1986
2083
  optOutResult = false;
1987
2084
  } else {
1988
- 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}`);
1989
2086
  optOutResult = await this.foundCmp.optOut();
1990
- enableLogs && console.log(`${this.foundCmp.name}: opt out result ${optOutResult}`);
2087
+ logsConfig.lifecycle && console.log(`${this.foundCmp.name}: opt out result ${optOutResult}`);
1991
2088
  }
1992
2089
  if (this.config.enablePrehide) {
1993
2090
  this.undoPrehide();
@@ -2013,15 +2110,16 @@
2013
2110
  return optOutResult;
2014
2111
  }
2015
2112
  async doOptIn() {
2113
+ const logsConfig = this.config.logs;
2016
2114
  this.updateState({ lifecycle: "runningOptIn" });
2017
2115
  let optInResult;
2018
2116
  if (!this.foundCmp) {
2019
- enableLogs && console.log("no CMP to opt in");
2117
+ logsConfig.errors && console.log("no CMP to opt in");
2020
2118
  optInResult = false;
2021
2119
  } else {
2022
- 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}`);
2023
2121
  optInResult = await this.foundCmp.optIn();
2024
- enableLogs && console.log(`${this.foundCmp.name}: opt in result ${optInResult}`);
2122
+ logsConfig.lifecycle && console.log(`${this.foundCmp.name}: opt in result ${optInResult}`);
2025
2123
  }
2026
2124
  if (this.config.enablePrehide) {
2027
2125
  this.undoPrehide();
@@ -2048,12 +2146,13 @@
2048
2146
  return optInResult;
2049
2147
  }
2050
2148
  async doSelfTest() {
2149
+ const logsConfig = this.config.logs;
2051
2150
  let selfTestResult;
2052
2151
  if (!this.foundCmp) {
2053
- enableLogs && console.log("no CMP to self test");
2152
+ logsConfig.errors && console.log("no CMP to self test");
2054
2153
  selfTestResult = false;
2055
2154
  } else {
2056
- 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}`);
2057
2156
  selfTestResult = await this.foundCmp.test();
2058
2157
  }
2059
2158
  this.sendContentMessage({
@@ -2066,19 +2165,21 @@
2066
2165
  return selfTestResult;
2067
2166
  }
2068
2167
  async waitForPopup(cmp, retries = 5, interval = 500) {
2069
- 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);
2070
2170
  const isOpen = await cmp.detectPopup().catch((e) => {
2071
- enableLogs && console.warn(`error detecting popup for ${cmp.name}`, e);
2171
+ logsConfig.errors && console.warn(`error detecting popup for ${cmp.name}`, e);
2072
2172
  return false;
2073
2173
  });
2074
2174
  if (!isOpen && retries > 0) {
2075
- await wait(interval);
2175
+ await this.domActions.wait(interval);
2076
2176
  return this.waitForPopup(cmp, retries - 1, interval);
2077
2177
  }
2078
- enableLogs && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
2178
+ logsConfig.lifecycle && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
2079
2179
  return isOpen;
2080
2180
  }
2081
2181
  prehideElements() {
2182
+ const logsConfig = this.config.logs;
2082
2183
  const globalHidden = [
2083
2184
  "#didomi-popup,.didomi-popup-container,.didomi-popup-notice,.didomi-consent-popup-preferences,#didomi-notice,.didomi-popup-backdrop,.didomi-screen-medium"
2084
2185
  ];
@@ -2091,15 +2192,15 @@
2091
2192
  this.updateState({ prehideOn: true });
2092
2193
  setTimeout(() => {
2093
2194
  if (this.config.enablePrehide && this.state.prehideOn && !["runningOptOut", "runningOptIn"].includes(this.state.lifecycle)) {
2094
- enableLogs && console.log("Process is taking too long, unhiding elements");
2195
+ logsConfig.lifecycle && console.log("Process is taking too long, unhiding elements");
2095
2196
  this.undoPrehide();
2096
2197
  }
2097
2198
  }, this.config.prehideTimeout || 2e3);
2098
- return prehide(selectors.join(","));
2199
+ return this.domActions.prehide(selectors.join(","));
2099
2200
  }
2100
2201
  undoPrehide() {
2101
2202
  this.updateState({ prehideOn: false });
2102
- return undoPrehide();
2203
+ return this.domActions.undoPrehide();
2103
2204
  }
2104
2205
  updateState(change) {
2105
2206
  Object.assign(this.state, change);
@@ -2112,7 +2213,8 @@
2112
2213
  });
2113
2214
  }
2114
2215
  async receiveMessageCallback(message) {
2115
- if (enableLogs && !["evalResp", "report"].includes(message.type)) {
2216
+ const logsConfig = this.config?.logs;
2217
+ if (logsConfig?.messages) {
2116
2218
  console.log("received from background", message, window.location.href);
2117
2219
  }
2118
2220
  switch (message.type) {