@duckduckgo/autoconsent 8.0.0 → 8.2.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.
@@ -1,5 +1,4 @@
1
1
  import { click, elementExists, wait } from '../rule-executors';
2
- import { waitFor } from '../utils';
3
2
  import AutoConsentCMPBase from './base';
4
3
 
5
4
  export default class Cookiebot extends AutoConsentCMPBase {
@@ -23,9 +22,7 @@ export default class Cookiebot extends AutoConsentCMPBase {
23
22
  }
24
23
 
25
24
  async detectPopup() {
26
- return await waitFor(() => {
27
- return this.mainWorldEval('EVAL_COOKIEBOT_2')
28
- }, 10, 500);
25
+ return this.mainWorldEval('EVAL_COOKIEBOT_2');
29
26
  }
30
27
 
31
28
  async optOut() {
package/lib/cmps/klaro.ts CHANGED
@@ -36,7 +36,7 @@ export default class Klaro extends AutoConsentCMPBase {
36
36
  }
37
37
 
38
38
  if (!this.settingsOpen) {
39
- click('.klaro .cn-learn-more');
39
+ click('.klaro .cn-learn-more,.klaro .cm-button-manage');
40
40
  await waitForElement('.klaro > .cookie-modal', 2000);
41
41
  this.settingsOpen = true;
42
42
  }
@@ -45,8 +45,8 @@ export default class Klaro extends AutoConsentCMPBase {
45
45
  return true;
46
46
  }
47
47
 
48
- click('.cm-purpose:not(.cm-toggle-all) > input:not(.half-checked)', true);
49
- return click('.cm-btn-accept');
48
+ 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);
49
+ return click('.cm-btn-accept,.cm-button');
50
50
  }
51
51
 
