@duckduckgo/autoconsent 14.81.0 → 14.83.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.
@@ -728,6 +728,7 @@ function normalizeConfig(providedConfig) {
728
728
  enableGeneratedRules: true,
729
729
  enableHeuristicDetection: false,
730
730
  enableHeuristicAction: false,
731
+ enablePopupMutationObserver: false,
731
732
  detectRetries: 20,
732
733
  isMainWorld: false,
733
734
  prehideTimeout: 2e3,
@@ -3963,16 +3964,29 @@ var AutoConsent = class {
3963
3964
  this.updateState({ selfTest: selfTestResult });
3964
3965
  return selfTestResult;
3965
3966
  }
3966
- // TODO: use MutationObserver like in findCmp()
3967
3967
  async waitForPopup(cmp, retries = 10, interval = 500) {
3968
3968
  const logsConfig = this.config.logs;
3969
3969
  logsConfig.lifecycle && console.log("checking if popup is open...", cmp.name);
3970
+ let mutationObserver = null;
3971
+ if (this.config.enablePopupMutationObserver) {
3972
+ mutationObserver = this.domActions.waitForMutation("html", 1e4);
3973
+ mutationObserver.catch(() => {
3974
+ });
3975
+ }
3970
3976
  const isOpen = await cmp.detectPopup().catch((e) => {
3971
3977
  logsConfig.errors && console.warn(`error detecting popup for ${cmp.name}`, e);
3972
3978
  return false;
3973
3979
  });
3974
3980
  if (!isOpen && retries > 0) {
3975
- await this.domActions.wait(interval);
3981
+ if (mutationObserver) {
3982
+ try {
3983
+ await Promise.all([this.domActions.wait(interval), mutationObserver]);
3984
+ } catch (e) {
3985
+ logsConfig.lifecycle && console.log(cmp.name, "popup detection timed out waiting for DOM mutation");
3986
+ }
3987
+ } else {
3988
+ await this.domActions.wait(interval);
3989
+ }
3976
3990
  return this.waitForPopup(cmp, retries - 1, interval);
3977
3991
  }
3978
3992
  logsConfig.lifecycle && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
@@ -698,6 +698,7 @@ function normalizeConfig(providedConfig) {
698
698
  enableGeneratedRules: true,
699
699
  enableHeuristicDetection: false,
700
700
  enableHeuristicAction: false,
701
+ enablePopupMutationObserver: false,
701
702
  detectRetries: 20,
702
703
  isMainWorld: false,
703
704
  prehideTimeout: 2e3,
@@ -3933,16 +3934,29 @@ var AutoConsent = class {
3933
3934
  this.updateState({ selfTest: selfTestResult });
3934
3935
  return selfTestResult;
3935
3936
  }
3936
- // TODO: use MutationObserver like in findCmp()
3937
3937
  async waitForPopup(cmp, retries = 10, interval = 500) {
3938
3938
  const logsConfig = this.config.logs;
3939
3939
  logsConfig.lifecycle && console.log("checking if popup is open...", cmp.name);
3940
+ let mutationObserver = null;
3941
+ if (this.config.enablePopupMutationObserver) {
3942
+ mutationObserver = this.domActions.waitForMutation("html", 1e4);
3943
+ mutationObserver.catch(() => {
3944
+ });
3945
+ }
3940
3946
  const isOpen = await cmp.detectPopup().catch((e) => {
3941
3947
  logsConfig.errors && console.warn(`error detecting popup for ${cmp.name}`, e);
3942
3948
  return false;
3943
3949
  });
3944
3950
  if (!isOpen && retries > 0) {
3945
- await this.domActions.wait(interval);
3951
+ if (mutationObserver) {
3952
+ try {
3953
+ await Promise.all([this.domActions.wait(interval), mutationObserver]);
3954
+ } catch (e) {
3955
+ logsConfig.lifecycle && console.log(cmp.name, "popup detection timed out waiting for DOM mutation");
3956
+ }
3957
+ } else {
3958
+ await this.domActions.wait(interval);
3959
+ }
3946
3960
  return this.waitForPopup(cmp, retries - 1, interval);
3947
3961
  }
3948
3962
  logsConfig.lifecycle && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
@@ -11291,6 +11291,7 @@ function normalizeConfig(providedConfig) {
11291
11291
  enableGeneratedRules: true,
11292
11292
  enableHeuristicDetection: false,
11293
11293
  enableHeuristicAction: false,
11294
+ enablePopupMutationObserver: false,
11294
11295
  detectRetries: 20,
11295
11296
  isMainWorld: false,
11296
11297
  prehideTimeout: 2e3,
@@ -14961,16 +14962,29 @@ var AutoConsent = class {
14961
14962
  this.updateState({ selfTest: selfTestResult });
14962
14963
  return selfTestResult;
14963
14964
  }
14964
- // TODO: use MutationObserver like in findCmp()
14965
14965
  async waitForPopup(cmp, retries = 10, interval = 500) {
14966
14966
  const logsConfig = this.config.logs;
14967
14967
  logsConfig.lifecycle && console.log("checking if popup is open...", cmp.name);
14968
+ let mutationObserver = null;
14969
+ if (this.config.enablePopupMutationObserver) {
14970
+ mutationObserver = this.domActions.waitForMutation("html", 1e4);
14971
+ mutationObserver.catch(() => {
14972
+ });
14973
+ }
14968
14974
  const isOpen = await cmp.detectPopup().catch((e) => {
14969
14975
  logsConfig.errors && console.warn(`error detecting popup for ${cmp.name}`, e);
14970
14976
  return false;
14971
14977
  });
14972
14978
  if (!isOpen && retries > 0) {
14973
- await this.domActions.wait(interval);
14979
+ if (mutationObserver) {
14980
+ try {
14981
+ await Promise.all([this.domActions.wait(interval), mutationObserver]);
14982
+ } catch (e) {
14983
+ logsConfig.lifecycle && console.log(cmp.name, "popup detection timed out waiting for DOM mutation");
14984
+ }
14985
+ } else {
14986
+ await this.domActions.wait(interval);
14987
+ }
14974
14988
  return this.waitForPopup(cmp, retries - 1, interval);
14975
14989
  }
14976
14990
  logsConfig.lifecycle && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
@@ -11225,6 +11225,7 @@ function normalizeConfig(providedConfig) {
11225
11225
  enableGeneratedRules: true,
11226
11226
  enableHeuristicDetection: false,
11227
11227
  enableHeuristicAction: false,
11228
+ enablePopupMutationObserver: false,
11228
11229
  detectRetries: 20,
11229
11230
  isMainWorld: false,
11230
11231
  prehideTimeout: 2e3,
@@ -14895,16 +14896,29 @@ var AutoConsent = class {
14895
14896
  this.updateState({ selfTest: selfTestResult });
14896
14897
  return selfTestResult;
14897
14898
  }
14898
- // TODO: use MutationObserver like in findCmp()
14899
14899
  async waitForPopup(cmp, retries = 10, interval = 500) {
14900
14900
  const logsConfig = this.config.logs;
14901
14901
  logsConfig.lifecycle && console.log("checking if popup is open...", cmp.name);
14902
+ let mutationObserver = null;
14903
+ if (this.config.enablePopupMutationObserver) {
14904
+ mutationObserver = this.domActions.waitForMutation("html", 1e4);
14905
+ mutationObserver.catch(() => {
14906
+ });
14907
+ }
14902
14908
  const isOpen = await cmp.detectPopup().catch((e) => {
14903
14909
  logsConfig.errors && console.warn(`error detecting popup for ${cmp.name}`, e);
14904
14910
  return false;
14905
14911
  });
14906
14912
  if (!isOpen && retries > 0) {
14907
- await this.domActions.wait(interval);
14913
+ if (mutationObserver) {
14914
+ try {
14915
+ await Promise.all([this.domActions.wait(interval), mutationObserver]);
14916
+ } catch (e) {
14917
+ logsConfig.lifecycle && console.log(cmp.name, "popup detection timed out waiting for DOM mutation");
14918
+ }
14919
+ } else {
14920
+ await this.domActions.wait(interval);
14921
+ }
14908
14922
  return this.waitForPopup(cmp, retries - 1, interval);
14909
14923
  }
14910
14924
  logsConfig.lifecycle && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
@@ -700,6 +700,7 @@
700
700
  enableGeneratedRules: true,
701
701
  enableHeuristicDetection: false,
702
702
  enableHeuristicAction: false,
703
+ enablePopupMutationObserver: false,
703
704
  detectRetries: 20,
704
705
  isMainWorld: false,
705
706
  prehideTimeout: 2e3,
@@ -3703,16 +3704,29 @@
3703
3704
  this.updateState({ selfTest: selfTestResult });
3704
3705
  return selfTestResult;
3705
3706
  }
3706
- // TODO: use MutationObserver like in findCmp()
3707
3707
  async waitForPopup(cmp, retries = 10, interval = 500) {
3708
3708
  const logsConfig = this.config.logs;
3709
3709
  logsConfig.lifecycle && console.log("checking if popup is open...", cmp.name);
3710
+ let mutationObserver = null;
3711
+ if (this.config.enablePopupMutationObserver) {
3712
+ mutationObserver = this.domActions.waitForMutation("html", 1e4);
3713
+ mutationObserver.catch(() => {
3714
+ });
3715
+ }
3710
3716
  const isOpen = await cmp.detectPopup().catch((e) => {
3711
3717
  logsConfig.errors && console.warn(`error detecting popup for ${cmp.name}`, e);
3712
3718
  return false;
3713
3719
  });
3714
3720
  if (!isOpen && retries > 0) {
3715
- await this.domActions.wait(interval);
3721
+ if (mutationObserver) {
3722
+ try {
3723
+ await Promise.all([this.domActions.wait(interval), mutationObserver]);
3724
+ } catch (e) {
3725
+ logsConfig.lifecycle && console.log(cmp.name, "popup detection timed out waiting for DOM mutation");
3726
+ }
3727
+ } else {
3728
+ await this.domActions.wait(interval);
3729
+ }
3716
3730
  return this.waitForPopup(cmp, retries - 1, interval);
3717
3731
  }
3718
3732
  logsConfig.lifecycle && console.log(cmp.name, `popup is ${isOpen ? "open" : "not open"}`);
@@ -61,6 +61,7 @@ export type Config = {
61
61
  enableFilterList: boolean;
62
62
  enableHeuristicDetection: boolean;
63
63
  enableHeuristicAction: boolean;
64
+ enablePopupMutationObserver: boolean;
64
65
  visualTest: boolean;
65
66
  logs: {
66
67
  lifecycle: boolean;
package/lib/types.ts CHANGED
@@ -65,6 +65,7 @@ export type Config = {
65
65
  enableFilterList: boolean;
66
66
  enableHeuristicDetection: boolean;
67
67
  enableHeuristicAction: boolean;
68
+ enablePopupMutationObserver: boolean;
68
69
  visualTest: boolean; // If true, the script will delay before every click action
69
70
  logs: {
70
71
  lifecycle: boolean;
package/lib/utils.ts CHANGED
@@ -78,6 +78,7 @@ export function normalizeConfig(providedConfig: any): Config {
78
78
  enableGeneratedRules: true,
79
79
  enableHeuristicDetection: false,
80
80
  enableHeuristicAction: false,
81
+ enablePopupMutationObserver: false,
81
82
  detectRetries: 20,
82
83
  isMainWorld: false,
83
84
  prehideTimeout: 2000,
package/lib/web.ts CHANGED
@@ -553,16 +553,30 @@ export default class AutoConsent {
553
553
  return selfTestResult;
554
554
  }
555
555
 
556
- // TODO: use MutationObserver like in findCmp()
557
556
  async waitForPopup(cmp: AutoCMP, retries = 10, interval = 500): Promise<boolean> {
558
557
  const logsConfig = this.config.logs;
559
558
  logsConfig.lifecycle && console.log('checking if popup is open...', cmp.name);
559
+
560
+ let mutationObserver: Promise<boolean> | null = null;
561
+ if (this.config.enablePopupMutationObserver) {
562
+ mutationObserver = this.domActions.waitForMutation('html', 10000);
563
+ mutationObserver.catch(() => {});
564
+ }
565
+
560
566
  const isOpen = await cmp.detectPopup().catch((e) => {
561
567
  logsConfig.errors && console.warn(`error detecting popup for ${cmp.name}`, e);
562
568
  return false;
563
- }); // ignore possible errors in one-time popup detection
569
+ });
564
570
  if (!isOpen && retries > 0) {
565
- await this.domActions.wait(interval);
571
+ if (mutationObserver) {
572
+ try {
573
+ await Promise.all([this.domActions.wait(interval), mutationObserver]);
574
+ } catch (e) {
575
+ logsConfig.lifecycle && console.log(cmp.name, 'popup detection timed out waiting for DOM mutation');
576
+ }
577
+ } else {
578
+ await this.domActions.wait(interval);
579
+ }
566
580
  return this.waitForPopup(cmp, retries - 1, interval);
567
581
  }
568
582
  logsConfig.lifecycle && console.log(cmp.name, `popup is ${isOpen ? 'open' : 'not open'}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckduckgo/autoconsent",
3
- "version": "14.81.0",
3
+ "version": "14.83.0",
4
4
  "description": "",
5
5
  "types": "./dist/types/web.d.ts",
6
6
  "exports": {
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "facebook-mobile",
3
+ "runContext": {
4
+ "urlPattern": "^https://(m|mbasic)\\.facebook\\.com/"
5
+ },
6
+ "prehideSelectors": ["[data-testid=\"cookie-policy-manage-dialog\"]"],
7
+ "detectCmp": [{ "exists": "[data-testid=\"cookie-policy-manage-dialog\"]" }],
8
+ "detectPopup": [{ "visible": "[data-testid=\"cookie-policy-manage-dialog\"]" }],
9
+ "optIn": [
10
+ { "waitForThenClick": "[data-testid=\"cookie-policy-manage-dialog-accept-button\"]" },
11
+ { "waitForVisible": "[data-testid=\"cookie-policy-manage-dialog\"]", "check": "none" }
12
+ ],
13
+ "optOut": [
14
+ { "waitForThenClick": "[data-testid=\"cookie-policy-manage-dialog-decline-button\"]" },
15
+ { "waitForVisible": "[data-testid=\"cookie-policy-manage-dialog\"]", "check": "none" }
16
+ ]
17
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "facebook",
3
3
  "runContext": {
4
- "urlPattern": "^https://([a-z0-9-]+\\.)?facebook\\.com/"
4
+ "urlPattern": "^https://(www\\.)?facebook\\.com/"
5
5
  },
6
6
  "prehideSelectors": [],
7
7
  "detectCmp": [