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