@duckduckgo/autoconsent 8.1.0 → 9.0.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 (40) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/build.sh +1 -0
  3. package/dist/addon-firefox/background.bundle.js +60 -43
  4. package/dist/addon-firefox/content.bundle.js +484 -382
  5. package/dist/addon-firefox/manifest.json +1 -1
  6. package/dist/addon-mv3/background.bundle.js +60 -43
  7. package/dist/addon-mv3/content.bundle.js +484 -382
  8. package/dist/addon-mv3/manifest.json +1 -1
  9. package/dist/addon-mv3/popup.bundle.js +71 -33
  10. package/dist/addon-mv3/popup.html +28 -0
  11. package/dist/autoconsent.cjs.js +484 -382
  12. package/dist/autoconsent.esm.js +484 -382
  13. package/dist/autoconsent.playwright.js +1 -1
  14. package/dist/autoconsent.unit.js +10370 -0
  15. package/lib/cmps/airbnb.ts +5 -6
  16. package/lib/cmps/base.ts +97 -41
  17. package/lib/cmps/consentmanager.ts +13 -14
  18. package/lib/cmps/conversant.ts +8 -9
  19. package/lib/cmps/cookiebot.ts +8 -9
  20. package/lib/cmps/evidon.ts +7 -8
  21. package/lib/cmps/klaro.ts +13 -14
  22. package/lib/cmps/onetrust.ts +15 -16
  23. package/lib/cmps/sourcepoint-frame.ts +25 -26
  24. package/lib/cmps/tiktok.ts +7 -7
  25. package/lib/cmps/trustarc-frame.ts +27 -28
  26. package/lib/cmps/trustarc-top.ts +5 -6
  27. package/lib/cmps/uniconsent.ts +9 -10
  28. package/lib/dom-actions.ts +145 -0
  29. package/lib/eval-snippets.ts +17 -2
  30. package/lib/types.ts +24 -1
  31. package/lib/utils.ts +32 -1
  32. package/lib/web.ts +46 -34
  33. package/package.json +4 -4
  34. package/playwright/runner.ts +11 -3
  35. package/playwright/unit.ts +15 -0
  36. package/readme.md +1 -1
  37. package/tests/{rule-executors.spec.ts → dom-actions.spec.ts} +20 -21
  38. package/tests/klaro.spec.ts +1 -0
  39. package/lib/config.ts +0 -2
  40. package/lib/rule-executors.ts +0 -147