52
52
  async optIn() {
@@ -14,7 +14,22 @@ export const snippets = {
14
14
  EVAL_COOKIEBOT_3: () => window.Cookiebot.withdraw() || true,
15
15
  EVAL_COOKIEBOT_4: () => window.Cookiebot.hide() || true,
16
16
  EVAL_COOKIEBOT_5: () => window.Cookiebot.declined === true,
17
- EVAL_KLARO_1: () => klaro.getManager().config.services.every(c => c.required || !klaro.getManager().consents[c.name]),
17
+ EVAL_KLARO_1: () => {
18
+ const config = globalThis.klaroConfig || (globalThis.klaro?.getManager && globalThis.klaro.getManager().config)
19
+ if (!config) {
20
+ // with no klaro globals, we can't test on this page
21
+ return true
22
+ }
23
+ const optionalServices = (config.services || config.apps).filter(s => !s.required).map(s => s.name)
24
+ if (klaro && klaro.getManager) {
25
+ const manager = klaro.getManager()
26
+ return optionalServices.every(name => !manager.consents[name])
27
+ } else if (klaroConfig && klaroConfig.storageMethod === 'cookie') {
28
+ const cookieName = klaroConfig.cookieName || klaroConfig.storageName;
29
+ const consents = JSON.parse(decodeURIComponent(document.cookie.split(';').find(c => c.trim().startsWith(cookieName)).split('=')[1]))
30
+ return Object.keys(consents).filter(k => optionalServices.includes(k)).every(k => consents[k] === false)
31
+ }
32
+ },
18
33
  EVAL_ONETRUST_1: () => window.OnetrustActiveGroups.split(',').filter(s => s.length > 0).length <= 1,
19
34
  EVAL_TRUSTARC_TOP: () => window && window.truste && window.truste.eu.bindMap.prefCookie === '0',
20
35
 
@@ -57,6 +72,7 @@ export const snippets = {
57
72
  EVAL_EZOIC_0: () => ezCMP.handleAcceptAllClick(),
58
73
  EVAL_EZOIC_1: () => !!document.cookie.match(/ezCMPCookieConsent=[^;]+\|2=0\|3=0\|4=0/),
59
74
  EVAL_GOOGLE_0: () => !!document.cookie.match(/SOCS=CAE/),
75
+ EVAL_HEMA_TEST_0: () => document.cookie.includes('cookies_rejected=1'),
60
76
  EVAL_IUBENDA_0: () => document.querySelectorAll('.purposes-item input[type=checkbox]:not([disabled])').forEach(x => {if(x.checked) x.click()}) || true,
61
77
  EVAL_IUBENDA_1: () => !!document.cookie.match(/_iub_cs-\d+=/),
62
78
  EVAL_IWINK_TEST: () => document.cookie.includes('cookie_permission_granted=no'),
@@ -111,5 +127,5 @@ export const snippets = {
111
127
 
112
128
  export function getFunctionBody(snippetFunc: () => any) {
113
129
  const snippetStr = snippetFunc.toString();
114
- return snippetStr.substring(snippetStr.indexOf("=>") + 2);
130
+ return `(${snippetStr})()`
115
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckduckgo/autoconsent",
3
- "version": "8.0.0",
3
+ "version": "8.2.0",
4
4
  "description": "",
5
5
  "main": "dist/autoconsent.cjs.js",
6
6
  "module": "dist/autoconsent.esm.js",
@@ -18,6 +18,7 @@
18
18
  "test:firefox": "playwright test --project firefox",
19
19
  "test:chrome": "playwright test --project chrome",
20
20
  "test:lib": "playwright test tests/rule-executors.spec.ts",
21
+ "test:sample": "playwright test tests/_sample-test.spec.ts --project webkit",
21
22
  "fetch-fanboy-list": "wget https://www.fanboy.co.nz/fanboy-cookiemonster.txt",
22
23
  "fetch-site-list": "curl https://s3.amazonaws.com/cdn.cliqz.com/re-consent/supported_sites.txt > sites.txt",
23
24
  "build-rules": "node rules/build.mjs",
@@ -7,6 +7,7 @@ import { enableLogs } from "../lib/config";
7
7
  import { AutoAction } from "../lib/types";
8
8
 
9
9
  const testRegion = (process.env.REGION || "NA").trim();
10
+ test.describe.configure({ mode: 'parallel' });
10
11
 
11
12
  type TestOptions = {
12
13
  testOptOut: boolean;
@@ -15,7 +15,6 @@ const config: PlaywrightTestConfig = {
15
15
  use: {
16
16
  ...devices['Desktop Safari'],
17
17
  proxy,
18
- screenshot: 'only-on-failure',
19
18
  userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15',
20
19
  },
21
20
  },
@@ -24,7 +23,6 @@ const config: PlaywrightTestConfig = {
24
23
  use: {
25
24
  ...devices['iPhone SE'],
26
25
  proxy,
27
- screenshot: 'only-on-failure',
28
26
  userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1',
29
27
  },
30
28
  },
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "hema",
3
+ "prehideSelectors": [".cookie-modal"],
4
+ "detectCmp": [
5
+ { "visible": ".cookie-modal .cookie-accept-btn" }
6
+ ],
7
+ "detectPopup": [
8
+ { "visible": ".cookie-modal .cookie-accept-btn" }
9
+ ],
10
+ "optIn": [
11
+ { "waitForThenClick": ".cookie-modal .cookie-accept-btn" }
12
+ ],
13
+ "optOut": [
14
+ { "waitForThenClick": ".cookie-modal .js-cookie-reject-btn" }
15
+ ],
16
+ "test": [
17
+ {
18
+ "eval": "EVAL_HEMA_TEST_0"
19
+ }
20
+ ]
21
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "ing.de",
3
+ "runContext": {
4
+ "urlPattern": "^https://www\\.ing\\.de/"
5
+ },
6
+ "cosmetic": true,
7
+ "prehideSelectors": ["div[slot=\"backdrop\"]"],
8
+ "detectCmp": [{ "exists": "[data-tag-name=\"ing-cc-dialog-frame\"]" }],
9
+ "detectPopup": [{ "visible": "[data-tag-name=\"ing-cc-dialog-frame\"]" }],
10
+ "optIn": [{ "click": [
11
+ "[data-tag-name=\"ing-cc-dialog-level0\"]",
12
+ "[data-tag-name=\"ing-cc-button\"][class*=\"accept\"]"
13
+ ] }],
14
+ "optOut": [{ "click": [
15
+ "[data-tag-name=\"ing-cc-dialog-level0\"]",
16
+ "[data-tag-name=\"ing-cc-button\"][class*=\"more\"]"
17
+ ] }]
18
+ }
package/rules/rules.json CHANGED
@@ -2382,6 +2382,37 @@
2382
2382
  }
2383
2383
  ]
2384
2384
  },
2385
+ {
2386
+ "name": "hema",
2387
+ "prehideSelectors": [
2388
+ ".cookie-modal"
2389
+ ],
2390
+ "detectCmp": [
2391
+ {
2392
+ "visible": ".cookie-modal .cookie-accept-btn"
2393
+ }
2394
+ ],
2395
+ "detectPopup": [
2396
+ {
2397
+ "visible": ".cookie-modal .cookie-accept-btn"
2398
+ }
2399
+ ],
2400
+ "optIn": [
2401
+ {
2402
+ "waitForThenClick": ".cookie-modal .cookie-accept-btn"
2403
+ }
2404
+ ],
2405
+ "optOut": [
2406
+ {
2407
+ "waitForThenClick": ".cookie-modal .js-cookie-reject-btn"
2408
+ }
2409
+ ],
2410
+ "test": [
2411
+ {
2412
+ "eval": "EVAL_HEMA_TEST_0"
2413
+ }
2414
+ ]
2415
+ },
2385
2416
  {
2386
2417
  "name": "hl.co.uk",
2387
2418
  "prehideSelectors": [
@@ -2479,6 +2510,42 @@
2479
2510
  }
2480
2511
  ]
2481
2512
  },
2513
+ {
2514
+ "name": "ing.de",
2515
+ "runContext": {
2516
+ "urlPattern": "^https://www\\.ing\\.de/"
2517
+ },
2518
+ "cosmetic": true,
2519
+ "prehideSelectors": [
2520
+ "div[slot=\"backdrop\"]"
2521
+ ],
2522
+ "detectCmp": [
2523
+ {
2524
+ "exists": "[data-tag-name=\"ing-cc-dialog-frame\"]"
2525
+ }
2526
+ ],
2527
+ "detectPopup": [
2528
+ {
2529
+ "visible": "[data-tag-name=\"ing-cc-dialog-frame\"]"
2530
+ }
2531
+ ],
2532
+ "optIn": [
2533
+ {
2534
+ "click": [
2535
+ "[data-tag-name=\"ing-cc-dialog-level0\"]",
2536
+ "[data-tag-name=\"ing-cc-button\"][class*=\"accept\"]"
2537
+ ]
2538
+ }
2539
+ ],
2540
+ "optOut": [
2541
+ {
2542
+ "click": [
2543
+ "[data-tag-name=\"ing-cc-dialog-level0\"]",
2544
+ "[data-tag-name=\"ing-cc-button\"][class*=\"more\"]"
2545
+ ]
2546
+ }
2547
+ ]
2548
+ },
2482
2549
  {
2483
2550
  "name": "ionos.de",
2484
2551
  "prehideSelectors": [
@@ -0,0 +1,16 @@
1
+ import coverageData from "../data/coverage.json";
2
+ import generateCMPTests from "../playwright/runner";
3
+
4
+ const region = (process.env.REGION || "US").trim();
5
+ const nSites = parseInt(process.env.NSITES || '1')
6
+
7
+ Object.keys(coverageData).forEach((name) => {
8
+ if (!coverageData[name][region]) {
9
+ // no coverage in this region
10
+ return;
11
+ }
12
+ const siteList = coverageData[name][region].exampleSites.slice(0, nSites);
13
+ generateCMPTests(name, siteList, {
14
+ testOptIn: false,
15
+ });
16
+ });
@@ -0,0 +1,7 @@
1
+ import generateCMPTests from "../playwright/runner";
2
+
3
+ generateCMPTests('hema', [
4
+ 'https://hema.nl/',
5
+ 'https://www.hema.com/de-de',
6
+ ], {
7
+ });
@@ -5,5 +5,6 @@ generateCMPTests('Klaro', [
5
5
  'https://www.zeitraum-moebel.de/',
6
6
  'https://repisalud.isciii.es/',
7
7
  'https://www.innogames.com/',
8
+ 'https://www.lebenslauf.de/',
8
9
  // 'https://dspace.library.stonybrook.edu', // polyfills Promise so playwright doesn't work
9
10
  ]);