@duckduckgo/autoconsent 4.4.0 → 5.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.
package/lib/types.ts CHANGED
@@ -34,6 +34,7 @@ export type Config = {
34
34
  enablePrehide: boolean;
35
35
  enableCosmeticRules: boolean;
36
36
  detectRetries: number;
37
+ prehideTimeout: number;
37
38
  }
38
39
 
39
40
  export type LifecycleState = 'loading' |
package/lib/web.ts CHANGED
@@ -4,7 +4,7 @@ import { ConsentOMaticCMP, ConsentOMaticConfig } from './cmps/consentomatic';
4
4
  import { AutoConsentCMPRule } from './rules';
5
5
  import { enableLogs } from './config';
6
6
  import { BackgroundMessage, InitMessage } from './messages';
7
- import { prehide, undoPrehide } from './rule-executors';
7
+ import { prehide, undoPrehide, wait } from './rule-executors';
8
8
  import { evalState, resolveEval } from './eval-handler';
9
9
  import { getRandomID } from './random';
10
10
 
@@ -202,12 +202,8 @@ export default class AutoConsent {
202
202
  }
203
203
 
204
204
  if (foundCMPs.length === 0 && retries > 0) {
205
- return new Promise((resolve) => {
206
- setTimeout(async () => {
207
- const result = this.findCmp(retries - 1);
208
- resolve(result);
209
- }, 500);
210
- });
205
+ await wait(500);
206
+ return this.findCmp(retries - 1);
211
207
  }
212
208
 
213
209
  return foundCMPs;
@@ -332,7 +328,8 @@ export default class AutoConsent {
332
328
  enableLogs && console.log('checking if popup is open...', cmp.name);
333
329
  const isOpen = await cmp.detectPopup();
334
330
  if (!isOpen && retries > 0) {
335
- return new Promise((resolve) => setTimeout(() => resolve(this.waitForPopup(cmp, retries - 1, interval)), interval));
331
+ await wait(interval);
332
+ return this.waitForPopup(cmp, retries - 1, interval);
336
333
  }
337
334
  enableLogs && console.log(cmp.name, `popup is ${isOpen ? 'open' : 'not open'}`);
338
335
  return isOpen;
@@ -352,6 +349,17 @@ export default class AutoConsent {
352
349
  }, globalHidden);
353
350
 
354
351
  this.updateState({ prehideOn: true })
352
+ setTimeout(() => {
353
+ // unhide things if we are still looking for a pop-up
354
+ if (
355
+ this.config.enablePrehide &&
356
+ this.state.prehideOn &&
357
+ !['runningOptOut', 'runningOptIn'].includes(this.state.lifecycle)
358
+ ) {
359
+ enableLogs && console.log('Process is taking too long, unhiding elements');
360
+ this.undoPrehide();
361
+ }
362
+ }, this.config.prehideTimeout || 2000);
355
363
  return prehide(selectors);
356
364
  }
357
365
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckduckgo/autoconsent",
3
- "version": "4.4.0",
3
+ "version": "5.0.0",
4
4
  "description": "",
5
5
  "main": "dist/autoconsent.cjs.js",
6
6
  "module": "dist/autoconsent.esm.js",
@@ -49,7 +49,7 @@
49
49
  "rollup-plugin-copy": "^3.4.0",
50
50
  "rollup-plugin-terser": "^7.0.2",
51
51
  "tslib": "^2.4.0",
52
- "typescript": "^4.6.4",
52
+ "typescript": "^5.1.6",
53
53
  "web-ext": "^7.3.0"
54
54
  },
55
55
  "repository": "duckduckgo/autoconsent",