@duckduckgo/autoconsent 17.4.0 → 18.1.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 (102) hide show
  1. package/.github/workflows/ddg-release.yml +6 -3
  2. package/.prettierignore +1 -0
  3. package/AGENTS.md +2 -0
  4. package/CHANGELOG.md +57 -0
  5. package/dist/addon-firefox/background.bundle.js +4 -1
  6. package/dist/addon-firefox/compact-rules.json +1 -1
  7. package/dist/addon-firefox/content.bundle.js +608 -61
  8. package/dist/addon-firefox/manifest.json +1 -1
  9. package/dist/addon-firefox/rule-index.json +1 -1
  10. package/dist/addon-firefox/rules.json +1 -1
  11. package/dist/addon-mv3/background.bundle.js +4 -1
  12. package/dist/addon-mv3/compact-rules.json +1 -1
  13. package/dist/addon-mv3/content.bundle.js +608 -61
  14. package/dist/addon-mv3/manifest.json +1 -1
  15. package/dist/addon-mv3/rule-index.json +1 -1
  16. package/dist/addon-mv3/rules.json +1 -1
  17. package/dist/autoconsent.cjs.js +614 -67
  18. package/dist/autoconsent.esm.js +614 -67
  19. package/dist/autoconsent.playwright.js +608 -61
  20. package/dist/autoconsent.standalone.js +615 -68
  21. package/dist/heuristics.cjs.js +621 -52
  22. package/dist/heuristics.mjs +609 -50
  23. package/dist/types/cmps/tiktok.d.ts +0 -2
  24. package/dist/types/eval-snippets.d.ts +2 -0
  25. package/dist/types/heuristic-classify.d.ts +2 -6
  26. package/dist/types/heuristic-detect.d.ts +32 -0
  27. package/dist/types/heuristic-literals.d.ts +1 -0
  28. package/dist/types/heuristic-negatives.d.ts +25 -0
  29. package/dist/types/heuristic-patterns.d.ts +18 -2
  30. package/dist/types/heuristic-prefilter.d.ts +13 -0
  31. package/docs/heuristic-detection.md +78 -0
  32. package/docs/heuristic-prefilter.md +62 -0
  33. package/eslint.config.mjs +16 -1
  34. package/lib/cmps/evidon.ts +5 -4
  35. package/lib/cmps/tiktok.ts +0 -5
  36. package/lib/eval-snippets.ts +3 -0
  37. package/lib/heuristic-classify.ts +4 -39
  38. package/lib/heuristic-detect.ts +209 -0
  39. package/lib/heuristic-literals.ts +207 -0
  40. package/lib/heuristic-negatives.ts +173 -0
  41. package/lib/heuristic-patterns.ts +104 -31
  42. package/lib/heuristic-prefilter.ts +40 -0
  43. package/lib/heuristics.ts +8 -4
  44. package/lib/web.ts +1 -1
  45. package/package.json +2 -1
  46. package/rules/autoconsent/binogi.json +32 -0
  47. package/rules/autoconsent/bokio.json +32 -0
  48. package/rules/autoconsent/botble-cookie-consent.json +16 -0
  49. package/rules/autoconsent/calcolo-tools.json +23 -0
  50. package/rules/autoconsent/consilium-europa-eu.json +35 -0
  51. package/rules/autoconsent/dtu-findit.json +47 -0
  52. package/rules/autoconsent/hikvision.com.json +18 -0
  53. package/rules/autoconsent/hmgroup-turbocookie.json +18 -0
  54. package/rules/autoconsent/hmrc-tracking-consent.json +40 -0
  55. package/rules/autoconsent/hurra-consent.json +16 -0
  56. package/rules/autoconsent/isidewith.com.json +38 -0
  57. package/rules/autoconsent/landgate.json +10 -0
  58. package/rules/autoconsent/meta-cookie-dialog-v2.json +40 -0
  59. package/rules/autoconsent/pakamera.json +19 -0
  60. package/rules/autoconsent/purecookie-cosmetic.json +13 -0
  61. package/rules/autoconsent/random-org.json +41 -0
  62. package/rules/autoconsent/reverb-gdpr-nag.json +18 -0
  63. package/rules/autoconsent/reverb.json +24 -0
  64. package/rules/autoconsent/tallink.json +13 -0
  65. package/rules/autoconsent/tealium.json +4 -1
  66. package/rules/autoconsent/typo3-cookieconsent.json +9 -0
  67. package/rules/autoconsent/vinnies-org-au.json +29 -0
  68. package/rules/autoconsent/zoho.json +23 -0
  69. package/rules/compact-rules.json +1 -1
  70. package/rules/rule-index.json +1 -1
  71. package/rules/rules.json +1 -1
  72. package/scripts/build-heuristic-literals.ts +24 -0
  73. package/scripts/required-literals.ts +177 -0
  74. package/tests/binogi.spec.ts +3 -0
  75. package/tests/bokio.spec.ts +6 -0
  76. package/tests/botble-cookie-consent.spec.ts +11 -0
  77. package/tests/calcolo-tools.spec.ts +3 -0
  78. package/tests/consilium-europa-eu.spec.ts +3 -0
  79. package/tests/dtu-findit.spec.ts +3 -0
  80. package/tests/evidon.spec.ts +2 -1
  81. package/tests/hikvision.com.spec.ts +3 -0
  82. package/tests/hmgroup-turbocookie.spec.ts +7 -0
  83. package/tests/hmrc-tracking-consent.spec.ts +7 -0
  84. package/tests/hurra-consent.spec.ts +8 -0
  85. package/tests/isidewith.com.spec.ts +3 -0
  86. package/tests/landgate.spec.ts +3 -0
  87. package/tests/meta-cookie-dialog-v2.spec.ts +10 -0
  88. package/tests/pakamera.spec.ts +5 -0
  89. package/tests/purecookie-cosmetic.spec.ts +8 -0
  90. package/tests/random-org.spec.ts +3 -0
  91. package/tests/reverb.spec.ts +7 -0
  92. package/tests/tallink.spec.ts +3 -0
  93. package/tests/tiktok.spec.ts +2 -2
  94. package/tests/typo3-cookieconsent.spec.ts +10 -0
  95. package/tests/vinnies-org-au.spec.ts +3 -0
  96. package/tests/zoho.spec.ts +5 -0
  97. package/tests-wtr/heuristics/heuristics-utils.test.ts +222 -8
  98. package/tests-wtr/heuristics/regex-syntax.test.ts +81 -0
  99. package/rules/generated/auto_GB_capcut.com_0.json +0 -28
  100. package/rules/generated/auto_NL_bonprix.nl_ovi.json +0 -40
  101. package/tests/generated/auto_GB_capcut.com_0.spec.ts +0 -2
  102. package/tests/generated/auto_NL_bonprix.nl_ovi.spec.ts +0 -2
