@duckduckgo/autoconsent 8.2.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 (38) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/build.sh +1 -0
  3. package/dist/addon-firefox/background.bundle.js +45 -42
  4. package/dist/addon-firefox/content.bundle.js +468 -380
  5. package/dist/addon-firefox/manifest.json +1 -1
  6. package/dist/addon-mv3/background.bundle.js +45 -42
  7. package/dist/addon-mv3/content.bundle.js +468 -380
  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 +468 -380
  12. package/dist/autoconsent.esm.js +468 -380
  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/types.ts +24 -1
  30. package/lib/utils.ts +32 -1
  31. package/lib/web.ts +46 -34
  32. package/package.json +4 -4
  33. package/playwright/runner.ts +11 -3
  34. package/playwright/unit.ts +15 -0
  35. package/readme.md +1 -1
  36. package/tests/{rule-executors.spec.ts → dom-actions.spec.ts} +20 -21
  37. package/lib/config.ts +0 -2
  38. package/lib/rule-executors.ts +0 -147
package/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
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
+
1
18
  # v8.2.0 (Thu Jan 11 2024)
2
19
 
3
20
  #### 🚀 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
@@ -163,6 +160,35 @@
163
160
  return chrome.storage.local.remove(key);
164
161
  }
165
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
+
166
192
  // addon/utils.ts
167
193
  async function showOptOutStatus(tabId, status, cmp = "") {
168
194
  let title = "";
@@ -186,7 +212,7 @@
186
212
  title = `Click to opt out (${cmp})`;
187
213
  icon = "icons/cookie.png";
188
214
  }
189
- enableLogs && console.log("Setting action state to", status);
215
+ console.log("Setting action state to", status);
190
216
  const action = chrome.action || chrome.pageAction;
191
217
  if (chrome.pageAction) {
192
218
  chrome.pageAction.show(tabId);
@@ -201,36 +227,13 @@
201
227
  });
202
228
  }
203
229
  async function initConfig() {
204
- const storedConfig = await storageGet("config");
205
- enableLogs && console.log("storedConfig", storedConfig);
206
- const defaultConfig = {
207
- enabled: true,
208
- autoAction: "optOut",
209
- // if falsy, the extension will wait for an explicit user signal before opting in/out
210
- disabledCmps: [],
211
- enablePrehide: true,
212
- enableCosmeticRules: true,
213
- detectRetries: 20,
214
- isMainWorld: false,
215
- prehideTimeout: 2e3
216
- };
217
- if (!storedConfig) {
218
- enableLogs && console.log("new config", defaultConfig);
219
- await storageSet({
220
- config: defaultConfig
221
- });
222
- } else {
223
- const updatedConfig = structuredClone(defaultConfig);
224
- for (const key of Object.keys(defaultConfig)) {
225
- if (typeof storedConfig[key] !== "undefined") {
226
- updatedConfig[key] = storedConfig[key];
227
- }
228
- }
229
- enableLogs && console.log("updated config", updatedConfig);
230
- await storageSet({
231
- config: updatedConfig
232
- });
233
- }
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
+ });
234
237
  }
235
238
 
236
239
  // addon/background.ts
@@ -288,14 +291,15 @@
288
291
  async (msg, sender) => {
289
292
  const tabId = sender.tab.id;
290
293
  const frameId = sender.frameId;
291
- if (enableLogs) {
294
+ const autoconsentConfig = await storageGet("config");
295
+ const logsConfig = autoconsentConfig.logs;
296
+ if (logsConfig.lifecycle) {
297
+ console.log("got config", autoconsentConfig);
292
298
  console.groupCollapsed(`${msg.type} from ${sender.origin || sender.url}`);
293
299
  console.log(msg, sender);
294
300
  console.groupEnd();
295
301
  }
296
302
  const rules = await storageGet("rules");
297
- const autoconsentConfig = await storageGet("config");
298
- enableLogs && console.log("got config", autoconsentConfig);
299
303
  switch (msg.type) {
300
304
  case "init":
301
305
  if (frameId === 0) {
@@ -311,7 +315,7 @@
311
315
  break;
312
316
  case "eval":
313
317
  evalInTab(tabId, frameId, msg.code, msg.snippetId).then(([result]) => {
314
- if (enableLogs) {
318
+ if (logsConfig.evals) {
315
319
  console.groupCollapsed(`eval result for ${sender.origin || sender.url}`);
316
320
  console.log(msg.code, result.result);
317
321
  console.groupEnd();
@@ -343,7 +347,7 @@
343
347
  }
344
348
  break;
345
349
  case "selfTestResult":
346
- enableLogs && console.log(`Self-test result ${msg.result}`);
350
+ logsConfig.lifecycle && console.log(`Self-test result ${msg.result}`);
347
351
  if (msg.result) {
348
352
  await showOptOutStatus(tabId, "verified", msg.cmp);
349
353
  }
@@ -353,7 +357,7 @@
353
357
  const selfTestKey = `selfTest${tabId}`;
354
358
  const selfTestFrameId = (await chrome.storage.local.get(selfTestKey))?.[selfTestKey];
355
359
  if (typeof selfTestFrameId === "number") {
356
- enableLogs && console.log(`Requesting self-test in ${selfTestFrameId}`);
360
+ logsConfig.lifecycle && console.log(`Requesting self-test in ${selfTestFrameId}`);
357
361
  storageRemove(selfTestKey);
358
362
  chrome.tabs.sendMessage(tabId, {
359
363
  type: "selfTest"
@@ -361,7 +365,7 @@
361
365
  frameId: selfTestFrameId
362
366
  });
363
367
  } else {
364
- enableLogs && console.log(`No self-test scheduled`);
368
+ logsConfig.lifecycle && console.log(`No self-test scheduled`);
365
369
  }
366
370
  break;
367
371
  }
@@ -388,7 +392,6 @@
388
392
  const frameId = await storageGet(detectedKey);
389
393
  if (typeof frameId === "number") {
390
394
  storageRemove(detectedKey);
391
- enableLogs && console.log("action.onClicked", tabId, frameId);
392
395
  await showOptOutStatus(tabId, "working");
393
396
  chrome.tabs.sendMessage(tabId, {
394
397
  type: "optOut"