@duckduckgo/autoconsent 14.91.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.
@@ -707,7 +707,8 @@
707
707
  errors: true,
708
708
  messages: false,
709
709
  waits: false
710
- }
710
+ },
711
+ performanceLoggingEnabled: false
711
712
  };
712
713
  const updatedConfig = copyObject(defaultConfig);
713
714
  for (const key of Object.keys(defaultConfig)) {
@@ -1988,7 +1989,10 @@
1988
1989
  return false;
1989
1990
  }
1990
1991
  detectCmp() {
1992
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorStart");
1991
1993
  this.popups = getActionablePopups();
1994
+ this.autoconsent.config.performanceLoggingEnabled && performance.mark("heuristicDetectorEnd");
1995
+ this.autoconsent.config.performanceLoggingEnabled && performance.measure("heuristicDetector", "heuristicDetectorStart", "heuristicDetectorEnd");
1992
1996
  if (this.popups.length > 0) {
1993
1997
  return Promise.resolve(true);
1994
1998
  }
@@ -3379,6 +3383,8 @@
3379
3383
  });
3380
3384
  }
3381
3385
  parseDeclarativeRules(declarativeRules) {
3386
+ const perfEnabled = this.#config?.performanceLoggingEnabled;
3387
+ perfEnabled && performance.mark("parseDeclarativeRulesStart");
3382
3388
  if (declarativeRules.consentomatic) {
3383
3389
  for (const [name, rule] of Object.entries(declarativeRules.consentomatic)) {
3384
3390
  this.addConsentomaticCMP(name, rule);
@@ -3394,9 +3400,11 @@
3394
3400
  const rules = decodeRules(declarativeRules.compact);
3395
3401
  rules.forEach(this.addDeclarativeCMP.bind(this));
3396
3402
  } catch (e) {
3397
- this.config.logs.errors && console.error(e);
3403
+ this.#config?.logs.errors && console.error(e);
3398
3404
  }
3399
3405
  }
3406
+ perfEnabled && performance.mark("parseDeclarativeRulesEnd");
3407
+ perfEnabled && performance.measure("parseDeclarativeRules", "parseDeclarativeRulesStart", "parseDeclarativeRulesEnd");
3400
3408
  }
