@duckduckgo/autoconsent 14.91.0 → 14.93.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.
package/lib/web.ts CHANGED
@@ -103,7 +103,6 @@ export default class AutoConsent {
103
103
  if (config.enableFilterList) {
104
104
  this.initializeFilterList();
105
105
  }
106
-
107
106
  this.rules = filterCMPs(this.rules, normalizedConfig);
108
107
 
109
108
  if (this.shouldPrehide) {
@@ -166,6 +165,8 @@ export default class AutoConsent {
166
165
  }
167
166
 
168
167
  parseDeclarativeRules(declarativeRules: RuleBundle) {
168
+ const perfEnabled = this.#config?.performanceLoggingEnabled;
169
+ perfEnabled && performance.mark('parseDeclarativeRulesStart');
169
170
  if (declarativeRules.consentomatic) {
170
171
  for (const [name, rule] of Object.entries(declarativeRules.consentomatic)) {
171
172
  this.addConsentomaticCMP(name, rule);
@@ -183,9 +184,11 @@ export default class AutoConsent {
183
184
  const rules = decodeRules(declarativeRules.compact);
184
185
  rules.forEach(this.addDeclarativeCMP.bind(this));
185
186
  } catch (e) {
186
- this.config.logs.errors && console.error(e);
187
+ this.#config?.logs.errors && console.error(e);
187
188
  }
188
189
  }
190
+ perfEnabled && performance.mark('parseDeclarativeRulesEnd');
191
+ perfEnabled && performance.measure('parseDeclarativeRules', 'parseDeclarativeRulesStart', 'parseDeclarativeRulesEnd');
189
192
  }
190
193
 
191
194
  addDeclarativeCMP(ruleset: AutoConsentCMPRule) {
@@ -210,6 +213,9 @@ export default class AutoConsent {
210
213
  this.updateState({ lifecycle: 'started' });
211
214
  const foundCmps = await this.findCmp(this.config.detectRetries);
212
215
  this.updateState({ detectedCmps: foundCmps.map((c) => c.name) });
216
+ if (this.config.performanceLoggingEnabled) {
217
+ this.updateState({ performance: this.measurePerformance() });
218
+ }
213
219
  if (foundCmps.length === 0) {
214
220
  logsConfig.lifecycle && console.log('no CMP found', location.href);
215
221
  if (this.shouldPrehide) {
@@ -323,7 +329,11 @@ export default class AutoConsent {
323
329
  `Trying ${stageName} rules`,
324
330
  ruleGroup.map((r) => r.name),
325
331
  );
332
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStage_${stageName}`);
326
333
  await Promise.all(ruleGroup.map(runDetectCmp));
334
+ this.config.performanceLoggingEnabled && performance.mark(`findCmpStageEnd_${stageName}`);
335
+ this.config.performanceLoggingEnabled &&
336
+ performance.measure(`findCmp_${stageName}`, `findCmpStage_${stageName}`, `findCmpStageEnd_${stageName}`);
327
337
 
328
338
  // exit early if we already found a CMP
329
339
  if (foundCMPs.length > 0) {
@@ -352,6 +362,7 @@ export default class AutoConsent {
352
362
 
353
363
  detectHeuristics() {
354
364
  if (this.config.enableHeuristicDetection) {
365
+ this.config.performanceLoggingEnabled && performance.mark('detectHeuristicsStart');
355
366
  const { patterns, snippets } = checkHeuristicPatterns(document.documentElement?.innerText || '');
356
367
  if (
357
368
  patterns.length > 0 &&
@@ -360,6 +371,9 @@ export default class AutoConsent {
360
371
  this.config.logs.lifecycle && console.log('Heuristic patterns found', patterns, snippets);
361
372
  this.updateState({ heuristicPatterns: patterns, heuristicSnippets: snippets }); // we don't care about previously found patterns
362
373
  }
374
+ this.config.performanceLoggingEnabled && performance.mark('detectHeuristicsEnd');
375
+ this.config.performanceLoggingEnabled &&
376
+ performance.measure('detectHeuristics', 'detectHeuristicsStart', 'detectHeuristicsEnd');
363
377
  }
364
378
  }
365
379
 
@@ -666,6 +680,21 @@ export default class AutoConsent {
666
680
  case 'evalResp':
667
681
  resolveEval(message.id, message.result);
668
682
  break;
683
+ case 'measurePerformance':
684
+ this.updateState({ performance: this.measurePerformance() });
685
+ break;
669
686
  }
670
687
  }
688
+
689
+ measurePerformance() {
690
+ const getRoundedPerformanceEntries = (name: string) => performance.getEntriesByName(name).map((m) => Number(m.duration.toFixed(3)));
691
+ return {
692
+ detectHeuristics: getRoundedPerformanceEntries('detectHeuristics'),
693
+ heuristicDetector: getRoundedPerformanceEntries('heuristicDetector'),
694
+ findCmpSiteSpecific: getRoundedPerformanceEntries('findCmp_site-specific'),
695
+ findCmpGeneric: getRoundedPerformanceEntries('findCmp_generic'),
696
+ findCmpHeuristic: getRoundedPerformanceEntries('findCmp_heuristic'),
697
+ parseDeclarativeRules: getRoundedPerformanceEntries('parseDeclarativeRules'),
698
+ };
699
+ }
671
700
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckduckgo/autoconsent",
3
- "version": "14.91.0",
3
+ "version": "14.93.0",
4
4
  "description": "",
5
5
  "types": "./dist/types/web.d.ts",
6
6
  "exports": {
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "vivenu",
3
+ "vendorUrl": "https://vivenu.com",
4
+ "prehideSelectors": [],
5
+ "detectCmp": [
6
+ {
7
+ "exists": "[data-slot=\"dialog-content\"] a[href*=\"vivenu.com/dataprivacy\"]"
8
+ }
9
+ ],
10
+ "detectPopup": [
11
+ {
12
+ "visible": "[data-slot=\"dialog-content\"] a[href*=\"vivenu.com/dataprivacy\"]"
13
+ }
14
+ ],
15
+ "optIn": [
16
+ {
17
+ "waitForThenClick": "[data-slot=\"dialog-content\"]:has(a[href*=\"vivenu.com/dataprivacy\"]) button:nth-of-type(1)"
18
+ }
19
+ ],
20
+ "optOut": [
21
+ {
22
+ "waitForThenClick": "[data-slot=\"dialog-content\"]:has(a[href*=\"vivenu.com/dataprivacy\"]) button:nth-of-type(2)"
23
+ }
24
+ ],
25
+ "test": [
26
+ {
27
+ "visible": "[data-slot=\"dialog-content\"] a[href*=\"vivenu.com/dataprivacy\"]",
28
+ "check": "none"
29
+ }
30
+ ]
31
+ }