@duckduckgo/autoconsent 14.90.0 → 14.92.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.
@@ -742,7 +742,8 @@ function normalizeConfig(providedConfig) {
742
742
  errors: true,
743
743
  messages: false,
744
744
  waits: false
745
- }
745
+ },
746
+ performanceLoggingEnabled: false
746
747
  };
747
748
  const updatedConfig = copyObject(defaultConfig);
748
749
  for (const key of Object.keys(defaultConfig)) {
@@ -2023,7 +2024,10 @@ var AutoConsentHeuristicCMP = class extends AutoConsentCMPBase {
2023
2024
  return false;
2024
2025
  }
2025
2026
  detectCmp() {
2027
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorStart");
2026
2028
  this.popups = getActionablePopups();
2029
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorEnd");
2030
+ this.autoconsent.config.performanceLoggingEnabled && performance.measure("heuristicDetector", "heuristicDetectorStart", "heuristicDetectorEnd");
2027
2031
  if (this.popups.length > 0) {
2028
2032
  return Promise.resolve(true);
2029
2033
  }
@@ -3647,6 +3651,8 @@ var AutoConsent = class {
3647
3651
  });
3648
3652
  }
3649
3653
  parseDeclarativeRules(declarativeRules) {
3654
+ const perfEnabled = __privateGet(this, _config)?.performanceLoggingEnabled;
3655
+ perfEnabled && performance.mark("parseDeclarativeRulesStart");
3650
3656
  if (declarativeRules.consentomatic) {
3651
3657
  for (const [name, rule] of Object.entries(declarativeRules.consentomatic)) {
3652
3658
  this.addConsentomaticCMP(name, rule);
@@ -3662,9 +3668,11 @@ var AutoConsent = class {
3662
3668
  const rules = decodeRules(declarativeRules.compact);
3663
3669
  rules.forEach(this.addDeclarativeCMP.bind(this));
3664
3670
  } catch (e) {
3665
- this.config.logs.errors && console.error(e);
3671
+ __privateGet(this, _config)?.logs.errors && console.error(e);
3666
3672
  }
3667
3673
  }
3674
+ perfEnabled && performance.mark("parseDeclarativeRulesEnd");
3675
+ perfEnabled && performance.measure("parseDeclarativeRules", "parseDeclarativeRulesStart", "parseDeclarativeRulesEnd");
3668
3676
  }
3669
3677
  addDeclarativeCMP(ruleset) {
3670
3678
  if ((ruleset.minimumRuleStepVersion || 1) <= SUPPORTED_RULE_STEP_VERSION) {
@@ -3684,6 +3692,9 @@ var AutoConsent = class {
3684
3692
  this.updateState({ lifecycle: "started" });
3685
3693
  const foundCmps = await this.findCmp(this.config.detectRetries);
3686
3694
  this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
3695
+ if (this.config.performanceLoggingEnabled) {
3696
+ this.updateState({ performance: this.measurePerformance() });
3697
+ }
3687
3698
  if (foundCmps.length === 0) {
3688
3699
  logsConfig.lifecycle && console.log("no CMP found", location.href);
3689
3700
  if (this.shouldPrehide) {
@@ -3755,7 +3766,10 @@ var AutoConsent = class {
3755
3766
  ];
3756
3767
  const runDetectCmp = async (cmp) => {
3757
3768
  try {
3769
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmp_${cmp.name}`);
3758
3770
  const result = await cmp.detectCmp();
3771
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmpEnd_${cmp.name}`);
3772
+ this.config.performanceLoggingEnabled && performance.measure(`detectCmp_${cmp.name}`, `detectCmp_${cmp.name}`, `detectCmpEnd_${cmp.name}`);
3759
3773
  if (result) {
3760
3774
  logsConfig.lifecycle && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
3761
3775
  this.sendContentMessage({
@@ -3777,7 +3791,10 @@ var AutoConsent = class {
3777
3791
  `Trying ${stageName} rules`,
3778
3792
  ruleGroup.map((r) => r.name)
3779
3793
  );
3794
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStage_${stageName}`);
3780
3795
  await Promise.all(ruleGroup.map(runDetectCmp));
3796
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStageEnd_${stageName}`);
3797
+ this.config.performanceLoggingEnabled && performance.measure(`findCmp_${stageName}`, `findCmpStage_${stageName}`, `findCmpStageEnd_${stageName}`);
3781
3798
  if (foundCMPs.length > 0) {
3782
3799
  break;
3783
3800
  }
@@ -3795,11 +3812,14 @@ var AutoConsent = class {
3795
3812
  }
3796
3813
  detectHeuristics() {
3797
3814
  if (this.config.enableHeuristicDetection) {
3815
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsStart");
3798
3816
  const { patterns, snippets: snippets2 } = checkHeuristicPatterns(document.documentElement?.innerText || "");
3799
3817
  if (patterns.length > 0 && (patterns.length !== this.state.heuristicPatterns.length || this.state.heuristicPatterns.some((p, i) => p !== patterns[i]))) {
3800
3818
  this.config.logs.lifecycle && console.log("Heuristic patterns found", patterns, snippets2);
3801
3819
  this.updateState({ heuristicPatterns: patterns, heuristicSnippets: snippets2 });
3802
3820
  }
3821
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsEnd");
3822
+ this.config.performanceLoggingEnabled && performance.measure("detectHeuristics", "detectHeuristicsStart", "detectHeuristicsEnd");
3803
3823
  }
3804
3824
  }
3805
3825
  /**
@@ -4061,8 +4081,33 @@ var AutoConsent = class {
4061
4081
  case "evalResp":
4062
4082
  resolveEval(message.id, message.result);
4063
4083
  break;
4084
+ case "measurePerformance":
4085
+ this.updateState({ performance: this.measurePerformance() });
4086
+ break;
4064
4087
  }
4065
4088
  }
4089
+ measurePerformance() {
4090
+ const getRoundedPerformanceEntries = (name) => performance.getEntriesByName(name).map((m) => Number(m.duration.toFixed(3)));
4091
+ return {
4092
+ detectHeuristics: getRoundedPerformanceEntries("detectHeuristics"),
4093
+ heuristicDetector: getRoundedPerformanceEntries("heuristicDetector"),
4094
+ findCmpSiteSpecific: getRoundedPerformanceEntries("findCmp_site-specific"),
4095
+ findCmpGeneric: getRoundedPerformanceEntries("findCmp_generic"),
4096
+ findCmpHeuristic: getRoundedPerformanceEntries("findCmp_heuristic"),
4097
+ parseDeclarativeRules: getRoundedPerformanceEntries("parseDeclarativeRules")
4098
+ };
4099
+ }
4100
+ measureDetailedRulePerformance() {
4101
+ const cmpPerformance = performance.getEntriesByType("measure").filter((m) => m.name.startsWith("detectCmp_")).reduce((acc, m) => {
4102
+ const k = m.name.slice(10);
4103
+ if (!acc[k]) {
4104
+ acc[k] = 0;
4105
+ }
4106
+ acc[k] += m.duration;
4107
+ return acc;
4108
+ }, /* @__PURE__ */ Object.create(null));
4109
+ return cmpPerformance;
4110
+ }
4066
4111
  };
4067
4112
  _config = new WeakMap();
4068
4113
  // Annotate the CommonJS export names for ESM import in node:
@@ -712,7 +712,8 @@ function normalizeConfig(providedConfig) {
712
712
  errors: true,
713
713
  messages: false,
714
714
  waits: false
715
- }
715
+ },
716
+ performanceLoggingEnabled: false
716
717
  };
717
718
  const updatedConfig = copyObject(defaultConfig);
718
719
  for (const key of Object.keys(defaultConfig)) {
@@ -1993,7 +1994,10 @@ var AutoConsentHeuristicCMP = class extends AutoConsentCMPBase {
1993
1994
  return false;
1994
1995
  }
1995
1996
  detectCmp() {
1997
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorStart");
1996
1998
  this.popups = getActionablePopups();
1999
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorEnd");
2000
+ this.autoconsent.config.performanceLoggingEnabled && performance.measure("heuristicDetector", "heuristicDetectorStart", "heuristicDetectorEnd");
1997
2001
  if (this.popups.length > 0) {
1998
2002
  return Promise.resolve(true);
1999
2003
  }
@@ -3617,6 +3621,8 @@ var AutoConsent = class {
3617
3621
  });
3618
3622
  }
3619
3623
  parseDeclarativeRules(declarativeRules) {
3624
+ const perfEnabled = __privateGet(this, _config)?.performanceLoggingEnabled;
3625
+ perfEnabled && performance.mark("parseDeclarativeRulesStart");
3620
3626
  if (declarativeRules.consentomatic) {
3621
3627
  for (const [name, rule] of Object.entries(declarativeRules.consentomatic)) {
3622
3628
  this.addConsentomaticCMP(name, rule);
@@ -3632,9 +3638,11 @@ var AutoConsent = class {
3632
3638
  const rules = decodeRules(declarativeRules.compact);
3633
3639
  rules.forEach(this.addDeclarativeCMP.bind(this));
3634
3640
  } catch (e) {
3635
- this.config.logs.errors && console.error(e);
3641
+ __privateGet(this, _config)?.logs.errors && console.error(e);
3636
3642
  }
3637
3643
  }
3644
+ perfEnabled && performance.mark("parseDeclarativeRulesEnd");
3645
+ perfEnabled && performance.measure("parseDeclarativeRules", "parseDeclarativeRulesStart", "parseDeclarativeRulesEnd");
3638
3646
  }
3639
3647
  addDeclarativeCMP(ruleset) {
3640
3648
  if ((ruleset.minimumRuleStepVersion || 1) <= SUPPORTED_RULE_STEP_VERSION) {
@@ -3654,6 +3662,9 @@ var AutoConsent = class {
3654
3662
  this.updateState({ lifecycle: "started" });
3655
3663
  const foundCmps = await this.findCmp(this.config.detectRetries);
3656
3664
  this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
3665
+ if (this.config.performanceLoggingEnabled) {
3666
+ this.updateState({ performance: this.measurePerformance() });
3667
+ }
3657
3668
  if (foundCmps.length === 0) {
3658
3669
  logsConfig.lifecycle && console.log("no CMP found", location.href);
3659
3670
  if (this.shouldPrehide) {
@@ -3725,7 +3736,10 @@ var AutoConsent = class {
3725
3736
  ];
3726
3737
  const runDetectCmp = async (cmp) => {
3727
3738
  try {
3739
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmp_${cmp.name}`);
3728
3740
  const result = await cmp.detectCmp();
3741
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmpEnd_${cmp.name}`);
3742
+ this.config.performanceLoggingEnabled && performance.measure(`detectCmp_${cmp.name}`, `detectCmp_${cmp.name}`, `detectCmpEnd_${cmp.name}`);
3729
3743
  if (result) {
3730
3744
  logsConfig.lifecycle && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
3731
3745
  this.sendContentMessage({
@@ -3747,7 +3761,10 @@ var AutoConsent = class {
3747
3761
  `Trying ${stageName} rules`,
3748
3762
  ruleGroup.map((r) => r.name)
3749
3763
  );
3764
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStage_${stageName}`);
3750
3765
  await Promise.all(ruleGroup.map(runDetectCmp));
3766
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStageEnd_${stageName}`);
3767
+ this.config.performanceLoggingEnabled && performance.measure(`findCmp_${stageName}`, `findCmpStage_${stageName}`, `findCmpStageEnd_${stageName}`);
3751
3768
  if (foundCMPs.length > 0) {
3752
3769
  break;
3753
3770
  }
@@ -3765,11 +3782,14 @@ var AutoConsent = class {
3765
3782
  }
3766
3783
  detectHeuristics() {
3767
3784
  if (this.config.enableHeuristicDetection) {
3785
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsStart");
3768
3786
  const { patterns, snippets: snippets2 } = checkHeuristicPatterns(document.documentElement?.innerText || "");
3769
3787
  if (patterns.length > 0 && (patterns.length !== this.state.heuristicPatterns.length || this.state.heuristicPatterns.some((p, i) => p !== patterns[i]))) {
3770
3788
  this.config.logs.lifecycle && console.log("Heuristic patterns found", patterns, snippets2);
3771
3789
  this.updateState({ heuristicPatterns: patterns, heuristicSnippets: snippets2 });
3772
3790
  }
3791
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsEnd");
3792
+ this.config.performanceLoggingEnabled && performance.measure("detectHeuristics", "detectHeuristicsStart", "detectHeuristicsEnd");
3773
3793
  }
3774
3794
  }
3775
3795
  /**
@@ -4031,8 +4051,33 @@ var AutoConsent = class {
4031
4051
  case "evalResp":
4032
4052
  resolveEval(message.id, message.result);
4033
4053
  break;
4054
+ case "measurePerformance":
4055
+ this.updateState({ performance: this.measurePerformance() });
4056
+ break;
4034
4057
  }
4035
4058
  }
4059
+ measurePerformance() {
4060
+ const getRoundedPerformanceEntries = (name) => performance.getEntriesByName(name).map((m) => Number(m.duration.toFixed(3)));
4061
+ return {
4062
+ detectHeuristics: getRoundedPerformanceEntries("detectHeuristics"),
4063
+ heuristicDetector: getRoundedPerformanceEntries("heuristicDetector"),
4064
+ findCmpSiteSpecific: getRoundedPerformanceEntries("findCmp_site-specific"),
4065
+ findCmpGeneric: getRoundedPerformanceEntries("findCmp_generic"),
4066
+ findCmpHeuristic: getRoundedPerformanceEntries("findCmp_heuristic"),
4067
+ parseDeclarativeRules: getRoundedPerformanceEntries("parseDeclarativeRules")
4068
+ };
4069
+ }
4070
+ measureDetailedRulePerformance() {
4071
+ const cmpPerformance = performance.getEntriesByType("measure").filter((m) => m.name.startsWith("detectCmp_")).reduce((acc, m) => {
4072
+ const k = m.name.slice(10);
4073
+ if (!acc[k]) {
4074
+ acc[k] = 0;
4075
+ }
4076
+ acc[k] += m.duration;
4077
+ return acc;
4078
+ }, /* @__PURE__ */ Object.create(null));
4079
+ return cmpPerformance;
4080
+ }
4036
4081
  };
4037
4082
  _config = new WeakMap();
4038
4083
  export {
@@ -11305,7 +11305,8 @@ function normalizeConfig(providedConfig) {
11305
11305
  errors: true,
11306
11306
  messages: false,
11307
11307
  waits: false
11308
- }
11308
+ },
11309
+ performanceLoggingEnabled: false
11309
11310
  };
11310
11311
  const updatedConfig = copyObject(defaultConfig);
11311
11312
  for (const key of Object.keys(defaultConfig)) {
@@ -13253,7 +13254,10 @@ var AutoConsentHeuristicCMP = class extends AutoConsentCMPBase {
13253
13254
  return false;
13254
13255
  }
13255
13256
  detectCmp() {
13257
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorStart");
13256
13258
  this.popups = getActionablePopups();
13259
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorEnd");
13260
+ this.autoconsent.config.performanceLoggingEnabled && performance.measure("heuristicDetector", "heuristicDetectorStart", "heuristicDetectorEnd");
13257
13261
  if (this.popups.length > 0) {
13258
13262
  return Promise.resolve(true);
13259
13263
  }
@@ -14645,6 +14649,8 @@ var AutoConsent = class {
14645
14649
  });
14646
14650
  }
14647
14651
  parseDeclarativeRules(declarativeRules) {
14652
+ const perfEnabled = __privateGet(this, _config)?.performanceLoggingEnabled;
14653
+ perfEnabled && performance.mark("parseDeclarativeRulesStart");
14648
14654
  if (declarativeRules.consentomatic) {
14649
14655
  for (const [name, rule] of Object.entries(declarativeRules.consentomatic)) {
14650
14656
  this.addConsentomaticCMP(name, rule);
@@ -14660,9 +14666,11 @@ var AutoConsent = class {
14660
14666
  const rules = decodeRules(declarativeRules.compact);
14661
14667
  rules.forEach(this.addDeclarativeCMP.bind(this));
14662
14668
  } catch (e) {
14663
- this.config.logs.errors && console.error(e);
14669
+ __privateGet(this, _config)?.logs.errors && console.error(e);
14664
14670
  }
14665
14671
  }
14672
+ perfEnabled && performance.mark("parseDeclarativeRulesEnd");
14673
+ perfEnabled && performance.measure("parseDeclarativeRules", "parseDeclarativeRulesStart", "parseDeclarativeRulesEnd");
14666
14674
  }
14667
14675
  addDeclarativeCMP(ruleset) {
14668
14676
  if ((ruleset.minimumRuleStepVersion || 1) <= SUPPORTED_RULE_STEP_VERSION) {
@@ -14682,6 +14690,9 @@ var AutoConsent = class {
14682
14690
  this.updateState({ lifecycle: "started" });
14683
14691
  const foundCmps = await this.findCmp(this.config.detectRetries);
14684
14692
  this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
14693
+ if (this.config.performanceLoggingEnabled) {
14694
+ this.updateState({ performance: this.measurePerformance() });
14695
+ }
14685
14696
  if (foundCmps.length === 0) {
14686
14697
  logsConfig.lifecycle && console.log("no CMP found", location.href);
14687
14698
  if (this.shouldPrehide) {
@@ -14753,7 +14764,10 @@ var AutoConsent = class {
14753
14764
  ];
14754
14765
  const runDetectCmp = async (cmp) => {
14755
14766
  try {
14767
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmp_${cmp.name}`);
14756
14768
  const result = await cmp.detectCmp();
14769
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmpEnd_${cmp.name}`);
14770
+ this.config.performanceLoggingEnabled && performance.measure(`detectCmp_${cmp.name}`, `detectCmp_${cmp.name}`, `detectCmpEnd_${cmp.name}`);
14757
14771
  if (result) {
14758
14772
  logsConfig.lifecycle && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
14759
14773
  this.sendContentMessage({
@@ -14775,7 +14789,10 @@ var AutoConsent = class {
14775
14789
  `Trying ${stageName} rules`,
14776
14790
  ruleGroup.map((r) => r.name)
14777
14791
  );
14792
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStage_${stageName}`);
14778
14793
  await Promise.all(ruleGroup.map(runDetectCmp));
14794
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStageEnd_${stageName}`);
14795
+ this.config.performanceLoggingEnabled && performance.measure(`findCmp_${stageName}`, `findCmpStage_${stageName}`, `findCmpStageEnd_${stageName}`);
14779
14796
  if (foundCMPs.length > 0) {
14780
14797
  break;
14781
14798
  }
@@ -14793,11 +14810,14 @@ var AutoConsent = class {
14793
14810
  }
14794
14811
  detectHeuristics() {
14795
14812
  if (this.config.enableHeuristicDetection) {
14813
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsStart");
14796
14814
  const { patterns, snippets: snippets2 } = checkHeuristicPatterns(document.documentElement?.innerText || "");
14797
14815
  if (patterns.length > 0 && (patterns.length !== this.state.heuristicPatterns.length || this.state.heuristicPatterns.some((p, i) => p !== patterns[i]))) {
14798
14816
  this.config.logs.lifecycle && console.log("Heuristic patterns found", patterns, snippets2);
14799
14817
  this.updateState({ heuristicPatterns: patterns, heuristicSnippets: snippets2 });
14800
14818
  }
14819
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsEnd");
14820
+ this.config.performanceLoggingEnabled && performance.measure("detectHeuristics", "detectHeuristicsStart", "detectHeuristicsEnd");
14801
14821
  }
14802
14822
  }
14803
14823
  /**
@@ -15059,8 +15079,33 @@ var AutoConsent = class {
15059
15079
  case "evalResp":
15060
15080
  resolveEval(message.id, message.result);
15061
15081
  break;
15082
+ case "measurePerformance":
15083
+ this.updateState({ performance: this.measurePerformance() });
15084
+ break;
15062
15085
  }
15063
15086
  }
15087
+ measurePerformance() {
15088
+ const getRoundedPerformanceEntries = (name) => performance.getEntriesByName(name).map((m) => Number(m.duration.toFixed(3)));
15089
+ return {
15090
+ detectHeuristics: getRoundedPerformanceEntries("detectHeuristics"),
15091
+ heuristicDetector: getRoundedPerformanceEntries("heuristicDetector"),
15092
+ findCmpSiteSpecific: getRoundedPerformanceEntries("findCmp_site-specific"),
15093
+ findCmpGeneric: getRoundedPerformanceEntries("findCmp_generic"),
15094
+ findCmpHeuristic: getRoundedPerformanceEntries("findCmp_heuristic"),
15095
+ parseDeclarativeRules: getRoundedPerformanceEntries("parseDeclarativeRules")
15096
+ };
15097
+ }
15098
+ measureDetailedRulePerformance() {
15099
+ const cmpPerformance = performance.getEntriesByType("measure").filter((m) => m.name.startsWith("detectCmp_")).reduce((acc, m) => {
15100
+ const k = m.name.slice(10);
15101
+ if (!acc[k]) {
15102
+ acc[k] = 0;
15103
+ }
15104
+ acc[k] += m.duration;
15105
+ return acc;
15106
+ }, /* @__PURE__ */ Object.create(null));
15107
+ return cmpPerformance;
15108
+ }
15064
15109
  };
15065
15110
  _config = new WeakMap();
15066
15111
 
@@ -11239,7 +11239,8 @@ function normalizeConfig(providedConfig) {
11239
11239
  errors: true,
11240
11240
  messages: false,
11241
11241
  waits: false
11242
- }
11242
+ },
11243
+ performanceLoggingEnabled: false
11243
11244
  };
11244
11245
  const updatedConfig = copyObject(defaultConfig);
11245
11246
  for (const key of Object.keys(defaultConfig)) {
@@ -13187,7 +13188,10 @@ var AutoConsentHeuristicCMP = class extends AutoConsentCMPBase {
13187
13188
  return false;
13188
13189
  }
13189
13190
  detectCmp() {
13191
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorStart");
13190
13192
  this.popups = getActionablePopups();
13193
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorEnd");
13194
+ this.autoconsent.config.performanceLoggingEnabled && performance.measure("heuristicDetector", "heuristicDetectorStart", "heuristicDetectorEnd");
13191
13195
  if (this.popups.length > 0) {
13192
13196
  return Promise.resolve(true);
13193
13197
  }
@@ -14579,6 +14583,8 @@ var AutoConsent = class {
14579
14583
  });
14580
14584
  }
14581
14585
  parseDeclarativeRules(declarativeRules) {
14586
+ const perfEnabled = __privateGet(this, _config)?.performanceLoggingEnabled;
14587
+ perfEnabled && performance.mark("parseDeclarativeRulesStart");
14582
14588
  if (declarativeRules.consentomatic) {
14583
14589
  for (const [name, rule] of Object.entries(declarativeRules.consentomatic)) {
14584
14590
  this.addConsentomaticCMP(name, rule);
@@ -14594,9 +14600,11 @@ var AutoConsent = class {
14594
14600
  const rules = decodeRules(declarativeRules.compact);
14595
14601
  rules.forEach(this.addDeclarativeCMP.bind(this));
14596
14602
  } catch (e) {
14597
- this.config.logs.errors && console.error(e);
14603
+ __privateGet(this, _config)?.logs.errors && console.error(e);
14598
14604
  }
14599
14605
  }
14606
+ perfEnabled && performance.mark("parseDeclarativeRulesEnd");
14607
+ perfEnabled && performance.measure("parseDeclarativeRules", "parseDeclarativeRulesStart", "parseDeclarativeRulesEnd");
14600
14608
  }
14601
14609
  addDeclarativeCMP(ruleset) {
14602
14610
  if ((ruleset.minimumRuleStepVersion || 1) <= SUPPORTED_RULE_STEP_VERSION) {
@@ -14616,6 +14624,9 @@ var AutoConsent = class {
14616
14624
  this.updateState({ lifecycle: "started" });
14617
14625
  const foundCmps = await this.findCmp(this.config.detectRetries);
14618
14626
  this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
14627
+ if (this.config.performanceLoggingEnabled) {
14628
+ this.updateState({ performance: this.measurePerformance() });
14629
+ }
14619
14630
  if (foundCmps.length === 0) {
14620
14631
  logsConfig.lifecycle && console.log("no CMP found", location.href);
14621
14632
  if (this.shouldPrehide) {
@@ -14687,7 +14698,10 @@ var AutoConsent = class {
14687
14698
  ];
14688
14699
  const runDetectCmp = async (cmp) => {
14689
14700
  try {
14701
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmp_${cmp.name}`);
14690
14702
  const result = await cmp.detectCmp();
14703
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmpEnd_${cmp.name}`);
14704
+ this.config.performanceLoggingEnabled && performance.measure(`detectCmp_${cmp.name}`, `detectCmp_${cmp.name}`, `detectCmpEnd_${cmp.name}`);
14691
14705
  if (result) {
14692
14706
  logsConfig.lifecycle && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
14693
14707
  this.sendContentMessage({
@@ -14709,7 +14723,10 @@ var AutoConsent = class {
14709
14723
  `Trying ${stageName} rules`,
14710
14724
  ruleGroup.map((r) => r.name)
14711
14725
  );
14726
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStage_${stageName}`);
14712
14727
  await Promise.all(ruleGroup.map(runDetectCmp));
14728
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStageEnd_${stageName}`);
14729
+ this.config.performanceLoggingEnabled && performance.measure(`findCmp_${stageName}`, `findCmpStage_${stageName}`, `findCmpStageEnd_${stageName}`);
14713
14730
  if (foundCMPs.length > 0) {
14714
14731
  break;
14715
14732
  }
@@ -14727,11 +14744,14 @@ var AutoConsent = class {
14727
14744
  }
14728
14745
  detectHeuristics() {
14729
14746
  if (this.config.enableHeuristicDetection) {
14747
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsStart");
14730
14748
  const { patterns, snippets: snippets2 } = checkHeuristicPatterns(document.documentElement?.innerText || "");
14731
14749
  if (patterns.length > 0 && (patterns.length !== this.state.heuristicPatterns.length || this.state.heuristicPatterns.some((p, i) => p !== patterns[i]))) {
14732
14750
  this.config.logs.lifecycle && console.log("Heuristic patterns found", patterns, snippets2);
14733
14751
  this.updateState({ heuristicPatterns: patterns, heuristicSnippets: snippets2 });
14734
14752
  }
14753
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsEnd");
14754
+ this.config.performanceLoggingEnabled && performance.measure("detectHeuristics", "detectHeuristicsStart", "detectHeuristicsEnd");
14735
14755
  }
14736
14756
  }
14737
14757
  /**
@@ -14993,8 +15013,33 @@ var AutoConsent = class {
14993
15013
  case "evalResp":
14994
15014
  resolveEval(message.id, message.result);
14995
15015
  break;
15016
+ case "measurePerformance":
15017
+ this.updateState({ performance: this.measurePerformance() });
15018
+ break;
14996
15019
  }
14997
15020
  }
15021
+ measurePerformance() {
15022
+ const getRoundedPerformanceEntries = (name) => performance.getEntriesByName(name).map((m) => Number(m.duration.toFixed(3)));
15023
+ return {
15024
+ detectHeuristics: getRoundedPerformanceEntries("detectHeuristics"),
15025
+ heuristicDetector: getRoundedPerformanceEntries("heuristicDetector"),
15026
+ findCmpSiteSpecific: getRoundedPerformanceEntries("findCmp_site-specific"),
15027
+ findCmpGeneric: getRoundedPerformanceEntries("findCmp_generic"),
15028
+ findCmpHeuristic: getRoundedPerformanceEntries("findCmp_heuristic"),
15029
+ parseDeclarativeRules: getRoundedPerformanceEntries("parseDeclarativeRules")
15030
+ };
15031
+ }
15032
+ measureDetailedRulePerformance() {
15033
+ const cmpPerformance = performance.getEntriesByType("measure").filter((m) => m.name.startsWith("detectCmp_")).reduce((acc, m) => {
15034
+ const k = m.name.slice(10);
15035
+ if (!acc[k]) {
15036
+ acc[k] = 0;
15037
+ }
15038
+ acc[k] += m.duration;
15039
+ return acc;
15040
+ }, /* @__PURE__ */ Object.create(null));
15041
+ return cmpPerformance;
15042
+ }
14998
15043
  };
14999
15044
  _config = new WeakMap();
15000
15045
 
@@ -714,7 +714,8 @@
714
714
  errors: true,
715
715
  messages: false,
716
716
  waits: false
717
- }
717
+ },
718
+ performanceLoggingEnabled: false
718
719
  };
719
720
  const updatedConfig = copyObject(defaultConfig);
720
721
  for (const key of Object.keys(defaultConfig)) {
@@ -1995,7 +1996,10 @@
1995
1996
  return false;
1996
1997
  }
1997
1998
  detectCmp() {
1999
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorStart");
1998
2000
  this.popups = getActionablePopups();
2001
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorEnd");
2002
+ this.autoconsent.config.performanceLoggingEnabled && performance.measure("heuristicDetector", "heuristicDetectorStart", "heuristicDetectorEnd");
1999
2003
  if (this.popups.length > 0) {
2000
2004
  return Promise.resolve(true);
2001
2005
  }
@@ -3387,6 +3391,8 @@
3387
3391
  });
3388
3392
  }
3389
3393
  parseDeclarativeRules(declarativeRules) {
3394
+ const perfEnabled = __privateGet(this, _config)?.performanceLoggingEnabled;
3395
+ perfEnabled && performance.mark("parseDeclarativeRulesStart");
3390
3396
  if (declarativeRules.consentomatic) {
3391
3397
  for (const [name, rule] of Object.entries(declarativeRules.consentomatic)) {
3392
3398
  this.addConsentomaticCMP(name, rule);
@@ -3402,9 +3408,11 @@
3402
3408
  const rules = decodeRules(declarativeRules.compact);
3403
3409
  rules.forEach(this.addDeclarativeCMP.bind(this));
3404
3410
  } catch (e) {
3405
- this.config.logs.errors && console.error(e);
3411
+ __privateGet(this, _config)?.logs.errors && console.error(e);
3406
3412
  }
3407
3413
  }
3414
+ perfEnabled && performance.mark("parseDeclarativeRulesEnd");
3415
+ perfEnabled && performance.measure("parseDeclarativeRules", "parseDeclarativeRulesStart", "parseDeclarativeRulesEnd");
3408
3416
  }
3409
3417
  addDeclarativeCMP(ruleset) {
3410
3418
  if ((ruleset.minimumRuleStepVersion || 1) <= SUPPORTED_RULE_STEP_VERSION) {
@@ -3424,6 +3432,9 @@
3424
3432
  this.updateState({ lifecycle: "started" });
3425
3433
  const foundCmps = await this.findCmp(this.config.detectRetries);
3426
3434
  this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
3435
+ if (this.config.performanceLoggingEnabled) {
3436
+ this.updateState({ performance: this.measurePerformance() });
3437
+ }
3427
3438
  if (foundCmps.length === 0) {
3428
3439
  logsConfig.lifecycle && console.log("no CMP found", location.href);
3429
3440
  if (this.shouldPrehide) {
@@ -3495,7 +3506,10 @@
3495
3506
  ];
3496
3507
  const runDetectCmp = async (cmp) => {
3497
3508
  try {
3509
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmp_${cmp.name}`);
3498
3510
  const result = await cmp.detectCmp();
3511
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmpEnd_${cmp.name}`);
3512
+ this.config.performanceLoggingEnabled && performance.measure(`detectCmp_${cmp.name}`, `detectCmp_${cmp.name}`, `detectCmpEnd_${cmp.name}`);
3499
3513
  if (result) {
3500
3514
  logsConfig.lifecycle && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
3501
3515
  this.sendContentMessage({
@@ -3517,7 +3531,10 @@
3517
3531
  `Trying ${stageName} rules`,
3518
3532
  ruleGroup.map((r) => r.name)
3519
3533
  );
3534
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStage_${stageName}`);
3520
3535
  await Promise.all(ruleGroup.map(runDetectCmp));
3536
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStageEnd_${stageName}`);
3537
+ this.config.performanceLoggingEnabled && performance.measure(`findCmp_${stageName}`, `findCmpStage_${stageName}`, `findCmpStageEnd_${stageName}`);
3521
3538
  if (foundCMPs.length > 0) {
3522
3539
  break;
3523
3540
  }
@@ -3535,11 +3552,14 @@
3535
3552
  }
3536
3553
  detectHeuristics() {
3537
3554
  if (this.config.enableHeuristicDetection) {
3555
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsStart");
3538
3556
  const { patterns, snippets: snippets2 } = checkHeuristicPatterns(document.documentElement?.innerText || "");
3539
3557
  if (patterns.length > 0 && (patterns.length !== this.state.heuristicPatterns.length || this.state.heuristicPatterns.some((p, i) => p !== patterns[i]))) {
3540
3558
  this.config.logs.lifecycle && console.log("Heuristic patterns found", patterns, snippets2);
3541
3559
  this.updateState({ heuristicPatterns: patterns, heuristicSnippets: snippets2 });
3542
3560
  }
3561
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsEnd");
3562
+ this.config.performanceLoggingEnabled && performance.measure("detectHeuristics", "detectHeuristicsStart", "detectHeuristicsEnd");
3543
3563
  }
3544
3564
  }
3545
3565
  /**
@@ -3801,8 +3821,33 @@
3801
3821
  case "evalResp":
3802
3822
  resolveEval(message.id, message.result);
3803
3823
  break;
3824
+ case "measurePerformance":
3825
+ this.updateState({ performance: this.measurePerformance() });
3826
+ break;
3804
3827
  }
3805
3828
  }
3829
+ measurePerformance() {
3830
+ const getRoundedPerformanceEntries = (name) => performance.getEntriesByName(name).map((m) => Number(m.duration.toFixed(3)));
3831
+ return {
3832
+ detectHeuristics: getRoundedPerformanceEntries("detectHeuristics"),
3833
+ heuristicDetector: getRoundedPerformanceEntries("heuristicDetector"),
3834
+ findCmpSiteSpecific: getRoundedPerformanceEntries("findCmp_site-specific"),
3835
+ findCmpGeneric: getRoundedPerformanceEntries("findCmp_generic"),
3836
+ findCmpHeuristic: getRoundedPerformanceEntries("findCmp_heuristic"),
3837
+ parseDeclarativeRules: getRoundedPerformanceEntries("parseDeclarativeRules")
3838
+ };
3839
+ }
3840
+ measureDetailedRulePerformance() {
3841
+ const cmpPerformance = performance.getEntriesByType("measure").filter((m) => m.name.startsWith("detectCmp_")).reduce((acc, m) => {
3842
+ const k = m.name.slice(10);
3843
+ if (!acc[k]) {
3844
+ acc[k] = 0;
3845
+ }
3846
+ acc[k] += m.duration;
3847
+ return acc;
3848
+ }, /* @__PURE__ */ Object.create(null));
3849
+ return cmpPerformance;
3850
+ }
3806
3851
  };
3807
3852
  _config = new WeakMap();
3808
3853
 
@@ -1,6 +1,6 @@
1
1
  import { snippets } from './eval-snippets';
2
2
  import { Config, ConsentState, RuleBundle } from './types';
3
- export type BackgroundMessage = InitResponseMessage | EvalResponseMessage | OptOutMessage | OptInMessage | SelfTestMessage;
3
+ export type BackgroundMessage = InitResponseMessage | EvalResponseMessage | OptOutMessage | OptInMessage | SelfTestMessage | MeasurePerformanceMessage;
4
4
  export type ContentScriptMessage = InitMessage | EvalMessage | DelayMessage | DetectedMessage | FoundMessage | OptOutResultMessage | OptInResultMessage | SelfTestResultMessage | DoneMessage | ErrorMessage | ReportMessage;
5
5
  export type BackgroundDevtoolsMessage = DevtoolsAuditMessage | InstanceTerminatedMessage | InitResponseMessage;
6
6
  export type DevtoolsMessage = DevtoolsInitMessage;
@@ -99,3 +99,6 @@ export type DevtoolsInitMessage = {
99
99
  type: 'init';
100
100
  tabId: number;
101
101
  };
102
+ export type MeasurePerformanceMessage = {
103
+ type: 'measurePerformance';
104
+ };
@@ -72,6 +72,7 @@ export type Config = {
72
72
  messages: boolean;
73
73
  waits: boolean;
74
74
  };
75
+ performanceLoggingEnabled: boolean;
75
76
  };
76
77
  export type LifecycleState = 'loading' | 'initialized' | 'waitingForInitResponse' | 'started' | 'nothingDetected' | 'cosmeticFiltersDetected' | 'cmpDetected' | 'openPopupDetected' | 'runningOptOut' | 'runningOptIn' | 'optOutSucceeded' | 'optOutFailed' | 'optInSucceeded' | 'optInFailed' | 'done';
77
78
  export type ConsentState = {
@@ -88,6 +89,7 @@ export type ConsentState = {
88
89
  clicks: number;
89
90
  startTime: number;
90
91
  endTime: number;
92
+ performance?: Record<string, number[]>;
91
93
  };
92
94
  export interface ButtonData {
93
95
  text: string;
@@ -57,4 +57,13 @@ export default class AutoConsent {
57
57
  filterListFallback(): boolean;
58
58
  updateState(change: Partial<ConsentState>): void;
59
59
  receiveMessageCallback(message: BackgroundMessage): Promise<void>;
60
+ measurePerformance(): {
61
+ detectHeuristics: number[];
62
+ heuristicDetector: number[];
63
+ findCmpSiteSpecific: number[];
64
+ findCmpGeneric: number[];
65
+ findCmpHeuristic: number[];
66
+ parseDeclarativeRules: number[];
67
+ };
68
+ measureDetailedRulePerformance(): Record<string, number>;
60
69
  }
package/lib/cmps/base.ts CHANGED
@@ -442,7 +442,11 @@ export class AutoConsentHeuristicCMP extends AutoConsentCMPBase {
442
442
  }
443
443
 
444
444
  detectCmp(): Promise<boolean> {
445
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark('heuristicDetectorStart');
445
446
  this.popups = getActionablePopups();
447
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark('heuristicDetectorEnd');
448
+ this.autoconsent.config.performanceLoggingEnabled &&
449
+ performance.measure('heuristicDetector', 'heuristicDetectorStart', 'heuristicDetectorEnd');
446
450
  if (this.popups.length > 0) {
447
451
  return Promise.resolve(true);
448
452
  }