3401
3409
  addDeclarativeCMP(ruleset) {
3402
3410
  if ((ruleset.minimumRuleStepVersion || 1) <= SUPPORTED_RULE_STEP_VERSION) {
@@ -3416,6 +3424,9 @@
3416
3424
  this.updateState({ lifecycle: "started" });
3417
3425
  const foundCmps = await this.findCmp(this.config.detectRetries);
3418
3426
  this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
3427
+ if (this.config.performanceLoggingEnabled) {
3428
+ this.updateState({ performance: this.measurePerformance() });
3429
+ }
3419
3430
  if (foundCmps.length === 0) {
3420
3431
  logsConfig.lifecycle && console.log("no CMP found", location.href);
3421
3432
  if (this.shouldPrehide) {
@@ -3487,7 +3498,10 @@
3487
3498
  ];
3488
3499
  const runDetectCmp = async (cmp) => {
3489
3500
  try {
3501
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmp_${cmp.name}`);
3490
3502
  const result = await cmp.detectCmp();
3503
+ this.config.performanceLoggingEnabled && performance.mark(`detectCmpEnd_${cmp.name}`);
3504
+ this.config.performanceLoggingEnabled && performance.measure(`detectCmp_${cmp.name}`, `detectCmp_${cmp.name}`, `detectCmpEnd_${cmp.name}`);
3491
3505
  if (result) {
3492
3506
  logsConfig.lifecycle && console.log(`Found CMP: ${cmp.name} ${window.location.href}`);
3493
3507
  this.sendContentMessage({
@@ -3509,7 +3523,10 @@
3509
3523
  `Trying ${stageName} rules`,
3510
3524
  ruleGroup.map((r) => r.name)
3511
3525
  );
3526
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStage_${stageName}`);
3512
3527
  await Promise.all(ruleGroup.map(runDetectCmp));
3528
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStageEnd_${stageName}`);
3529
+ this.config.performanceLoggingEnabled && performance.measure(`findCmp_${stageName}`, `findCmpStage_${stageName}`, `findCmpStageEnd_${stageName}`);
3513
3530
  if (foundCMPs.length > 0) {
3514
3531
  break;
3515
3532
  }
@@ -3527,11 +3544,14 @@
3527
3544
  }
3528
3545
  detectHeuristics() {
3529
3546
  if (this.config.enableHeuristicDetection) {
3547
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsStart");
3530
3548
  const { patterns, snippets: snippets2 } = checkHeuristicPatterns(document.documentElement?.innerText || "");
3531
3549
  if (patterns.length > 0 && (patterns.length !== this.state.heuristicPatterns.length || this.state.heuristicPatterns.some((p, i) => p !== patterns[i]))) {
3532
3550
  this.config.logs.lifecycle && console.log("Heuristic patterns found", patterns, snippets2);
3533
3551
  this.updateState({ heuristicPatterns: patterns, heuristicSnippets: snippets2 });
3534
3552
  }
3553
+ this.config.performanceLoggingEnabled && performance.mark("detectHeuristicsEnd");
3554
+ this.config.performanceLoggingEnabled && performance.measure("detectHeuristics", "detectHeuristicsStart", "detectHeuristicsEnd");
3535
3555
  }
3536
3556
  }
3537
3557
  /**
@@ -3793,8 +3813,33 @@
3793
3813
  case "evalResp":
3794
3814
  resolveEval(message.id, message.result);
3795
3815
  break;
3816
+ case "measurePerformance":
3817
+ this.updateState({ performance: this.measurePerformance() });
3818
+ break;
3796
3819
  }
3797
3820
  }
3821
+ measurePerformance() {
3822
+ const getRoundedPerformanceEntries = (name) => performance.getEntriesByName(name).map((m) => Number(m.duration.toFixed(3)));
3823
+ return {
3824
+ detectHeuristics: getRoundedPerformanceEntries("detectHeuristics"),
3825
+ heuristicDetector: getRoundedPerformanceEntries("heuristicDetector"),
3826
+ findCmpSiteSpecific: getRoundedPerformanceEntries("findCmp_site-specific"),
3827
+ findCmpGeneric: getRoundedPerformanceEntries("findCmp_generic"),
3828
+ findCmpHeuristic: getRoundedPerformanceEntries("findCmp_heuristic"),
3829
+ parseDeclarativeRules: getRoundedPerformanceEntries("parseDeclarativeRules")
3830
+ };
3831
+ }
3832
+ measureDetailedRulePerformance() {
3833
+ const cmpPerformance = performance.getEntriesByType("measure").filter((m) => m.name.startsWith("detectCmp_")).reduce((acc, m) => {
3834
+ const k = m.name.slice(10);
3835
+ if (!acc[k]) {
3836
+ acc[k] = 0;
3837
+ }
3838
+ acc[k] += m.duration;
3839
+ return acc;
3840
+ }, /* @__PURE__ */ Object.create(null));
3841
+ return cmpPerformance;
3842
+ }
3798
3843
  };
3799
3844
 
3800
3845
  // addon/content.ts
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Autoconsent",
4
- "version": "2026.6.5",
4
+ "version": "2026.6.6",
5
5
  "background": {
6
6
  "service_worker": "background.bundle.js"
7
7
  },
@@ -538,7 +538,8 @@
538
538
  errors: true,
539
539
  messages: false,
540
540
  waits: false
541
- }
541
+ },
542
+ performanceLoggingEnabled: false
542
543
  };
543
544
  const updatedConfig = copyObject(defaultConfig);
544
545
  for (const key of Object.keys(defaultConfig)) {
@@ -571,6 +572,9 @@
571
572
  waits: true
572
573
  };
573
574
  }
575
+ if (storedConfig.performanceLoggingEnabled === void 0) {
576
+ storedConfig.performanceLoggingEnabled = true;
577
+ }
574
578
  return normalizeConfig(storedConfig);
575
579
  }
576
580
  async function showOptOutStatus(tabId, status, cmp = "") {