@duckduckgo/autoconsent 1.0.8 → 2.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/.eslintrc.cjs +14 -0
- package/.vscode/settings.json +7 -0
- package/Jenkinsfile +68 -39
- package/api.md +104 -0
- package/dist/autoconsent.cjs.js +1 -1387
- package/dist/autoconsent.esm.js +1 -1379
- package/dist/autoconsent.playwright.js +1 -0
- package/dist/autoconsent.standalone.js +1 -0
- package/lib/cmps/all.ts +15 -10
- package/lib/cmps/base.ts +91 -91
- package/lib/cmps/consentmanager.ts +31 -19
- package/lib/cmps/consentomatic.ts +89 -0
- package/lib/cmps/cookiebot.ts +58 -55
- package/lib/cmps/evidon.ts +29 -18
- package/lib/cmps/onetrust.ts +32 -20
- package/lib/cmps/sourcepoint-frame.ts +102 -0
- package/lib/cmps/sourcepoint-top.ts +47 -0
- package/lib/cmps/trustarc-frame.ts +115 -0
- package/lib/cmps/trustarc-top.ts +91 -0
- package/lib/consentomatic/index.ts +233 -70
- package/lib/{web/consentomatic → consentomatic}/tools.ts +0 -0
- package/lib/eval-handler.ts +58 -0
- package/lib/index.ts +0 -2
- package/lib/messages.ts +100 -0
- package/lib/rule-executors.ts +108 -0
- package/lib/rules.ts +82 -0
- package/lib/types.ts +35 -0
- package/lib/utils.ts +64 -0
- package/lib/web.ts +283 -74
- package/package.json +17 -14
- package/playwright/content.ts +27 -0
- package/playwright/runner.ts +131 -0
- package/playwright/standalone.ts +36 -0
- package/playwright.config.ts +7 -0
- package/readme.md +57 -47
- package/rollup.config.js +23 -15
- package/rules/autoconsent/baden-wuerttemberg-de.json +7 -3
- package/rules/autoconsent/bundesregierung-de.json +5 -1
- package/rules/autoconsent/cc-banner.json +0 -1
- package/rules/autoconsent/cookie-notice.json +0 -1
- package/rules/autoconsent/cookieconsent.json +5 -6
- package/rules/autoconsent/destatis-de.json +0 -1
- package/rules/autoconsent/etsy.json +3 -2
- package/rules/autoconsent/eu-cookie-compliance.json +0 -1
- package/rules/autoconsent/hl-co-uk.json +8 -9
- package/rules/autoconsent/johnlewis.json +5 -2
- package/rules/autoconsent/notice-cookie.json +0 -1
- package/rules/autoconsent/osano.json +0 -1
- package/rules/autoconsent/tealium.json +4 -5
- package/rules/rules.json +44 -37
- package/tests/192.spec.ts +1 -1
- package/tests/arzt-auskunft.spec.ts +1 -1
- package/tests/asus.spec.ts +1 -1
- package/tests/ausopen.spec.ts +1 -1
- package/tests/aws.amazon.spec.ts +1 -1
- package/tests/baden-wuerttemberg.spec.ts +1 -1
- package/tests/borlabs.spec.ts +1 -1
- package/tests/bundesregierung.spec.ts +5 -2
- package/tests/ccbanner.spec.ts +1 -1
- package/tests/consentmanager.spec.ts +3 -3
- package/tests/cookiebot.spec.ts +8 -2
- package/tests/cookieconsent.spec.ts +1 -1
- package/tests/cookielawinfo.spec.ts +1 -1
- package/tests/cookienotice.spec.ts +1 -1
- package/tests/corona-in-zahlen.spec.ts +1 -1
- package/tests/deepl.spec.ts +1 -1
- package/tests/destatis.spec.ts +1 -1
- package/tests/didomi.spec.ts +6 -2
- package/tests/drupal.spec.ts +8 -0
- package/tests/dunelm.spec.ts +1 -1
- package/tests/etsy.spec.ts +1 -1
- package/tests/eu-cookie-compliance-banner.spec.ts +1 -1
- package/tests/evidon.spec.ts +1 -1
- package/tests/fundingchoices.spec.ts +2 -1
- package/tests/gov-uk.spec.ts +1 -1
- package/tests/hl-co-uk.spec.ts +1 -1
- package/tests/hubspot.spec.ts +1 -1
- package/tests/ionos.spec.ts +1 -1
- package/tests/johnlewis.spec.ts +2 -2
- package/tests/klaro.spec.ts +1 -1
- package/tests/marksandspencer.spec.ts +1 -1
- package/tests/mediamarkt.spec.ts +1 -1
- package/tests/metoffice-gov-uk.spec.ts +1 -1
- package/tests/microsoft.spec.ts +1 -1
- package/tests/moneysavingexpert.spec.ts +1 -1
- package/tests/motor-talk.spec.ts +1 -1
- package/tests/national-lottery.spec.ts +1 -1
- package/tests/netflix.spec.ts +1 -1
- package/tests/nhs.spec.ts +1 -1
- package/tests/notice-cookie.spec.ts +1 -1
- package/tests/obi.spec.ts +1 -1
- package/tests/oil.spec.ts +1 -1
- package/tests/onetrust.spec.ts +10 -1
- package/tests/osano.spec.ts +1 -1
- package/tests/otto.spec.ts +1 -1
- package/tests/paypal.spec.ts +1 -1
- package/tests/quantcast.spec.ts +4 -1
- package/tests/snigel.spec.ts +1 -1
- package/tests/sourcepoint.spec.ts +8 -8
- package/tests/springer.spec.ts +1 -1
- package/tests/steampowered.spec.ts +1 -1
- package/tests/tealium.spec.ts +1 -1
- package/tests/testcmp.spec.ts +1 -1
- package/tests/thalia.spec.ts +1 -1
- package/tests/thefreedictionary.spec.ts +1 -1
- package/tests/trustarc.spec.ts +25 -4
- package/tests/usercentrics-1.spec.ts +1 -1
- package/tests/uswitch.spec.ts +1 -1
- package/tests/vodafone.spec.ts +1 -1
- package/tests/waitrose.spec.ts +1 -1
- package/tests/wetransfer.spec.ts +1 -1
- package/tests/wordpressgdpr.spec.ts +1 -1
- package/tests/xing.spec.ts +1 -1
- package/tsconfig.json +2 -2
- package/.eslintrc +0 -12
- package/cosmetics/rules.json +0 -110
- package/dist/autoconsent.puppet.js +0 -1078
- package/lib/cmps/all.js +0 -19
- package/lib/cmps/base.js +0 -174
- package/lib/cmps/consentmanager.js +0 -31
- package/lib/cmps/cookiebot.js +0 -77
- package/lib/cmps/evidon.js +0 -26
- package/lib/cmps/onetrust.js +0 -34
- package/lib/cmps/sourcepoint.js +0 -82
- package/lib/cmps/sourcepoint.ts +0 -95
- package/lib/cmps/trustarc.js +0 -106
- package/lib/cmps/trustarc.ts +0 -147
- package/lib/config.js +0 -1
- package/lib/consentomatic/index.js +0 -52
- package/lib/detector.js +0 -33
- package/lib/detector.ts +0 -34
- package/lib/hider.js +0 -13
- package/lib/hider.ts +0 -16
- package/lib/index.js +0 -4
- package/lib/messages.d.ts +0 -61
- package/lib/node.js +0 -35
- package/lib/node.ts +0 -43
- package/lib/puppet/tab.js +0 -121
- package/lib/puppet/tab.ts +0 -146
- package/lib/rules.d.ts +0 -80
- package/lib/tabwrapper.js +0 -67
- package/lib/tabwrapper.ts +0 -74
- package/lib/types.d.ts +0 -61
- package/lib/web/consentomatic/index.js +0 -188
- package/lib/web/consentomatic/index.ts +0 -249
- package/lib/web/consentomatic/tools.js +0 -177
- package/lib/web/content-utils.js +0 -29
- package/lib/web/content-utils.ts +0 -31
- package/lib/web/content.js +0 -89
- package/lib/web/content.ts +0 -80
- package/lib/web/tab.js +0 -112
- package/lib/web/tab.ts +0 -178
- package/lib/web.js +0 -95
- package/tests/runner.ts +0 -61
package/lib/cmps/trustarc.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import AutoConsentBase, { waitFor } from "./base";
|
|
2
|
-
import { TabActor } from "../types";
|
|
3
|
-
|
|
4
|
-
export default class TrustArc extends AutoConsentBase {
|
|
5
|
-
|
|
6
|
-
prehideSelectors = [
|
|
7
|
-
".trustarc-banner-container",
|
|
8
|
-
".truste_popframe,.truste_overlay,.truste_box_overlay,#truste-consent-track",
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
constructor() {
|
|
12
|
-
super("TrustArc");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
detectFrame(_: TabActor, frame: { url: string }) {
|
|
16
|
-
return frame.url.startsWith("https://consent-pref.trustarc.com/?");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async detectCmp(tab: TabActor) {
|
|
20
|
-
if (
|
|
21
|
-
tab.frame &&
|
|
22
|
-
tab.frame.url.startsWith("https://consent-pref.trustarc.com/?")
|
|
23
|
-
) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
return tab.elementExists("#truste-show-consent,#truste-consent-track");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async detectPopup(tab: TabActor) {
|
|
30
|
-
return (
|
|
31
|
-
(await tab.elementsAreVisible("#truste-consent-content,.truste-consent-content,#trustarc-banner-overlay")) ||
|
|
32
|
-
(tab.frame &&
|
|
33
|
-
(await tab.waitForElement(
|
|
34
|
-
"#defaultpreferencemanager",
|
|
35
|
-
5000,
|
|
36
|
-
tab.frame.id
|
|
37
|
-
)))
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async openFrame(tab: TabActor) {
|
|
42
|
-
if (await tab.elementExists("#truste-show-consent")) {
|
|
43
|
-
await tab.clickElement("#truste-show-consent");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async navigateToSettings(tab: TabActor, frameId: number) {
|
|
48
|
-
// wait for it to load
|
|
49
|
-
await waitFor(
|
|
50
|
-
async () => {
|
|
51
|
-
return (
|
|
52
|
-
(await tab.elementExists(".shp", frameId)) ||
|
|
53
|
-
(await tab.elementsAreVisible(".advance", "any", frameId)) ||
|
|
54
|
-
tab.elementExists(".switch span:first-child", frameId)
|
|
55
|
-
);
|
|
56
|
-
},
|
|
57
|
-
10,
|
|
58
|
-
500
|
|
59
|
-
);
|
|
60
|
-
// splash screen -> hit more information
|
|
61
|
-
if (await tab.elementExists(".shp", frameId)) {
|
|
62
|
-
await tab.clickElement(".shp", frameId);
|
|
63
|
-
}
|
|
64
|
-
await tab.waitForElement(".prefPanel", 5000, frameId);
|
|
65
|
-
// go to advanced settings if not yet shown
|
|
66
|
-
if (await tab.elementsAreVisible(".advance", "any", frameId)) {
|
|
67
|
-
await tab.clickElement(".advance", frameId);
|
|
68
|
-
}
|
|
69
|
-
// takes a while to load the opt-in/opt-out buttons
|
|
70
|
-
return await waitFor(
|
|
71
|
-
() => tab.elementsAreVisible(".switch span:first-child", "any", frameId),
|
|
72
|
-
5,
|
|
73
|
-
1000
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async optOut(tab: TabActor) {
|
|
78
|
-
// await tab.hideElements(['.truste_overlay', '.truste_box_overlay', '.trustarc-banner', '.truste-banner']);
|
|
79
|
-
if (await tab.elementExists("#truste-consent-required")) {
|
|
80
|
-
return tab.clickElement("#truste-consent-required");
|
|
81
|
-
}
|
|
82
|
-
if (!tab.frame) {
|
|
83
|
-
await tab.clickElement("#truste-show-consent");
|
|
84
|
-
await waitFor(
|
|
85
|
-
async () =>
|
|
86
|
-
!!tab.frame &&
|
|
87
|
-
(await tab.elementsAreVisible(".mainContent", "any", tab.frame.id)),
|
|
88
|
-
50,
|
|
89
|
-
100
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
const frameId = tab.frame!.id;
|
|
93
|
-
await waitFor(() => tab.eval("document.readyState === 'complete'", frameId), 20, 100);
|
|
94
|
-
tab.hideElements([".truste_popframe", ".truste_overlay", ".truste_box_overlay", "#truste-consent-track"]);
|
|
95
|
-
if (await tab.elementExists('.rejectAll', frameId)) {
|
|
96
|
-
return tab.clickElement('.rejectAll', frameId);
|
|
97
|
-
}
|
|
98
|
-
if (await tab.waitForElement('#catDetails0', 1000, frameId)) {
|
|
99
|
-
await tab.clickElement("#catDetails0", frameId);
|
|
100
|
-
return tab.clickElement(".submit", frameId);
|
|
101
|
-
}
|
|
102
|
-
if (await tab.elementExists(".required", frameId)) {
|
|
103
|
-
await tab.clickElement(".required", frameId);
|
|
104
|
-
} else {
|
|
105
|
-
await this.navigateToSettings(tab, frameId);
|
|
106
|
-
await tab.clickElements(
|
|
107
|
-
".switch span:nth-child(1):not(.active)",
|
|
108
|
-
frameId
|
|
109
|
-
);
|
|
110
|
-
await tab.clickElement(".submit", frameId);
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
await tab.waitForThenClick("#gwt-debug-close_id", 20000, tab.frame.id);
|
|
114
|
-
} catch (e) {
|
|
115
|
-
// ignore frame disappearing
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async optIn(tab: TabActor) {
|
|
121
|
-
if (!tab.frame) {
|
|
122
|
-
await this.openFrame(tab);
|
|
123
|
-
await waitFor(() => !!tab.frame, 10, 200);
|
|
124
|
-
}
|
|
125
|
-
const frameId = tab.frame!.id;
|
|
126
|
-
await this.navigateToSettings(tab, frameId);
|
|
127
|
-
await tab.clickElements(".switch span:nth-child(2)", frameId);
|
|
128
|
-
await tab.clickElement(".submit", frameId);
|
|
129
|
-
await waitFor(
|
|
130
|
-
() => tab.elementExists("#gwt-debug-close_id", frameId),
|
|
131
|
-
300,
|
|
132
|
-
1000
|
|
133
|
-
);
|
|
134
|
-
await tab.clickElement("#gwt-debug-close_id", frameId);
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async openCmp(tab: TabActor) {
|
|
139
|
-
await tab.eval("truste.eu.clickListener()");
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async test() {
|
|
144
|
-
// TODO: find out how to test TrustArc
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
}
|
package/lib/config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const enableLogs = false; // change this to enable debug logs
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export class ConsentOMaticCMP {
|
|
2
|
-
constructor(name, config) {
|
|
3
|
-
this.name = name;
|
|
4
|
-
this.config = config;
|
|
5
|
-
this.methods = new Map();
|
|
6
|
-
config.methods.forEach(methodConfig => {
|
|
7
|
-
if (methodConfig.action) {
|
|
8
|
-
this.methods.set(methodConfig.name, methodConfig.action);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
this.hasSelfTest = this.methods.has("TEST_CONSENT");
|
|
12
|
-
}
|
|
13
|
-
async detectCmp(tab) {
|
|
14
|
-
return (await Promise.all(this.config.detectors.map(detectorConfig => tab.matches(detectorConfig.presentMatcher)))).some(matched => matched);
|
|
15
|
-
}
|
|
16
|
-
async detectPopup(tab) {
|
|
17
|
-
return (await Promise.all(this.config.detectors.map(detectorConfig => tab.matches(detectorConfig.showingMatcher)))).some(matched => matched);
|
|
18
|
-
}
|
|
19
|
-
async executeAction(tab, method, param) {
|
|
20
|
-
if (this.methods.has(method)) {
|
|
21
|
-
return tab.executeAction(this.methods.get(method), param);
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
async optOut(tab) {
|
|
26
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
27
|
-
await this.executeAction(tab, "OPEN_OPTIONS");
|
|
28
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
29
|
-
await this.executeAction(tab, "DO_CONSENT", []);
|
|
30
|
-
await this.executeAction(tab, "SAVE_CONSENT");
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
async optIn(tab) {
|
|
34
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
35
|
-
await this.executeAction(tab, "OPEN_OPTIONS");
|
|
36
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
37
|
-
await this.executeAction(tab, "DO_CONSENT", ['D', 'A', 'B', 'E', 'F', 'X']);
|
|
38
|
-
await this.executeAction(tab, "SAVE_CONSENT");
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
async openCmp(tab) {
|
|
42
|
-
await this.executeAction(tab, "HIDE_CMP");
|
|
43
|
-
await this.executeAction(tab, "OPEN_OPTIONS");
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
test(tab) {
|
|
47
|
-
return this.executeAction(tab, "TEST_CONSENT");
|
|
48
|
-
}
|
|
49
|
-
detectFrame(tab, frame) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
package/lib/detector.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { enableLogs } from './config';
|
|
2
|
-
export default async function detectDialog(tab, retries, rules) {
|
|
3
|
-
let breakEarly = false;
|
|
4
|
-
const found = await new Promise(async (resolve) => {
|
|
5
|
-
let earlyReturn = false;
|
|
6
|
-
enableLogs && console.log(`${new Date()} [${tab.id}] Detecting CMPs (${rules.length} rules)`);
|
|
7
|
-
await Promise.all(rules.map(async (r, index) => {
|
|
8
|
-
try {
|
|
9
|
-
if (await r.detectCmp(tab)) {
|
|
10
|
-
earlyReturn = true;
|
|
11
|
-
enableLogs && console.log(`Found CMP in [${tab.id}]: ${r.name}`);
|
|
12
|
-
resolve(index);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
catch (e) {
|
|
16
|
-
breakEarly = true;
|
|
17
|
-
}
|
|
18
|
-
}));
|
|
19
|
-
if (!earlyReturn) {
|
|
20
|
-
resolve(-1);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
enableLogs && console.log(`${new Date()} CMP detection finished in [${tab.id}], found rule #${found}`);
|
|
24
|
-
if (found === -1 && retries > 0 && !breakEarly) {
|
|
25
|
-
return new Promise((resolve) => {
|
|
26
|
-
setTimeout(async () => {
|
|
27
|
-
const result = detectDialog(tab, retries - 1, rules);
|
|
28
|
-
resolve(result);
|
|
29
|
-
}, 500);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return found > -1 ? rules[found] : null;
|
|
33
|
-
}
|
package/lib/detector.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { enableLogs } from './config';
|
|
2
|
-
import { AutoCMP, TabActor } from './types';
|
|
3
|
-
|
|
4
|
-
export default async function detectDialog(tab: TabActor, retries: number, rules: AutoCMP[]): Promise<AutoCMP> {
|
|
5
|
-
let breakEarly = false;
|
|
6
|
-
const found: number = await new Promise(async (resolve) => {
|
|
7
|
-
let earlyReturn = false;
|
|
8
|
-
enableLogs && console.log(`${new Date()} [${tab.id}] Detecting CMPs (${rules.length} rules)`);
|
|
9
|
-
await Promise.all(rules.map(async (r, index) => {
|
|
10
|
-
try {
|
|
11
|
-
if (await r.detectCmp(tab)) {
|
|
12
|
-
earlyReturn = true;
|
|
13
|
-
enableLogs && console.log(`Found CMP in [${tab.id}]: ${r.name}`);
|
|
14
|
-
resolve(index)
|
|
15
|
-
}
|
|
16
|
-
} catch (e) {
|
|
17
|
-
breakEarly = true;
|
|
18
|
-
}
|
|
19
|
-
}));
|
|
20
|
-
if (!earlyReturn) {
|
|
21
|
-
resolve(-1)
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
enableLogs && console.log(`${new Date()} CMP detection finished in [${tab.id}], found rule #${found}`);
|
|
25
|
-
if (found === -1 && retries > 0 && !breakEarly) {
|
|
26
|
-
return new Promise((resolve) => {
|
|
27
|
-
setTimeout(async () => {
|
|
28
|
-
const result = detectDialog(tab, retries - 1, rules);
|
|
29
|
-
resolve(result);
|
|
30
|
-
}, 500);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return found > -1 ? rules[found] : null;
|
|
34
|
-
}
|
package/lib/hider.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// hide rules not specific to a single CMP rule
|
|
2
|
-
const globalHidden = [
|
|
3
|
-
"#didomi-popup,.didomi-popup-container,.didomi-popup-notice,.didomi-consent-popup-preferences,#didomi-notice,.didomi-popup-backdrop,.didomi-screen-medium",
|
|
4
|
-
];
|
|
5
|
-
export default async function prehideElements(tab, rules) {
|
|
6
|
-
const selectors = rules.reduce((selectorList, rule) => {
|
|
7
|
-
if (rule.prehideSelectors) {
|
|
8
|
-
return [...selectorList, ...rule.prehideSelectors];
|
|
9
|
-
}
|
|
10
|
-
return selectorList;
|
|
11
|
-
}, globalHidden);
|
|
12
|
-
await tab.hideElements(selectors, undefined, 'opacity');
|
|
13
|
-
}
|
package/lib/hider.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AutoCMP, TabActor } from './types';
|
|
2
|
-
|
|
3
|
-
// hide rules not specific to a single CMP rule
|
|
4
|
-
const globalHidden = [
|
|
5
|
-
"#didomi-popup,.didomi-popup-container,.didomi-popup-notice,.didomi-consent-popup-preferences,#didomi-notice,.didomi-popup-backdrop,.didomi-screen-medium",
|
|
6
|
-
]
|
|
7
|
-
|
|
8
|
-
export default async function prehideElements(tab: TabActor, rules: AutoCMP[]): Promise<void> {
|
|
9
|
-
const selectors = rules.reduce((selectorList, rule) => {
|
|
10
|
-
if (rule.prehideSelectors) {
|
|
11
|
-
return [...selectorList, ...rule.prehideSelectors];
|
|
12
|
-
}
|
|
13
|
-
return selectorList;
|
|
14
|
-
}, globalHidden);
|
|
15
|
-
await tab.hideElements(selectors, undefined, 'opacity');
|
|
16
|
-
}
|
package/lib/index.js
DELETED
package/lib/messages.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
export type ContentScriptMessage =
|
|
2
|
-
| ClickMessage
|
|
3
|
-
| ElemExistsMessage
|
|
4
|
-
| ElemVisibleMessage
|
|
5
|
-
| GetAttributeMessage
|
|
6
|
-
| EvalMessage
|
|
7
|
-
| HideMessage
|
|
8
|
-
| UndoHideMessage
|
|
9
|
-
| MatchesMessage
|
|
10
|
-
| ActionMessage;
|
|
11
|
-
|
|
12
|
-
export type HideMethod = 'display' | 'opacity';
|
|
13
|
-
|
|
14
|
-
type ClickMessage = {
|
|
15
|
-
type: "click";
|
|
16
|
-
selector: string;
|
|
17
|
-
all?: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type ElemExistsMessage = {
|
|
21
|
-
type: "elemExists";
|
|
22
|
-
selector: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type ElemVisibleMessage = {
|
|
26
|
-
type: "elemVisible";
|
|
27
|
-
selector: string;
|
|
28
|
-
check?: "any" | "none" | "all";
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type GetAttributeMessage = {
|
|
32
|
-
type: "getAttribute";
|
|
33
|
-
selector: string;
|
|
34
|
-
attribute: string;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type EvalMessage = {
|
|
38
|
-
type: "eval";
|
|
39
|
-
script: string;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
type HideMessage = {
|
|
43
|
-
type: "hide";
|
|
44
|
-
selectors: string[];
|
|
45
|
-
method: HideMethod;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
type UndoHideMessage = {
|
|
49
|
-
type: "undohide"
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
type MatchesMessage = {
|
|
53
|
-
type: "matches";
|
|
54
|
-
config: any;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
type ActionMessage = {
|
|
58
|
-
type: "executeAction";
|
|
59
|
-
config: any;
|
|
60
|
-
param: any;
|
|
61
|
-
};
|
package/lib/node.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import Tab from './puppet/tab';
|
|
2
|
-
import detectDialog from './detector';
|
|
3
|
-
import TabConsent from './tabwrapper';
|
|
4
|
-
import prehideElements from './hider';
|
|
5
|
-
export * from './index';
|
|
6
|
-
export { ConsentOMaticCMP } from './consentomatic/index';
|
|
7
|
-
export { Tab, detectDialog, TabConsent, };
|
|
8
|
-
export function attachToPage(page, url, rules, retries = 1, prehide = true) {
|
|
9
|
-
const frames = {
|
|
10
|
-
0: page.mainFrame(),
|
|
11
|
-
};
|
|
12
|
-
const tab = new Tab(page, url, frames);
|
|
13
|
-
async function onFrame(frame) {
|
|
14
|
-
const allFrames = await page.frames();
|
|
15
|
-
allFrames.forEach((frame, frameId) => {
|
|
16
|
-
const frameMatch = rules.findIndex(r => r.detectFrame(tab, {
|
|
17
|
-
url: frame.url(),
|
|
18
|
-
}));
|
|
19
|
-
if (frameMatch > -1) {
|
|
20
|
-
tab.frame = {
|
|
21
|
-
type: rules[frameMatch].name,
|
|
22
|
-
url: frame.url(),
|
|
23
|
-
id: frameId,
|
|
24
|
-
};
|
|
25
|
-
frames[frameId] = frame;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
page.on('framenavigated', onFrame);
|
|
30
|
-
page.frames().forEach(onFrame);
|
|
31
|
-
if (prehide) {
|
|
32
|
-
prehideElements(tab, rules);
|
|
33
|
-
}
|
|
34
|
-
return new TabConsent(tab, detectDialog(tab, retries, rules));
|
|
35
|
-
}
|
package/lib/node.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import Tab from './puppet/tab';
|
|
2
|
-
import detectDialog from './detector';
|
|
3
|
-
import TabConsent from './tabwrapper';
|
|
4
|
-
import { AutoCMP } from './types';
|
|
5
|
-
import prehideElements from './hider';
|
|
6
|
-
|
|
7
|
-
export * from './index';
|
|
8
|
-
export { ConsentOMaticCMP } from './consentomatic/index';
|
|
9
|
-
export {
|
|
10
|
-
Tab,
|
|
11
|
-
detectDialog,
|
|
12
|
-
TabConsent,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function attachToPage(page: any, url: string, rules: AutoCMP[], retries = 1, prehide = true) {
|
|
16
|
-
const frames: { [id: number]: any } = {
|
|
17
|
-
0: page.mainFrame(),
|
|
18
|
-
};
|
|
19
|
-
const tab = new Tab(page, url, frames);
|
|
20
|
-
|
|
21
|
-
async function onFrame(frame: any) {
|
|
22
|
-
const allFrames: any[] = await page.frames();
|
|
23
|
-
allFrames.forEach((frame, frameId) => {
|
|
24
|
-
const frameMatch = rules.findIndex(r => r.detectFrame(tab, {
|
|
25
|
-
url: frame.url(),
|
|
26
|
-
}));
|
|
27
|
-
if (frameMatch > -1) {
|
|
28
|
-
tab.frame = {
|
|
29
|
-
type: rules[frameMatch].name,
|
|
30
|
-
url: frame.url(),
|
|
31
|
-
id: frameId,
|
|
32
|
-
};
|
|
33
|
-
frames[frameId] = frame;
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
page.on('framenavigated', onFrame);
|
|
38
|
-
page.frames().forEach(onFrame);
|
|
39
|
-
if (prehide) {
|
|
40
|
-
prehideElements(tab, rules);
|
|
41
|
-
}
|
|
42
|
-
return new TabConsent(tab, detectDialog(tab, retries, rules));
|
|
43
|
-
}
|
package/lib/puppet/tab.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { waitFor } from '../cmps/base';
|
|
2
|
-
import Tools from '../web/consentomatic/tools';
|
|
3
|
-
import { matches } from '../web/consentomatic/index';
|
|
4
|
-
import { hideElementsUtil, getStyleElementUtil } from '../web/content-utils';
|
|
5
|
-
const DEBUG = false;
|
|
6
|
-
export default class Tab {
|
|
7
|
-
constructor(page, url, frames) {
|
|
8
|
-
// puppeteer doesn't have tab IDs
|
|
9
|
-
this.id = 1;
|
|
10
|
-
this.page = page;
|
|
11
|
-
this.url = url;
|
|
12
|
-
this.frames = frames;
|
|
13
|
-
this._utilsSnippet = `
|
|
14
|
-
${getStyleElementUtil.toString()}
|
|
15
|
-
${hideElementsUtil.toString()}
|
|
16
|
-
`;
|
|
17
|
-
}
|
|
18
|
-
async elementExists(selector, frameId = 0) {
|
|
19
|
-
const elements = await this.frames[frameId].$$(selector);
|
|
20
|
-
DEBUG && console.log('[exists]', selector, elements.length > 0);
|
|
21
|
-
return elements.length > 0;
|
|
22
|
-
}
|
|
23
|
-
async clickElement(selector, frameId = 0) {
|
|
24
|
-
if (await this.elementExists(selector, frameId)) {
|
|
25
|
-
try {
|
|
26
|
-
const result = await this.frames[frameId].evaluate((s) => {
|
|
27
|
-
try {
|
|
28
|
-
document.querySelector(s).click();
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
return e.toString();
|
|
33
|
-
}
|
|
34
|
-
}, selector);
|
|
35
|
-
DEBUG && console.log('[click]', selector, result);
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
async clickElements(selector, frameId = 0) {
|
|
45
|
-
const elements = await this.frames[frameId].$$(selector);
|
|
46
|
-
DEBUG && console.log('[click all]', selector);
|
|
47
|
-
await this.frames[frameId].evaluate((s) => {
|
|
48
|
-
const elem = document.querySelectorAll(s);
|
|
49
|
-
elem.forEach(e => e.click());
|
|
50
|
-
}, selector);
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
async elementsAreVisible(selector, check, frameId = 0) {
|
|
54
|
-
if (!await this.elementExists(selector, frameId)) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
const visible = await this.frames[frameId].$$eval(selector, (nodes) => nodes.map((n) => n.offsetParent !== null || window.getComputedStyle(n).display !== "none"));
|
|
58
|
-
DEBUG && console.log('[visible]', selector, check, visible);
|
|
59
|
-
if (visible.length === 0) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
else if (check === 'any') {
|
|
63
|
-
return visible.some(r => r);
|
|
64
|
-
}
|
|
65
|
-
else if (check === 'none') {
|
|
66
|
-
return visible.every(r => !r);
|
|
67
|
-
}
|
|
68
|
-
return visible.every(r => r);
|
|
69
|
-
}
|
|
70
|
-
async getAttribute(selector, attribute, frameId = 0) {
|
|
71
|
-
const elem = await this.frames[frameId].$(selector);
|
|
72
|
-
if (elem) {
|
|
73
|
-
return (await elem.getProperty(attribute)).jsonValue();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
async eval(script, frameId = 0) {
|
|
77
|
-
const result = await this.frames[frameId].evaluate(script);
|
|
78
|
-
DEBUG && console.log('[eval]', script, result);
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
async waitForElement(selector, timeout, frameId = 0) {
|
|
82
|
-
const interval = 200;
|
|
83
|
-
const times = Math.ceil(timeout / interval);
|
|
84
|
-
return waitFor(() => this.elementExists(selector, frameId), times, interval);
|
|
85
|
-
}
|
|
86
|
-
async waitForThenClick(selector, timeout, frameId = 0) {
|
|
87
|
-
if (await this.waitForElement(selector, timeout, frameId)) {
|
|
88
|
-
return await this.clickElement(selector, frameId);
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
async hideElements(selectors, frameId = 0, method = 'display') {
|
|
93
|
-
return await this.frames[frameId].evaluate(`(() => {
|
|
94
|
-
${this._utilsSnippet}
|
|
95
|
-
return hideElementsUtil(${JSON.stringify(selectors)}, '${method}');
|
|
96
|
-
})()`);
|
|
97
|
-
}
|
|
98
|
-
undoHideElements(frameId) {
|
|
99
|
-
return Promise.resolve(true);
|
|
100
|
-
}
|
|
101
|
-
async goto(url) {
|
|
102
|
-
return this.page.goto(url);
|
|
103
|
-
}
|
|
104
|
-
wait(ms) {
|
|
105
|
-
return new Promise((resolve) => {
|
|
106
|
-
setTimeout(() => resolve(true), ms);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
matches(options) {
|
|
110
|
-
const script = `(() => {
|
|
111
|
-
const Tools = ${Tools.toString()};
|
|
112
|
-
const matches = ${matches.toString()};
|
|
113
|
-
return matches(${JSON.stringify(options)})
|
|
114
|
-
})();
|
|
115
|
-
`;
|
|
116
|
-
return this.frames[0].evaluate(script);
|
|
117
|
-
}
|
|
118
|
-
executeAction(config, param) {
|
|
119
|
-
throw new Error("Method not implemented.");
|
|
120
|
-
}
|
|
121
|
-
}
|