@duckduckgo/autoconsent 4.0.0 → 4.1.1
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/.github/ISSUE_TEMPLATE/broken-site-issue.md +29 -0
- package/CHANGELOG.md +39 -0
- package/Jenkinsfile +2 -2
- package/api.md +10 -1
- package/dist/addon-firefox/background.bundle.js +312 -1
- package/dist/addon-firefox/content.bundle.js +1912 -1
- package/dist/addon-firefox/manifest.json +1 -1
- package/dist/addon-firefox/rules.json +174 -38
- package/dist/addon-mv3/background.bundle.js +312 -1
- package/dist/addon-mv3/content.bundle.js +1912 -1
- package/dist/addon-mv3/devtools/background.html +10 -0
- package/dist/addon-mv3/devtools/bulma.min.css +1 -0
- package/dist/addon-mv3/devtools/loader.js +2 -0
- package/dist/addon-mv3/devtools/panel.html +88 -0
- package/dist/addon-mv3/devtools/panel.js +148 -0
- package/dist/addon-mv3/devtools/panel.ts +145 -0
- package/dist/addon-mv3/manifest.json +5 -3
- package/dist/addon-mv3/popup.bundle.js +173 -1
- package/dist/addon-mv3/popup.html +14 -0
- package/dist/addon-mv3/rules.json +174 -38
- package/dist/autoconsent.cjs.js +1 -1
- package/dist/autoconsent.esm.js +1 -1
- package/dist/autoconsent.playwright.js +1 -1
- package/lib/cmps/airbnb.ts +4 -0
- package/lib/cmps/base.ts +8 -0
- package/lib/cmps/consentmanager.ts +4 -0
- package/lib/cmps/consentomatic.ts +1 -0
- package/lib/cmps/conversant.ts +4 -0
- package/lib/cmps/cookiebot.ts +4 -0
- package/lib/cmps/evidon.ts +4 -0
- package/lib/cmps/klaro.ts +4 -0
- package/lib/cmps/onetrust.ts +4 -0
- package/lib/cmps/sourcepoint-frame.ts +4 -0
- package/lib/cmps/tiktok.ts +4 -0
- package/lib/cmps/trustarc-frame.ts +4 -0
- package/lib/cmps/trustarc-top.ts +4 -0
- package/lib/cmps/uniconsent.ts +4 -0
- package/lib/eval-handler.ts +2 -6
- package/lib/messages.ts +44 -13
- package/lib/random.ts +6 -0
- package/lib/rules.ts +2 -1
- package/lib/types.ts +27 -0
- package/lib/web.ts +127 -82
- package/package.json +4 -3
- package/playwright/runner.ts +1 -0
- package/rollup.config.js +18 -5
- package/rules/autoconsent/ausopen.json +2 -2
- package/rules/autoconsent/baden-wuerttemberg-de.json +1 -0
- package/rules/autoconsent/cc-banner.json +1 -0
- package/rules/autoconsent/complianz-notice.json +1 -0
- package/rules/autoconsent/cookie-notice.json +2 -1
- package/rules/autoconsent/dsgvo.json +1 -0
- package/rules/autoconsent/eu-cookie-compliance.json +1 -1
- package/rules/autoconsent/eu-cookie-law.json +1 -0
- package/rules/autoconsent/ezoic.json +1 -0
- package/rules/autoconsent/generic-cosmetic.json +9 -0
- package/rules/autoconsent/indeed-com.json +9 -0
- package/rules/autoconsent/jquery-cookiebar.json +1 -0
- package/rules/autoconsent/marksandspencer.json +2 -2
- package/rules/autoconsent/notice-cookie.json +1 -0
- package/rules/autoconsent/osano.json +1 -0
- package/rules/autoconsent/pornhub.json +12 -0
- package/rules/autoconsent/testcmp-cosmetic.json +18 -0
- package/rules/autoconsent/uk-cookie-consent.json +1 -0
- package/rules/autoconsent/xnxx-com.json +9 -0
- package/rules/rules.json +174 -38
- package/tests/borlabs.spec.ts +1 -1
- package/tests/complianz-optin.spec.ts +4 -4
- package/tests/cookie-notice.spec.ts +3 -1
- package/tests/cookiebot.spec.ts +0 -4
- package/tests/cookieinformation.spec.ts +0 -1
- package/tests/dsgvo.spec.ts +4 -1
- package/tests/evidon.spec.ts +2 -4
- package/tests/ezoic.spec.ts +0 -1
- package/tests/fundingchoices.spec.ts +0 -1
- package/tests/generic-cosmetic.spec.ts +11 -0
- package/tests/indeed.spec.ts +7 -0
- package/tests/moove.spec.ts +0 -6
- package/tests/pornhub.spec.ts +7 -0
- package/tests/pubtech.spec.ts +0 -1
- package/tests/reddit.spec.ts +1 -1
- package/tests/sibbo.spec.ts +0 -1
- package/tests/sirdata.spec.ts +0 -1
- package/tests/testcmp-banner.spec.ts +5 -0
- package/tests/trustarc.spec.ts +0 -2
- package/tests/uniconsent.spec.ts +1 -1
- package/tests/usercentrics-api.spec.ts +1 -0
- package/tests/usercentrics-button.spec.ts +0 -1
- package/tests/xnxx.spec.ts +8 -0
- package/tsconfig.json +2 -1
- package/rules/autoconsent/motor-talk-de.json +0 -24
- package/tests/motor-talk.spec.ts +0 -7
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Broken site issue
|
|
3
|
+
about: Report a site where autoconsent is not working
|
|
4
|
+
title: 'Site breakage: [SITE]'
|
|
5
|
+
labels: broken site
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Description
|
|
11
|
+
|
|
12
|
+
The popup on [site]
|
|
13
|
+
- [ ] is not detected
|
|
14
|
+
- [ ] is not dismissed properly
|
|
15
|
+
- [ ] other (elaborate below)
|
|
16
|
+
|
|
17
|
+
**Tested on**
|
|
18
|
+
- [ ] DuckDuckGo macOS browser
|
|
19
|
+
- [ ] DuckDuckGo Windows browser
|
|
20
|
+
- [ ] DuckDuckGo Android browser
|
|
21
|
+
- [ ] DuckDuckGo iOS browser
|
|
22
|
+
- [ ] Chrome browser extension
|
|
23
|
+
- [ ] Firefox browser extension
|
|
24
|
+
|
|
25
|
+
**Tested from country**:
|
|
26
|
+
|
|
27
|
+
**Autoconsent version**:
|
|
28
|
+
|
|
29
|
+
**Screenshot (optional)**
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
# v4.1.1 (Tue Jan 24 2023)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- Add a test cosmetic rule [#91](https://github.com/duckduckgo/autoconsent/pull/91) ([@muodov](https://github.com/muodov))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Maxim Tsoy ([@muodov](https://github.com/muodov))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# v4.1.0 (Tue Jan 17 2023)
|
|
14
|
+
|
|
15
|
+
#### 🚀 Enhancement
|
|
16
|
+
|
|
17
|
+
- Cosmetic rules [#67](https://github.com/duckduckgo/autoconsent/pull/67) ([@muodov](https://github.com/muodov))
|
|
18
|
+
- Extension Devtools [#42](https://github.com/duckduckgo/autoconsent/pull/42) ([@sammacbeth](https://github.com/sammacbeth) [@muodov](https://github.com/muodov))
|
|
19
|
+
|
|
20
|
+
#### 🐛 Bug Fix
|
|
21
|
+
|
|
22
|
+
- Cleaning up invalid tests [#49](https://github.com/duckduckgo/autoconsent/pull/49) ([@sammacbeth](https://github.com/sammacbeth))
|
|
23
|
+
- Fix type warning on bundle. [#83](https://github.com/duckduckgo/autoconsent/pull/83) ([@sammacbeth](https://github.com/sammacbeth))
|
|
24
|
+
- Add broken site issue template [#69](https://github.com/duckduckgo/autoconsent/pull/69) ([@sammacbeth](https://github.com/sammacbeth))
|
|
25
|
+
|
|
26
|
+
#### 🔩 Dependency Updates
|
|
27
|
+
|
|
28
|
+
- Bump @rollup/plugin-json from 5.0.2 to 6.0.0 [#72](https://github.com/duckduckgo/autoconsent/pull/72) ([@dependabot[bot]](https://github.com/dependabot[bot]))
|
|
29
|
+
- Bump @types/chrome from 0.0.204 to 0.0.206 [#85](https://github.com/duckduckgo/autoconsent/pull/85) ([@dependabot[bot]](https://github.com/dependabot[bot]))
|
|
30
|
+
- Bump eslint from 8.29.0 to 8.31.0 [#84](https://github.com/duckduckgo/autoconsent/pull/84) ([@dependabot[bot]](https://github.com/dependabot[bot]))
|
|
31
|
+
|
|
32
|
+
#### Authors: 3
|
|
33
|
+
|
|
34
|
+
- [@dependabot[bot]](https://github.com/dependabot[bot])
|
|
35
|
+
- Maxim Tsoy ([@muodov](https://github.com/muodov))
|
|
36
|
+
- Sam Macbeth ([@sammacbeth](https://github.com/sammacbeth))
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
1
40
|
# v4.0.0 (Wed Dec 14 2022)
|
|
2
41
|
|
|
3
42
|
#### 💥 Breaking Change
|
package/Jenkinsfile
CHANGED
|
@@ -3,7 +3,7 @@ def runPlaywrightTests(resultDir, browser, grep) {
|
|
|
3
3
|
timeout(20) {
|
|
4
4
|
sh 'mkdir -p ./test-results'
|
|
5
5
|
sh """
|
|
6
|
-
PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml npx playwright test --project $browser --reporter=junit --
|
|
6
|
+
PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml npx playwright test --project $browser --reporter=junit --grep "$grep"|| true
|
|
7
7
|
"""
|
|
8
8
|
}
|
|
9
9
|
} finally {
|
|
@@ -27,7 +27,7 @@ pipeline {
|
|
|
27
27
|
agent { label 'autoconsent-crawler' }
|
|
28
28
|
parameters {
|
|
29
29
|
string(name: 'TEST_RESULT_ROOT', defaultValue: '/mnt/efs/users/smacbeth/autoconsent/ci', description: 'Where test results and configuration are stored')
|
|
30
|
-
choice(name: 'BROWSER', choices: ['
|
|
30
|
+
choice(name: 'BROWSER', choices: ['chrome', 'webkit', 'iphoneSE', 'firefox'], description: 'Browser')
|
|
31
31
|
string(name: 'GREP', defaultValue: '', description: 'filter for tests matching a specific string')
|
|
32
32
|
}
|
|
33
33
|
environment {
|
package/api.md
CHANGED
|
@@ -77,6 +77,10 @@ sequenceDiagram
|
|
|
77
77
|
Note right of CS: execute self-test rules
|
|
78
78
|
CS -->>- BG: selfTestResult
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
opt periodically
|
|
82
|
+
CS ->> BG: report
|
|
83
|
+
end
|
|
80
84
|
```
|
|
81
85
|
|
|
82
86
|
### Asynchronous eval rules
|
|
@@ -101,4 +105,9 @@ sequenceDiagram
|
|
|
101
105
|
deactivate BG
|
|
102
106
|
|
|
103
107
|
Note over CS: Continue rule execution (or fail with timeout)
|
|
104
|
-
```
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Report messages
|
|
111
|
+
|
|
112
|
+
The content-script periodically sends `report` messages which give a summary of the status of what has run
|
|
113
|
+
so far in a particular frame. The exact contents of the report messages can be found in [type definitions](/lib/messages.ts).
|
|
@@ -1 +1,312 @@
|
|
|
1
|
-
|
|
1
|
+
(function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const manifestVersion = chrome.runtime.getManifest().manifest_version;
|
|
5
|
+
// Storage abstraction: MV2 keeps everything in memory, MV3 uses chrome.storage
|
|
6
|
+
const storage = {};
|
|
7
|
+
async function storageSet(obj) {
|
|
8
|
+
if (manifestVersion === 2) {
|
|
9
|
+
Object.assign(storage, obj);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
return chrome.storage.local.set(obj);
|
|
13
|
+
}
|
|
14
|
+
async function storageGet(key) {
|
|
15
|
+
if (key === null) {
|
|
16
|
+
if (manifestVersion === 2) {
|
|
17
|
+
return storage;
|
|
18
|
+
}
|
|
19
|
+
return await chrome.storage.local.get(null);
|
|
20
|
+
}
|
|
21
|
+
if (manifestVersion === 2) {
|
|
22
|
+
return storage[key];
|
|
23
|
+
}
|
|
24
|
+
return (await chrome.storage.local.get(key))?.[key];
|
|
25
|
+
}
|
|
26
|
+
async function storageRemove(key) {
|
|
27
|
+
if (manifestVersion === 2) {
|
|
28
|
+
delete storage[key];
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return chrome.storage.local.remove(key);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function showOptOutStatus(tabId, status, cmp = '') {
|
|
35
|
+
let title = "";
|
|
36
|
+
let icon = "icons/cookie-idle.png";
|
|
37
|
+
if (status === "success") {
|
|
38
|
+
title = `Opt out successful! (${cmp})`;
|
|
39
|
+
icon = "icons/party.png";
|
|
40
|
+
}
|
|
41
|
+
else if (status === "complete") {
|
|
42
|
+
title = `Opt out complete! (${cmp})`;
|
|
43
|
+
icon = "icons/tick.png";
|
|
44
|
+
}
|
|
45
|
+
else if (status === "working") {
|
|
46
|
+
title = `Processing... (${cmp})`;
|
|
47
|
+
icon = "icons/cog.png";
|
|
48
|
+
}
|
|
49
|
+
else if (status === "verified") {
|
|
50
|
+
title = `Verified (${cmp})`;
|
|
51
|
+
icon = "icons/verified.png";
|
|
52
|
+
}
|
|
53
|
+
else if (status === "idle") {
|
|
54
|
+
title = "Idle";
|
|
55
|
+
icon = "icons/cookie-idle.png";
|
|
56
|
+
}
|
|
57
|
+
else if (status === "available") {
|
|
58
|
+
title = `Click to opt out (${cmp})`;
|
|
59
|
+
icon = "icons/cookie.png";
|
|
60
|
+
}
|
|
61
|
+
const action = chrome.action || chrome.pageAction;
|
|
62
|
+
if (chrome.pageAction) {
|
|
63
|
+
chrome.pageAction.show(tabId);
|
|
64
|
+
}
|
|
65
|
+
await action.setTitle({
|
|
66
|
+
tabId,
|
|
67
|
+
title,
|
|
68
|
+
});
|
|
69
|
+
await action.setIcon({
|
|
70
|
+
tabId,
|
|
71
|
+
path: icon,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Mapping of tabIds to Port connections to open devtools panels.
|
|
77
|
+
* This is kept in memory, as the values are only relevant while the background service worker is
|
|
78
|
+
* alive. Once the service worker stops, Ports to devtools will be severed, and the panel will
|
|
79
|
+
* reestablish the connection.
|
|
80
|
+
*/
|
|
81
|
+
const openDevToolsPanels = new Map();
|
|
82
|
+
async function loadRules() {
|
|
83
|
+
const res = await fetch("./rules.json");
|
|
84
|
+
storageSet({
|
|
85
|
+
rules: await res.json(),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function initConfig() {
|
|
89
|
+
console.log('init sw');
|
|
90
|
+
const storedConfig = await storageGet('config');
|
|
91
|
+
console.log('storedConfig', storedConfig);
|
|
92
|
+
if (!storedConfig) {
|
|
93
|
+
console.log('init config');
|
|
94
|
+
const defaultConfig = {
|
|
95
|
+
enabled: true,
|
|
96
|
+
autoAction: 'optOut',
|
|
97
|
+
disabledCmps: [],
|
|
98
|
+
enablePrehide: true,
|
|
99
|
+
enableCosmeticRules: true,
|
|
100
|
+
detectRetries: 20,
|
|
101
|
+
};
|
|
102
|
+
await storageSet({
|
|
103
|
+
config: defaultConfig,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else if (typeof storedConfig.enableCosmeticRules === 'undefined') { // upgrade from old versions
|
|
107
|
+
storedConfig.enableCosmeticRules = true;
|
|
108
|
+
await storageSet({
|
|
109
|
+
config: storedConfig,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function evalInTab(tabId, frameId, code) {
|
|
114
|
+
if (manifestVersion === 2) {
|
|
115
|
+
return new Promise((resolve) => {
|
|
116
|
+
chrome.tabs.executeScript(tabId, {
|
|
117
|
+
frameId,
|
|
118
|
+
code: `!!window.eval(decodeURIComponent("${encodeURIComponent(code)}"))`
|
|
119
|
+
}, (resultArr) => {
|
|
120
|
+
resolve([{
|
|
121
|
+
result: resultArr[0],
|
|
122
|
+
frameId,
|
|
123
|
+
}]);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return chrome.scripting.executeScript({
|
|
128
|
+
target: {
|
|
129
|
+
tabId,
|
|
130
|
+
frameIds: [frameId],
|
|
131
|
+
},
|
|
132
|
+
world: "MAIN",
|
|
133
|
+
args: [code],
|
|
134
|
+
func: (code) => {
|
|
135
|
+
try {
|
|
136
|
+
return window.eval(code);
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
// ignore CSP errors
|
|
140
|
+
console.warn('eval error', code, e);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async function getTabReports(tabId) {
|
|
147
|
+
const storageKey = `reports-${tabId}`;
|
|
148
|
+
return (await chrome.storage.session.get(storageKey))[storageKey] || {};
|
|
149
|
+
}
|
|
150
|
+
async function updateTabReports(tabId, frameId, msg) {
|
|
151
|
+
const reportsForTab = await getTabReports(tabId);
|
|
152
|
+
reportsForTab[frameId] = msg;
|
|
153
|
+
await chrome.storage.session.set({ [`reports-${tabId}`]: reportsForTab });
|
|
154
|
+
}
|
|
155
|
+
chrome.runtime.onInstalled.addListener(() => {
|
|
156
|
+
loadRules();
|
|
157
|
+
initConfig();
|
|
158
|
+
});
|
|
159
|
+
if (manifestVersion === 2) {
|
|
160
|
+
// always load rules on startup in MV2
|
|
161
|
+
loadRules();
|
|
162
|
+
initConfig();
|
|
163
|
+
}
|
|
164
|
+
chrome.tabs.onRemoved.addListener((tabId) => {
|
|
165
|
+
storageRemove(`detected${tabId}`);
|
|
166
|
+
});
|
|
167
|
+
chrome.runtime.onMessage.addListener(async (msg, sender) => {
|
|
168
|
+
const tabId = sender.tab.id;
|
|
169
|
+
const frameId = sender.frameId;
|
|
170
|
+
const rules = await storageGet("rules");
|
|
171
|
+
const autoconsentConfig = await storageGet('config');
|
|
172
|
+
switch (msg.type) {
|
|
173
|
+
case "init":
|
|
174
|
+
if (frameId === 0) {
|
|
175
|
+
await showOptOutStatus(tabId, 'idle');
|
|
176
|
+
}
|
|
177
|
+
chrome.tabs.sendMessage(tabId, {
|
|
178
|
+
type: "initResp",
|
|
179
|
+
rules,
|
|
180
|
+
config: autoconsentConfig,
|
|
181
|
+
}, {
|
|
182
|
+
frameId,
|
|
183
|
+
});
|
|
184
|
+
break;
|
|
185
|
+
case "eval":
|
|
186
|
+
evalInTab(tabId, frameId, msg.code).then(([result]) => {
|
|
187
|
+
chrome.tabs.sendMessage(tabId, {
|
|
188
|
+
id: msg.id,
|
|
189
|
+
type: "evalResp",
|
|
190
|
+
result: result.result,
|
|
191
|
+
}, {
|
|
192
|
+
frameId,
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
break;
|
|
196
|
+
case "popupFound":
|
|
197
|
+
await showOptOutStatus(tabId, "available", msg.cmp);
|
|
198
|
+
storageSet({
|
|
199
|
+
[`detected${tabId}`]: frameId,
|
|
200
|
+
});
|
|
201
|
+
break;
|
|
202
|
+
case "optOutResult":
|
|
203
|
+
case "optInResult":
|
|
204
|
+
if (msg.result) {
|
|
205
|
+
await showOptOutStatus(tabId, "working", msg.cmp);
|
|
206
|
+
if (msg.scheduleSelfTest) {
|
|
207
|
+
await storageSet({
|
|
208
|
+
[`selfTest${tabId}`]: frameId,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
case "selfTestResult":
|
|
214
|
+
if (msg.result) {
|
|
215
|
+
await showOptOutStatus(tabId, "verified", msg.cmp);
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
case "autoconsentDone": {
|
|
219
|
+
await showOptOutStatus(tabId, "success", msg.cmp);
|
|
220
|
+
// sometimes self-test needs to be done in another frame
|
|
221
|
+
const selfTestKey = `selfTest${tabId}`;
|
|
222
|
+
const selfTestFrameId = (await chrome.storage.local.get(selfTestKey))?.[selfTestKey];
|
|
223
|
+
if (typeof selfTestFrameId === 'number') {
|
|
224
|
+
storageRemove(selfTestKey);
|
|
225
|
+
chrome.tabs.sendMessage(tabId, {
|
|
226
|
+
type: "selfTest",
|
|
227
|
+
}, {
|
|
228
|
+
frameId: selfTestFrameId,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case "autoconsentError":
|
|
234
|
+
console.error('Error:', msg.details);
|
|
235
|
+
break;
|
|
236
|
+
case "report":
|
|
237
|
+
if (sender.tab && openDevToolsPanels.has(sender.tab.id)) {
|
|
238
|
+
openDevToolsPanels.get(sender.tab.id).postMessage({
|
|
239
|
+
tabId: sender.tab.id,
|
|
240
|
+
frameId: sender.frameId,
|
|
241
|
+
...msg,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
updateTabReports(sender.tab.id, sender.frameId, msg);
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
if (manifestVersion === 2) { // MV3 handles this inside the popup
|
|
249
|
+
chrome.pageAction.onClicked.addListener(async (tab) => {
|
|
250
|
+
const tabId = tab.id;
|
|
251
|
+
const detectedKey = `detected${tabId}`;
|
|
252
|
+
const frameId = await storageGet(detectedKey);
|
|
253
|
+
if (typeof frameId === 'number') {
|
|
254
|
+
storageRemove(detectedKey);
|
|
255
|
+
await showOptOutStatus(tabId, "working");
|
|
256
|
+
chrome.tabs.sendMessage(tabId, {
|
|
257
|
+
type: "optOut",
|
|
258
|
+
}, {
|
|
259
|
+
frameId,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
// Communicate with devtools panels
|
|
265
|
+
chrome.runtime.onConnect.addListener(function (devToolsConnection) {
|
|
266
|
+
if (devToolsConnection.name.startsWith('instance-')) {
|
|
267
|
+
// connection from an autoconsent instance - used to detect frame destruction
|
|
268
|
+
const tabId = devToolsConnection.sender?.tab?.id;
|
|
269
|
+
const instanceId = devToolsConnection.name.slice('instance-'.length);
|
|
270
|
+
if (tabId && instanceId) {
|
|
271
|
+
devToolsConnection.onDisconnect.addListener(() => {
|
|
272
|
+
if (openDevToolsPanels.has(tabId)) {
|
|
273
|
+
openDevToolsPanels.get(tabId).postMessage({
|
|
274
|
+
type: 'instanceTerminated',
|
|
275
|
+
tabId,
|
|
276
|
+
instanceId,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
// remove stored frame data
|
|
280
|
+
updateTabReports(tabId, devToolsConnection.sender.frameId, undefined);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else if (devToolsConnection.name === 'devtools-panel') {
|
|
285
|
+
let tabId = -1;
|
|
286
|
+
// add the listener
|
|
287
|
+
devToolsConnection.onMessage.addListener(async (message) => {
|
|
288
|
+
tabId = message.tabId;
|
|
289
|
+
if (message.type === 'init') {
|
|
290
|
+
// save the message channel for this tab
|
|
291
|
+
openDevToolsPanels.set(tabId, devToolsConnection);
|
|
292
|
+
// dump data cached in bg to the panel
|
|
293
|
+
const reportsForTab = await getTabReports(tabId);
|
|
294
|
+
Object.keys(reportsForTab || {}).forEach((frameId) => {
|
|
295
|
+
devToolsConnection.postMessage({
|
|
296
|
+
tabId,
|
|
297
|
+
frameId,
|
|
298
|
+
...reportsForTab[parseInt(frameId, 10)]
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
devToolsConnection.onDisconnect.addListener(function () {
|
|
304
|
+
openDevToolsPanels.delete(tabId);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
chrome.tabs.onRemoved.addListener((tabId) => {
|
|
309
|
+
chrome.storage.session.remove(`reports-${tabId}`);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
})();
|