@duckduckgo/autoconsent 16.27.0 → 16.29.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/AGENTS.md +1 -1
- package/CHANGELOG.md +40 -0
- package/dist/addon-firefox/compact-rules.json +1 -1
- package/dist/addon-firefox/content.bundle.js +43 -6
- package/dist/addon-firefox/manifest.json +1 -1
- package/dist/addon-firefox/rule-index.json +1 -1
- package/dist/addon-firefox/rules.json +1 -1
- package/dist/addon-mv3/compact-rules.json +1 -1
- package/dist/addon-mv3/content.bundle.js +43 -6
- package/dist/addon-mv3/manifest.json +1 -1
- package/dist/addon-mv3/rule-index.json +1 -1
- package/dist/addon-mv3/rules.json +1 -1
- package/dist/autoconsent.cjs.js +43 -6
- package/dist/autoconsent.esm.js +43 -6
- package/dist/autoconsent.playwright.js +43 -6
- package/dist/autoconsent.standalone.js +44 -7
- package/dist/types/cmps/base.d.ts +2 -1
- package/dist/types/dom-actions.d.ts +3 -1
- package/dist/types/rules.d.ts +16 -2
- package/dist/types/types.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/docs/rule-syntax.md +26 -1
- package/lib/cmps/base.ts +10 -3
- package/lib/dom-actions.ts +33 -3
- package/lib/rules.ts +19 -2
- package/lib/types.ts +7 -1
- package/lib/utils.ts +16 -0
- package/package.json +1 -1
- package/rules/autoconsent/amazon-pay.json +13 -0
- package/rules/autoconsent/bbva.json +12 -0
- package/rules/autoconsent/deliveroo.json +15 -0
- package/rules/autoconsent/ebay.json +34 -0
- package/rules/autoconsent/ecbeing.json +10 -0
- package/rules/autoconsent/stright.json +29 -0
- package/rules/autoconsent/theguardian.com.json +13 -3
- package/rules/autoconsent/wpconsent.json +30 -0
- package/rules/compact-rules.json +1 -1
- package/rules/rule-index.json +1 -1
- package/rules/rules.json +1 -1
- package/tests/amazon-pay.spec.ts +3 -0
- package/tests/bbva.spec.ts +4 -0
- package/tests/deliveroo.spec.ts +3 -0
- package/tests/ecbeing.spec.ts +3 -0
- package/tests/stright.spec.ts +8 -0
- package/tests/wpconsent.spec.ts +5 -0
- package/tests-wtr/dom-actions/dom-actions.stylesheet.html +13 -0
- package/tests-wtr/dom-actions/dom-actions.stylesheet.ts +26 -0
- package/tests-wtr/dom-actions/dom-actions.wait-for-then-click.html +14 -0
- package/tests-wtr/dom-actions/dom-actions.wait-for-then-click.ts +106 -0
- package/tests-wtr/utils/append-stylesheet-rule.html +11 -0
- package/tests-wtr/utils/append-stylesheet-rule.test.ts +29 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
3
|
// lib/rules.ts
|
|
4
|
-
var SUPPORTED_RULE_STEP_VERSION =
|
|
4
|
+
var SUPPORTED_RULE_STEP_VERSION = 3;
|
|
5
5
|
|
|
6
6
|
// lib/random.ts
|
|
7
7
|
function getRandomID() {
|
|
@@ -80,6 +80,20 @@
|
|
|
80
80
|
}
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
83
|
+
function appendStylesheetRule(styleEl, cssRule, marker) {
|
|
84
|
+
if (!(styleEl instanceof HTMLStyleElement) || cssRule.length === 0) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
const markerComment = marker ? `/* autoconsent:${marker} */` : "";
|
|
88
|
+
if (markerComment && styleEl.innerText.includes(markerComment)) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
if (!markerComment && styleEl.innerText.includes(cssRule.trim())) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
styleEl.innerText += `${markerComment}${markerComment ? " " : ""}${cssRule} `;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
83
97
|
async function waitFor(predicate, maxTimes, interval) {
|
|
84
98
|
const result = await predicate();
|
|
85
99
|
if (!result && maxTimes > 0) {
|
|
@@ -1448,12 +1462,12 @@
|
|
|
1448
1462
|
waitForVisible(selector, timeout, check) {
|
|
1449
1463
|
return this.autoconsent.domActions.waitForVisible(selector, timeout, check);
|
|
1450
1464
|
}
|
|
1451
|
-
async waitForThenClick(selector, timeout, all) {
|
|
1465
|
+
async waitForThenClick(selector, timeout, all, retries, retryInterval) {
|
|
1452
1466
|
if (this.autoconsent.config.visualTest) {
|
|
1453
1467
|
await this.highlightElements(this.elementSelector(selector), all);
|
|
1454
1468
|
}
|
|
1455
1469
|
this.autoconsent.updateState({ clicks: this.autoconsent.state.clicks + 1 });
|
|
1456
|
-
return this.autoconsent.domActions.waitForThenClick(selector, timeout, all);
|
|
1470
|
+
return this.autoconsent.domActions.waitForThenClick(selector, timeout, all, retries, retryInterval);
|
|
1457
1471
|
}
|
|
1458
1472
|
wait(ms) {
|
|
1459
1473
|
return this.autoconsent.domActions.wait(ms);
|
|
@@ -1461,6 +1475,9 @@
|
|
|
1461
1475
|
hide(selector, method) {
|
|
1462
1476
|
return this.autoconsent.domActions.hide(selector, method);
|
|
1463
1477
|
}
|
|
1478
|
+
stylesheet(cssRule, stylesheetId) {
|
|
1479
|
+
return this.autoconsent.domActions.stylesheet(cssRule, stylesheetId);
|
|
1480
|
+
}
|
|
1464
1481
|
removeClass(selector, className) {
|
|
1465
1482
|
return this.autoconsent.domActions.removeClass(selector, className);
|
|
1466
1483
|
}
|
|
@@ -1574,7 +1591,7 @@
|
|
|
1574
1591
|
results.push(this.click(rule.click, rule.all));
|
|
1575
1592
|
}
|
|
1576
1593
|
if (rule.waitForThenClick) {
|
|
1577
|
-
results.push(this.waitForThenClick(rule.waitForThenClick, rule.timeout, rule.all));
|
|
1594
|
+
results.push(this.waitForThenClick(rule.waitForThenClick, rule.timeout, rule.all, rule.retry, rule.retryInterval));
|
|
1578
1595
|
}
|
|
1579
1596
|
if (rule.wait) {
|
|
1580
1597
|
results.push(this.wait(rule.wait));
|
|
@@ -1582,6 +1599,9 @@
|
|
|
1582
1599
|
if (rule.hide) {
|
|
1583
1600
|
results.push(this.hide(rule.hide, rule.method));
|
|
1584
1601
|
}
|
|
1602
|
+
if (rule.stylesheet !== void 0) {
|
|
1603
|
+
results.push(this.stylesheet(rule.stylesheet, rule.stylesheetId));
|
|
1604
|
+
}
|
|
1585
1605
|
if (rule.removeClass !== void 0) {
|
|
1586
1606
|
results.push(rule.selector ? this.removeClass(rule.selector, rule.removeClass) : false);
|
|
1587
1607
|
}
|
|
@@ -2533,6 +2553,8 @@
|
|
|
2533
2553
|
];
|
|
2534
2554
|
|
|
2535
2555
|
// lib/dom-actions.ts
|
|
2556
|
+
var DEFAULT_CLICK_RETRY_INTERVAL = 300;
|
|
2557
|
+
var CLICK_RETRY_POLL_INTERVAL = 50;
|
|
2536
2558
|
var DomActions = class {
|
|
2537
2559
|
constructor(autoconsentInstance) {
|
|
2538
2560
|
this.autoconsentInstance = autoconsentInstance;
|
|
@@ -2588,9 +2610,19 @@
|
|
|
2588
2610
|
this.autoconsentInstance.config.logs.rulesteps && console.log("[waitForVisible]", selector);
|
|
2589
2611
|
return waitFor(() => this.elementVisible(selector, check), times, interval);
|
|
2590
2612
|
}
|
|
2591
|
-
async waitForThenClick(selector, timeout = 1e4, all = false) {
|
|
2613
|
+
async waitForThenClick(selector, timeout = 1e4, all = false, retries = 0, retryInterval = DEFAULT_CLICK_RETRY_INTERVAL) {
|
|
2592
2614
|
await this.waitForElement(selector, timeout);
|
|
2593
|
-
|
|
2615
|
+
let clicked = await this.click(selector, all);
|
|
2616
|
+
for (let attempt = 0; clicked && attempt < retries; attempt++) {
|
|
2617
|
+
const pollTimes = Math.ceil(retryInterval / CLICK_RETRY_POLL_INTERVAL);
|
|
2618
|
+
const isGone = await waitFor(() => !this.elementVisible(selector, "any"), pollTimes, CLICK_RETRY_POLL_INTERVAL);
|
|
2619
|
+
if (isGone) {
|
|
2620
|
+
break;
|
|
2621
|
+
}
|
|
2622
|
+
this.autoconsentInstance.config.logs.rulesteps && console.log("[waitForThenClick] retrying click", selector);
|
|
2623
|
+
clicked = await this.click(selector, all);
|
|
2624
|
+
}
|
|
2625
|
+
return clicked;
|
|
2594
2626
|
}
|
|
2595
2627
|
wait(ms) {
|
|
2596
2628
|
this.autoconsentInstance.config.logs.rulesteps && this.autoconsentInstance.config.logs.waits && console.log("[wait]", ms);
|
|
@@ -2608,6 +2640,11 @@
|
|
|
2608
2640
|
const styleEl = getStyleElement();
|
|
2609
2641
|
return hideElements(styleEl, selector, method);
|
|
2610
2642
|
}
|
|
2643
|
+
stylesheet(cssRule, stylesheetId) {
|
|
2644
|
+
this.autoconsentInstance.config.logs.rulesteps && console.log("[stylesheet]", cssRule, stylesheetId);
|
|
2645
|
+
const styleEl = getStyleElement();
|
|
2646
|
+
return appendStylesheetRule(styleEl, cssRule, stylesheetId);
|
|
2647
|
+
}
|
|
2611
2648
|
removeClass(selector, className) {
|
|
2612
2649
|
const elements = this.elementSelector(selector);
|
|
2613
2650
|
this.autoconsentInstance.config.logs.rulesteps && console.log("[removeClass]", selector, className, elements);
|