package/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ # v9.0.0 (Thu Jan 11 2024)
2
+
3
+ #### 💥 Breaking Change
4
+
5
+ - Configurable logs [#332](https://github.com/duckduckgo/autoconsent/pull/332) ([@muodov](https://github.com/muodov))
6
+
7
+ #### 🔩 Dependency Updates
8
+
9
+ - Bump the dev-dependencies group with 3 updates [#335](https://github.com/duckduckgo/autoconsent/pull/335) ([@dependabot[bot]](https://github.com/dependabot[bot]))
10
+
11
+ #### Authors: 2
12
+
13
+ - [@dependabot[bot]](https://github.com/dependabot[bot])
14
+ - Maxim Tsoy ([@muodov](https://github.com/muodov))
15
+
16
+ ---
17
+
18
+ # v8.2.0 (Thu Jan 11 2024)
19
+
20
+ #### 🚀 Enhancement
21
+
22
+ - Klaro: fix toggle selectors [#339](https://github.com/duckduckgo/autoconsent/pull/339) ([@sammacbeth](https://github.com/sammacbeth))
23
+
24
+ #### Authors: 1
25
+
26
+ - Sam Macbeth ([@sammacbeth](https://github.com/sammacbeth))
27
+
28
+ ---
29
+
1
30
  # v8.1.0 (Wed Jan 10 2024)
2
31
 
3
32
  #### 🚀 Enhancement
package/build.sh CHANGED
@@ -4,6 +4,7 @@ set -ex
4
4
  ESBUILD="node_modules/.bin/esbuild --bundle"
5
5
 
6
6
  $ESBUILD --format=iife --target=es2021 --minify playwright/content.ts --outfile=dist/autoconsent.playwright.js
7
+ $ESBUILD --format=iife --target=es2021 playwright/unit.ts --outfile=dist/autoconsent.unit.js
7
8
  $ESBUILD --format=esm --target=es2021 lib/web.ts --outfile=dist/autoconsent.esm.js
8
9
  $ESBUILD --format=cjs --target=es2021 --platform=node lib/web.ts --outfile=dist/autoconsent.cjs.js
9
10
 
@@ -1,7 +1,4 @@
1
1
  (() => {
2
- // lib/config.ts
3
- var enableLogs = false;
4
-
5
2
  // lib/eval-snippets.ts
6
3
  var snippets = {
7
4
  // code-based rules
@@ -16,7 +13,21 @@
16
13
  EVAL_COOKIEBOT_3: () => window.Cookiebot.withdraw() || true,
17
14
  EVAL_COOKIEBOT_4: () => window.Cookiebot.hide() || true,
18
15
  EVAL_COOKIEBOT_5: () => window.Cookiebot.declined === true,
19
- EVAL_KLARO_1: () => klaro.getManager().config.services.every((c) => c.required || !klaro.getManager().consents[c.name]),
16
+ EVAL_KLARO_1: () => {
17
+ const config = globalThis.klaroConfig || globalThis.klaro?.getManager && globalThis.klaro.getManager().config;
18
+ if (!config) {
19
+ return true;
20
+ }
21
+ const optionalServices = (config.services || config.apps).filter((s) => !s.required).map((s) => s.name);
22
+ if (klaro && klaro.getManager) {
23
+ const manager = klaro.getManager();
24
+ return optionalServices.every((name) => !manager.consents[name]);
25
+ } else if (klaroConfig && klaroConfig.storageMethod === "cookie") {
26
+ const cookieName = klaroConfig.cookieName || klaroConfig.storageName;
27
+ const consents = JSON.parse(decodeURIComponent(document.cookie.split(";").find((c) => c.trim().startsWith(cookieName)).split("=")[1]));
28
+ return Object.keys(consents).filter((k) => optionalServices.includes(k)).every((k) => consents[k] === false);
29
+ }
30
+ },
20
31
  EVAL_ONETRUST_1: () => window.OnetrustActiveGroups.split(",").filter((s) => s.length > 0).length <= 1,
21
32
  EVAL_TRUSTARC_TOP: () => window && window.truste && window.truste.eu.bindMap.prefCookie === "0",
22
33
  // declarative rules
@@ -149,6 +160,35 @@
149
160
  return chrome.storage.local.remove(key);
150
161
  }
151
162
 
163
+ // lib/utils.ts
164
+ function normalizeConfig(providedConfig) {
165
+ const defaultConfig = {
166
+ enabled: true,
167
+ autoAction: "optOut",
168
+ // if falsy, the extension will wait for an explicit user signal before opting in/out
169
+ disabledCmps: [],
170
+ enablePrehide: true,
171
+ enableCosmeticRules: true,
172
+ detectRetries: 20,
173
+ isMainWorld: false,
174
+ prehideTimeout: 2e3,
175
+ logs: {
176
+ lifecycle: false,
177
+ rulesteps: false,
178
+ evals: false,
179
+ errors: true,
180
+ messages: false
181
+ }
182
+ };
183
+ const updatedConfig = structuredClone(defaultConfig);
184
+ for (const key of Object.keys(defaultConfig)) {
185
+ if (typeof providedConfig[key] !== "undefined") {
186
+ updatedConfig[key] = providedConfig[key];
187
+ }
188
+ }
189
+ return updatedConfig;
190
+ }
191
+
152
192
  // addon/utils.ts
153
193
  async function showOptOutStatus(tabId, status, cmp = "") {
154
194
  let title = "";
@@ -172,7 +212,7 @@
172
212
  title = `Click to opt out (${cmp})`;
173
213
  icon = "icons/cookie.png";
174
214
  }
175
- enableLogs && console.log("Setting action state to", status);
215
+ console.log("Setting action state to", status);
176
216
  const action = chrome.action || chrome.pageAction;
177
217
  if (chrome.pageAction) {
178
218
  chrome.pageAction.show(tabId);
@@ -187,36 +227,13 @@
187
227
  });
188
228
  }
189
229
  async function initConfig() {
190
- const storedConfig = await storageGet("config");
191
- enableLogs && console.log("storedConfig", storedConfig);
192
- const defaultConfig = {
193
- enabled: true,
194
- autoAction: "optOut",
195
- // if falsy, the extension will wait for an explicit user signal before opting in/out
196
- disabledCmps: [],
197
- enablePrehide: true,
198
- enableCosmeticRules: true,
199
- detectRetries: 20,
200
- isMainWorld: false,
201
- prehideTimeout: 2e3
202
- };
203
- if (!storedConfig) {
204
- enableLogs && console.log("new config", defaultConfig);
205
- await storageSet({
206
- config: defaultConfig
207
- });
208
- } else {
209
- const updatedConfig = structuredClone(defaultConfig);
210
- for (const key of Object.keys(defaultConfig)) {
211
- if (typeof storedConfig[key] !== "undefined") {
212
- updatedConfig[key] = storedConfig[key];
213
- }
214
- }
215
- enableLogs && console.log("updated config", updatedConfig);
216
- await storageSet({
217
- config: updatedConfig
218
- });
219
- }
230
+ const storedConfig = await storageGet("config") || {};
231
+ console.log("storedConfig", storedConfig);
232
+ const updatedConfig = normalizeConfig(storedConfig);
233
+ console.log("updated config", updatedConfig);
234
+ await storageSet({
235
+ config: updatedConfig
236
+ });
220
237
  }
221
238
 
222
239
  // addon/background.ts
@@ -274,14 +291,15 @@
274
291
  async (msg, sender) => {
275
292
  const tabId = sender.tab.id;
276
293
  const frameId = sender.frameId;
277
- if (enableLogs) {
294
+ const autoconsentConfig = await storageGet("config");
295
+ const logsConfig = autoconsentConfig.logs;
296
+ if (logsConfig.lifecycle) {
297
+ console.log("got config", autoconsentConfig);
278
298
  console.groupCollapsed(`${msg.type} from ${sender.origin || sender.url}`);
279
299
  console.log(msg, sender);
280
300
  console.groupEnd();
281
301
  }
282
302
  const rules = await storageGet("rules");
283
- const autoconsentConfig = await storageGet("config");
284
- enableLogs && console.log("got config", autoconsentConfig);
285
303
  switch (msg.type) {
286
304
  case "init":
287
305
  if (frameId === 0) {
@@ -297,7 +315,7 @@
297
315
  break;
298
316
  case "eval":
299
317
  evalInTab(tabId, frameId, msg.code, msg.snippetId).then(([result]) => {
300
- if (enableLogs) {
318
+ if (logsConfig.evals) {
301
319
  console.groupCollapsed(`eval result for ${sender.origin || sender.url}`);
302
320
  console.log(msg.code, result.result);
303
321
  console.groupEnd();
@@ -329,7 +347,7 @@
329
347
  }
330
348
  break;
331
349
  case "selfTestResult":
332
- enableLogs && console.log(`Self-test result ${msg.result}`);
350
+ logsConfig.lifecycle && console.log(`Self-test result ${msg.result}`);
333
351
  if (msg.result) {
334
352
  await showOptOutStatus(tabId, "verified", msg.cmp);
335
353
  }
@@ -339,7 +357,7 @@
339
357
  const selfTestKey = `selfTest${tabId}`;
340
358
  const selfTestFrameId = (await chrome.storage.local.get(selfTestKey))?.[selfTestKey];
341
359
  if (typeof selfTestFrameId === "number") {
342
- enableLogs && console.log(`Requesting self-test in ${selfTestFrameId}`);
360
+ logsConfig.lifecycle && console.log(`Requesting self-test in ${selfTestFrameId}`);
343
361
  storageRemove(selfTestKey);
344
362
  chrome.tabs.sendMessage(tabId, {
345
363
  type: "selfTest"
@@ -347,7 +365,7 @@
347
365
  frameId: selfTestFrameId
348
366
  });
349
367
  } else {
350
- enableLogs && console.log(`No self-test scheduled`);
368
+ logsConfig.lifecycle && console.log(`No self-test scheduled`);
351
369
  }
352
370
  break;
353
371
  }
@@ -374,7 +392,6 @@
374
392
  const frameId = await storageGet(detectedKey);
375
393
  if (typeof frameId === "number") {
376
394
  storageRemove(detectedKey);
377
- enableLogs && console.log("action.onClicked", tabId, frameId);
378
395
  await showOptOutStatus(tabId, "working");
379
396
  chrome.tabs.sendMessage(tabId, {
380
397
  type: "optOut"