@@ -1,8 +1,6 @@
1
- import { RunContext } from '../rules';
2
1
  import AutoConsentCMPBase from './base';
3
2
  export default class Tiktok extends AutoConsentCMPBase {
4
3
  name: string;
5
- runContext: RunContext;
6
4
  get hasSelfTest(): boolean;
7
5
  get isIntermediate(): boolean;
8
6
  get isCosmetic(): boolean;
@@ -78,6 +78,7 @@ export declare const snippets: {
78
78
  EVAL_TEALIUM_2: () => any;
79
79
  EVAL_TEALIUM_3: () => boolean;
80
80
  EVAL_TEALIUM_DONOTSELL_CHECK: () => boolean;
81
+ EVAL_TEALIUM_NO_DECISION: () => boolean;
81
82
  EVAL_TESTCMP_STEP: () => boolean;
82
83
  EVAL_TESTCMP_0: () => boolean;
83
84
  EVAL_TESTCMP_COSMETIC_0: () => boolean;
@@ -93,5 +94,6 @@ export declare const snippets: {
93
94
  EVAL_USERCENTRICS_BUTTON_0: () => any;
94
95
  EVAL_WAITROSE_0: () => boolean;
95
96
  EVAL_WBD_LTP_CLOSE: () => any;
97
+ EVAL_ZOHO_TEST: () => boolean;
96
98
  };
97
99
  export declare function getFunctionBody(snippetFunc: () => any): string;
@@ -1,17 +1,13 @@
1
1
  export * from './heuristic-patterns';
2
+ export * from './heuristic-negatives';
3
+ export * from './heuristic-detect';
2
4
  export type ButtonRegexClassification = 'reject' | 'settings' | 'accept' | 'acknowledge' | 'other';
3
5
  export type PopupClassification = 'none' | 'reject' | 'tier1' | 'tier2';
4
6
  export type ClassifiableButton = {
5
7
  text: string;
6
8
  regexClassification?: ButtonRegexClassification;
7
9
  };
8
- export declare function checkHeuristicPatterns(allText: string, detectPatterns?: RegExp[]): {
9
- patterns: string[];
10
- snippets: string[];
11
- };
12
- export declare function hasHeuristicPatterns(allText: string, detectPatterns?: RegExp[]): boolean;
13
10
  export declare function classifyButtons(buttons: ClassifiableButton[]): void;
14
- export declare function isExcludedPopup(popupText: string, excludePatterns?: RegExp[]): boolean;
15
11
  export declare function classifyPopup(buttons: ClassifiableButton[]): PopupClassification;
16
12
  export declare function cleanButtonText(buttonText: string): string;
17
13
  export declare function classifyButtonTextRegex(buttonText: string): ButtonRegexClassification;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Matching heuristic detect patterns against a text: input scopes, the required-literal prefilter and context negatives.
3
+ * Text only, no DOM APIs. See docs/heuristic-detection.md.
4
+ */
5
+ import { DetectPattern, HeuristicInput } from './heuristic-patterns';
6
+ import { ContextNegative } from './heuristic-negatives';
7
+ /** The text around a match that a context negative is tested on. */
8
+ export declare function negativeContext(text: string, start: number, end: number, negative: ContextNegative): string;
9
+ /**
10
+ * Matches the detect patterns against a text. `input` says what the text is: a popup element's text or a whole page's;
11
+ * patterns and context negatives scoped to the other input are skipped (without it, only unscoped ones apply). A
12
+ * pattern counts if one of its matches survives the context negatives; `suppressed` lists those that didn't.
13
+ * `patterns` and `negatives` replace the built-in lists.
14
+ */
15
+ export declare function checkHeuristicPatterns(allText: string, input?: HeuristicInput, options?: HeuristicPatternOptions): {
16
+ patterns: string[];
17
+ snippets: string[];
18
+ suppressed: {
19
+ pattern: string;
20
+ negative: string;
21
+ }[];
22
+ };
23
+ export declare function hasHeuristicPatterns(allText: string, input?: HeuristicInput, options?: HeuristicPatternOptions): boolean;
24
+ export type HeuristicPatternOptions = {
25
+ patterns?: DetectPattern[];
26
+ negatives?: ContextNegative[];
27
+ };
28
+ /**
29
+ * Names of the whole-text context negatives that exclude a text as this input, whether or not detect patterns match it:
30
+ * why a popup is not a consent popup.
31
+ */
32
+ export declare function excludedBy(text: string, input?: HeuristicInput, negatives?: ContextNegative[]): string[];
@@ -0,0 +1 @@
1
+ export declare const DETECT_PATTERN_LITERALS: string[][];
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Context negatives for heuristic detect patterns: wording that shows a match, or a whole popup, isn't a consent notice.
3
+ * The vocabulary they test (consent choices, age wording, leave buttons, legal clauses) is defined here, next to them.
4
+ * See docs/heuristic-detection.md.
5
+ */
6
+ import { HeuristicInput } from './heuristic-patterns';
7
+ /** A test on a text: a regex that must match it, or a predicate. */
8
+ export type TextTest = RegExp | ((text: string) => boolean);
9
+ /**
10
+ * Drops a single detect pattern match when its context matches `pattern` and not `unless` (with only `unless`, when the
11
+ * context lacks it). The context is `window` chars either side of the match, or its line and `lines` lines either side
12
+ * ([before, after] counts each side); the default is 150 chars. With `whole`, the context is the whole text, so a hit
13
+ * drops every match: the text is excluded. `appliesTo` limits it to some detect patterns.
14
+ */
15
+ export type ContextNegative = {
16
+ name: string;
17
+ pattern?: RegExp;
18
+ unless?: TextTest;
19
+ window?: number;
20
+ lines?: number | [number, number];
21
+ whole?: boolean;
22
+ input?: HeuristicInput;
23
+ appliesTo?: RegExp[];
24
+ };
25
+ export declare const DETECT_CONTEXT_NEGATIVES: ContextNegative[];
@@ -1,10 +1,26 @@
1
- export declare const DETECT_PATTERNS: RegExp[];
1
+ /** Which text a detect pattern or context negative applies to: a popup element's text, or a whole page's text. */
2
+ export type HeuristicInput = 'popup' | 'page';
3
+ /** A detect pattern, optionally limited to one input. */
4
+ export type DetectPattern = RegExp | {
5
+ pattern: RegExp;
6
+ input: HeuristicInput;
7
+ };
8
+ /** A detect pattern's regex. */
9
+ export declare const patternOf: (p: DetectPattern) => RegExp;
10
+ export declare const BY_CONTINUING_PRIVACY: RegExp;
11
+ export declare const ACCEPT_ALL: RegExp;
12
+ export declare const USE_OF_COOKIES: RegExp;
13
+ export declare const UTILISATION_DES_COOKIES: RegExp;
14
+ export declare const ACCEPTEZ_UTILISATION: RegExp;
15
+ export declare const VERWENDUNG_VON_COOKIES: RegExp;
16
+ export declare const DE_COOKIE_VERB: RegExp;
17
+ export declare const GEBRUIK_VAN_COOKIES: RegExp;
18
+ export declare const DETECT_PATTERNS: DetectPattern[];
2
19
  /**
3
20
  * @type {Array<string|RegExp>}
4
21
  */
5
22
  export declare const REJECT_PATTERNS: (string | RegExp)[];
6
23
  export declare const BUTTON_NEVER_MATCH_PATTERNS: RegExp[];
7
- export declare const DETECT_NEVER_MATCH_PATTERNS: RegExp[];
8
24
  export declare const SETTINGS_PATTERNS: (string | RegExp)[];
9
25
  export declare const ACCEPT_PATTERNS: (string | RegExp)[];
10
26
  export declare const ACKNOWLEDGE_PATTERNS: (string | RegExp)[];
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Required-literal prefilter for heuristic detect patterns (see docs/heuristic-prefilter.md): each built-in pattern has
3
+ * literals that any match must contain, generated at build time into heuristic-literals.ts. A text is checked for all
4
+ * of them in one pass, and a pattern whose literals are all absent can't match, so it is skipped without changing any
5
+ * result.
6
+ */
7
+ /**
8
+ * Finds which literals a text contains in one pass: a zero-width lookahead over the literals, longest first, reports
9
+ * the longest one starting at each position, and any other literal starting there is a prefix of it.
10
+ */
11
+ export declare function literalIndex(all: string[]): {
12
+ present: (lower: string) => Set<string>;
13
+ };
@@ -0,0 +1,78 @@
1
+ # Heuristic detection
2
+
3
+ Heuristic detection decides from text alone whether something looks like a cookie consent popup. It runs:
4
+
5
+ - on popup candidates found in the DOM, by the heuristic rule (`getActionablePopups` in `lib/heuristics.ts`);
6
+ - on a whole page's `innerText`, for reporting only (`detectHeuristics` in `lib/web.ts`);
7
+ - on crawl data, by tools such as tracker-radar-collector, through the `./heuristics` package entry.
8
+
9
+ ## Modules
10
+
11
+ | File | Contents |
12
+ |---|---|
13
+ | `lib/heuristic-patterns.ts` | `DETECT_PATTERNS`, the regexes that indicate a consent notice, and the button patterns |
14
+ | `lib/heuristic-negatives.ts` | `DETECT_CONTEXT_NEGATIVES`, and the vocabulary they test: consent choices, age wording, leave buttons, legal clauses |
15
+ | `lib/heuristic-detect.ts` | The matching engine: `checkHeuristicPatterns`, `hasHeuristicPatterns`, `excludedBy` |
16
+ | `lib/heuristic-prefilter.ts`, `lib/heuristic-literals.ts` | The required-literal prefilter; the literals file is generated (see [heuristic-prefilter.md](heuristic-prefilter.md)) |
17
+ | `lib/heuristic-classify.ts` | Button and popup classification, and the `./heuristics` entry, which re-exports the modules above |
18
+
19
+ ## Inputs
20
+
21
+ Every call says what the text is:
22
+
23
+ - `'popup'`: one popup element's text.
24
+ - `'page'`: a whole document's text, where cookie wording also appears in footers, policies and articles.
25
+
26
+ A detect pattern (`{ pattern, input }`) or a context negative (`input`) can be limited to one input. Without an input, only unscoped ones apply.
27
+
28
+ ## Using the lists
29
+
30
+ The `./heuristics` entry exports the lists. Their entries aren't all regexes:
31
+
32
+ - **`DETECT_PATTERNS`:** each entry is a `RegExp` or `{ pattern, input }`. Use `patternOf(p)` to get the regex. Passing an object to `String.prototype.match` would turn it into the regex `/[object Object]/`.
33
+ - **`DETECT_CONTEXT_NEGATIVES`:** each entry is a `ContextNegative`. Its `unless` may be a predicate rather than a regex.
34
+
35
+ To match text, call `checkHeuristicPatterns` or `hasHeuristicPatterns` rather than running the regexes yourself: they apply scopes, the prefilter and negatives. Custom lists go in the `patterns` and `negatives` options. The second argument is the input, and the functions throw if they get a list there, as older callers passed one.
36
+
37
+ ## Matching a text
38
+
39
+ `checkHeuristicPatterns(text, input, { patterns?, negatives? })` returns `{ patterns, snippets, suppressed }`. `hasHeuristicPatterns` gives the same answer as a boolean, and stops at the first pattern that counts.
40
+
41
+ 1. The text is cut to 100,000 characters.
42
+ 2. Patterns and negatives scoped to the other input are skipped.
43
+ 3. The prefilter skips patterns whose required literals are all missing from the text.
44
+ 4. Each remaining pattern is run. With no match, it doesn't count.
45
+ 5. For each match, the negatives that apply to that pattern (all of them, or the ones whose `appliesTo` includes it) are tested on the match's context.
46
+ 6. The pattern **counts** if at least one match has no negative hit. Otherwise it is reported in `suppressed`, with the negatives that hit.
47
+
48
+ The text matches if at least one pattern counts.
49
+
50
+ ## Context negatives
51
+
52
+ A `ContextNegative` has these fields:
53
+
54
+ | Field | Meaning |
55
+ |---|---|
56
+ | `name` | Reported in `suppressed` |
57
+ | `pattern` | Wording that shows the match isn't a consent notice. Without it, the negative hits whenever `unless` doesn't match. |
58
+ | `unless` | A regex or a predicate on the context. When it matches, the negative doesn't hit. |
59
+ | `window` | Context: this many characters either side of the match. The default is 150. |
60
+ | `lines` | Context: the match's line plus `n` lines either side, or `[before, after]` lines |
61
+ | `whole` | Context: the whole text. A hit drops every match, so the text is **excluded**. |
62
+ | `input` | Applies to `'popup'` or `'page'` text only |
63
+ | `appliesTo` | Applies to these detect patterns only |
64
+
65
+ Whole-text negatives with `input: 'popup'` are the popup exclusions:
66
+
67
+ - **`age-gate-popup`:** age wording, unless a cookie choice or the notice's own control is present and no leave or "I am under 18" button is. A bare "Accept all" doesn't count as a cookie choice, since it can be the gate's own confirmation.
68
+ - **`legal-agreement`:** license and terms clauses that cookie notices don't contain.
69
+
70
+ `excludedBy(text, input)` lists the whole-text negatives that hit a text, whether or not any detect pattern matches it. It's useful for tests and for explaining a result.
71
+
72
+ Page text has its own age-gate negative (`age-gate`), tested on a few lines around each match. A page can show an age statement and a real cookie banner at once.
73
+
74
+ ## Adding a pattern or negative
75
+
76
+ - **A detect pattern:** add it to `DETECT_PATTERNS`, run `npm run build-heuristic-literals`, and add a test with an example text and a near-miss that must not match.
77
+ - **A negative:** prefer narrow `appliesTo` and a short context. Add a test that drops the false positive and keeps a real notice with the same wording.
78
+ - **Compatibility:** don't use RegExp lookbehind in `lib/`, because some supported engines lack it (ESLint rejects it). Without the `u` flag, `\b` doesn't treat accented letters as word characters, so don't put `\b` next to one.
@@ -0,0 +1,62 @@
1
+ # Heuristic detection prefilter
2
+
3
+ `checkHeuristicPatterns` and `hasHeuristicPatterns` (`lib/heuristic-detect.ts`) match a text against the detect patterns in `DETECT_PATTERNS` (`lib/heuristic-patterns.ts`). There are a few hundred of them, and a whole page's text can be long, so running every regex on every page costs time. Most patterns cannot match on a given page, and the prefilter skips those cheaply without changing any result. See [heuristic-detection.md](heuristic-detection.md) for the whole matching flow.
4
+
5
+ ## How it works
6
+
7
+ Each detect pattern gets a set of **required literals**: lowercase strings such that *every* match of the pattern contains at least one of them. Some examples:
8
+
9
+ | Pattern | Required literals |
10
+ |---|---|
11
+ | `/accept all/gi` | `accept all` |
12
+ | `/\b(?:our\|unseren) \d{2,4} (?:partners\|partnern)\b/gi` | `partners`, `partnern` |
13
+ | `/\bcookies? zum einsatz\b\|\beinsatz von cookies\b/gi` | ` zum einsatz`, `einsatz von cookies` |
14
+ | `/by continuing\|\bab\b/gi` | none: `ab` is too short to be useful |
15
+
16
+ Detecting on a text works like this:
17
+
18
+ 1. The text is lowercased, and a single regex finds which literals it contains, in one pass (the **literal index**, below).
19
+ 2. A pattern that has literals is skipped when none of them are in that set. If a pattern had matched, the text would contain one of its literals, so skipping it can't change the result.
20
+ 3. A pattern with no literals is always run.
21
+
22
+ ## Build time and run time
23
+
24
+ ```text
25
+ DETECT_PATTERNS ──(npm run build-heuristic-literals)──> lib/heuristic-literals.ts ──> checkHeuristicPatterns
26
+ scripts/required-literals.ts DETECT_PATTERN_LITERALS lib/heuristic-prefilter.ts
27
+ (parses each regex source) (literal index at run time)
28
+ ```
29
+
30
+ - **`scripts/required-literals.ts`** (build time only) works out a pattern's literals from its regex source. It is not bundled into the library, so pages never parse pattern sources.
31
+ - **`scripts/build-heuristic-literals.ts`** runs it over `DETECT_PATTERNS` and writes **`lib/heuristic-literals.ts`**. Its `DETECT_PATTERN_LITERALS` is an array in `DETECT_PATTERNS` order: entry `i` holds pattern `i`'s literals, so the bundle doesn't repeat the pattern sources as keys.
32
+ - **`lib/heuristic-prefilter.ts`** (run time) builds the literal index over all the literals, once per page, and reports which literals a text contains.
33
+ - **`lib/heuristic-detect.ts`** pairs each built-in regex with its table entry.
34
+
35
+ A **custom pattern list**, passed to `checkHeuristicPatterns` or `hasHeuristicPatterns` as the `patterns` option, uses the same table. Built-in regexes in it (the same objects, such as those imported from `heuristic-patterns.ts`) keep their literals, and other patterns get none, so they are always run. Results are therefore the same for any list. Only custom patterns miss the speed-up.
36
+
37
+ ## Changing detect patterns
38
+
39
+ After adding, changing or removing a pattern in `DETECT_PATTERNS`, regenerate the table and commit it:
40
+
41
+ ```bash
42
+ npm run build-heuristic-literals
43
+ ```
44
+
45
+ A unit test in `tests-wtr/heuristics/heuristics-utils.test.ts` fails while the table is stale. A table whose length differs from `DETECT_PATTERNS` is ignored, so an added or removed pattern can't shift literals onto the wrong patterns: no pattern is skipped until the table is regenerated. An in-place edit of a pattern keeps the length, so it relies on that test.
46
+
47
+ ## How the literals are worked out
48
+
49
+ The literals must be **sound**: a literal that some match lacks would make the prefilter skip a pattern that matches. `requiredLiterals` therefore takes only what the regex source guarantees, and returns none when it can't tell:
50
+
51
+ - **Top-level alternation (`a|b`):** each alternative must have literals. The result is their union. If any alternative has none, the pattern gets none.
52
+ - **Literal runs:** consecutive literal characters form a candidate. Escaped punctuation such as `\/` or `\.` counts as a literal.
53
+ - **What ends a run:** a character class, `.`, `^`, `$`, a class escape (`\s`, `\w`, `\d`, `\b`…) or a group.
54
+ - **Quantifiers:** a character under `?`, `*` or `{0,…}` is left out. A quantified character ends the run after it.
55
+ - **Groups:** a required, non-lookaround group whose alternatives are all plain literals of 3+ characters, such as `(?:partners|partnern)`, is a candidate of its own. Other groups add nothing.
56
+ - **Choosing one candidate:** among the candidates whose literals are all at least 3 characters (ignoring spaces), it takes the one whose shortest literal is longest. It needs that shortest literal to be at least 4 characters, since short literals are common enough to make the check cost more than it saves.
57
+
58
+ Literals are lowercased, and the text is lowercased before the check, so the `i` flag is handled. A case-sensitive pattern is checked a little more loosely than it matches, which is still sound.
59
+
60
+ ## The literal index
61
+
62
+ The literal index is one zero-width lookahead over all literals, longest first: `(?=(literal1|literal2|…))`, run with `matchAll`. At each position it reports the longest literal starting there. Every shorter literal that starts at the same position is a prefix of it, so the index also marks those prefixes as present. Which literals imply which is worked out only for the literals a page actually contains.
package/eslint.config.mjs CHANGED
@@ -8,7 +8,7 @@ const c = tseslint.config(
8
8
  ...ddgConfig,
9
9
 
10
10
  {
11
- ignores: ['dist/**/*', '.agents/**/*'],
11
+ ignores: ['dist/**/*', '.agents/**/*', 'lib/heuristic-literals.ts'],
12
12
  },
13
13
 
14
14
  {
@@ -58,6 +58,21 @@ const c = tseslint.config(
58
58
  },
59
59
  },
60
60
 
61
+ {
62
+ // the library runs on engines without RegExp lookbehind (Safari before 16.4), where it fails to load
63
+ files: ['lib/**/*.ts'],
64
+ rules: {
65
+ 'no-restricted-syntax': [
66
+ 'error',
67
+ {
68
+ selector:
69
+ 'Literal[regex.pattern=/\\(\\?<[=!]/], Literal[value=/\\(\\?<[=!]/], TemplateElement[value.raw=/\\(\\?<[=!]/]',
70
+ message: 'RegExp lookbehind is not supported by all target browsers.',
71
+ },
72
+ ],
73
+ },
74
+ },
75
+
61
76
  {
62
77
  files: ['tests/**/*', 'tests-wtr/**/*'],
63
78
  languageOptions: {
@@ -17,15 +17,16 @@ export default class Evidon extends AutoConsentCMPBase {
17
17
  }
18
18
 
19
19
  async detectCmp() {
20
- return this.elementExists('#_evidon_banner');
20
+ return this.elementExists('#_evidon_banner, #_evidon-barrier-wrapper');
21
21
  }
22
22
 
23
23
  async detectPopup() {
24
- return this.elementVisible('#_evidon_banner', 'any');
24
+ return this.elementVisible('#_evidon_banner, #_evidon-barrier-wrapper #_evidon-banner', 'any');
25
25
  }
26
26
 
27
27
  async optOut() {
28
- if (await this.click('#_evidon-decline-button')) {
28
+ // some sites put a custom reject link into the banner text instead of a decline button
29
+ if (await this.click('#_evidon-decline-button, #_evidon-barrier-declinebutton, #_evidon_banner #RejectLink')) {
29
30
  return true;
30
31
  }
31
32
 
@@ -40,6 +41,6 @@ export default class Evidon extends AutoConsentCMPBase {
40
41
  }
41
42
 
42
43
  async optIn() {
43
- return await this.click('#_evidon-accept-button');
44
+ return await this.click('#_evidon-accept-button, #_evidon-banner-acceptbutton');
44
45
  }
45
46
  }
@@ -1,14 +1,9 @@
1
- import { RunContext } from '../rules';
2
1
  import { isElementVisible } from '../utils';
3
2
  import AutoConsentCMPBase from './base';
4
3
 
5
4
  export default class Tiktok extends AutoConsentCMPBase {
6
5
  name = 'tiktok.com';
7
6
 
8
- runContext: RunContext = {
9
- urlPattern: 'tiktok',
10
- };
11
-
12
7
  get hasSelfTest(): boolean {
13
8
  return true;
14
9
  }
@@ -280,6 +280,8 @@ export const snippets = {
280
280
  EVAL_TEALIUM_2: () => utag.gdpr.setConsentValue(true) || true,
281
281
  EVAL_TEALIUM_3: () => utag.gdpr.getConsentState() !== 1,
282
282
  EVAL_TEALIUM_DONOTSELL_CHECK: () => utag.gdpr.dns?.getDnsState() !== 1,
283
+ // 0 means no stored decision; otherwise the user reopened the prompt themselves
284
+ EVAL_TEALIUM_NO_DECISION: () => utag.gdpr.getConsentState() === 0,
283
285
  EVAL_TESTCMP_STEP: () => !!document.querySelector('#reject-all'),
284
286
  EVAL_TESTCMP_0: () => window.results.results[0] === 'button_clicked',
285
287
  EVAL_TESTCMP_COSMETIC_0: () => window.results.results[0] === 'banner_hidden',
@@ -296,6 +298,7 @@ export const snippets = {
296
298
  JSON.parse(localStorage.getItem('usercentrics')).consents.every((c) => c.isEssential || !c.consentStatus),
297
299
  EVAL_WAITROSE_0: () => Array.from(document.querySelectorAll('label[id$=cookies-deny-label]')).forEach((e) => e.click()) || true,
298
300
  EVAL_WBD_LTP_CLOSE: () => document.querySelector('dialog#ltp-dialog').close() || true,
301
+ EVAL_ZOHO_TEST: () => localStorage.getItem('zglobal_Acookie_optOut') === '3',
299
302
  };
300
303
 
301
304
  export function getFunctionBody(snippetFunc: () => any) {
@@ -1,17 +1,19 @@
1
1
  /**
2
2
  * Text-only heuristic classification: popup text and button labels in, classifications out.
3
3
  * Must not depend on DOM APIs, so that it can be used from Node (e.g. by tracker-radar-collector).
4
+ * This is the `./heuristics` package entry: it also exports the detect patterns, context negatives and the matching
5
+ * functions (heuristic-patterns.ts, heuristic-negatives.ts, heuristic-detect.ts).
4
6
  */
5
7
  import {
6
8
  ACCEPT_PATTERNS,
7
9
  ACKNOWLEDGE_PATTERNS,
8
10
  BUTTON_NEVER_MATCH_PATTERNS,
9
- DETECT_NEVER_MATCH_PATTERNS,
10
- DETECT_PATTERNS,
11
11
  REJECT_PATTERNS,
12
12
  SETTINGS_PATTERNS,
13
13
  } from './heuristic-patterns';
14
14
  export * from './heuristic-patterns';
15
+ export * from './heuristic-negatives';
16
+ export * from './heuristic-detect';
15
17
 
16
18
  export type ButtonRegexClassification = 'reject' | 'settings' | 'accept' | 'acknowledge' | 'other';
17
19
  export type PopupClassification = 'none' | 'reject' | 'tier1' | 'tier2';
@@ -21,49 +23,12 @@ export type ClassifiableButton = {
21
23
  regexClassification?: ButtonRegexClassification;
22
24
  };
23
25
 
24
- const TEXT_LIMIT = 100000;
25
-
26
- export function checkHeuristicPatterns(allText: string, detectPatterns = DETECT_PATTERNS) {
27
- allText = allText.slice(0, TEXT_LIMIT);
28
- const patterns = [];
29
- const snippets = [];
30
-
31
- for (const p of detectPatterns) {
32
- const matches = allText?.match(p);
33
- if (matches) {
34
- patterns.push(p.toString());
35
- // When a non-global regex has capture groups, `String.prototype.match`
36
- // returns undefined entries for optional groups that did not match.
37
- for (const m of matches) {
38
- if (typeof m === 'string') {
39
- snippets.push(m.substring(0, 200));
40
- }
41
- }
42
- }
43
- }
44
- return { patterns, snippets };
45
- }
46
-
47
- // same result as checking checkHeuristicPatterns() for patterns, but stops at the first match
48
- export function hasHeuristicPatterns(allText: string, detectPatterns = DETECT_PATTERNS): boolean {
49
- const text = allText.slice(0, TEXT_LIMIT);
50
- return detectPatterns.some((p) => text.search(p) !== -1);
51
- }
52
-
53
26
  export function classifyButtons(buttons: ClassifiableButton[]) {
54
27
  for (const button of buttons) {
55
28
  button.regexClassification = classifyButtonTextRegex(button.text);
56
29
  }
57
30
  }
58
31
 
59
- export function isExcludedPopup(popupText: string, excludePatterns = DETECT_NEVER_MATCH_PATTERNS): boolean {
60
- if (!popupText) {
61
- return false;
62
- }
63
- const truncated = popupText.slice(0, TEXT_LIMIT);
64
- return excludePatterns.some((p) => p.test(truncated));
65
- }
66
-
67
32
  export function classifyPopup(buttons: ClassifiableButton[]): PopupClassification {
68
33
  const { reject, settings, accept, acknowledge } = buttons.reduce(
69
34
  (acc, button) => {