@whotracksme/reporting 5.1.17

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.
Files changed (179) hide show
  1. package/.editorconfig +12 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc +16 -0
  4. package/.github/workflows/release.yml +34 -0
  5. package/.github/workflows/tests.yml +20 -0
  6. package/.prettierrc +9 -0
  7. package/.tool-versions +1 -0
  8. package/CHANGELOG.md +795 -0
  9. package/LICENSE +373 -0
  10. package/README.md +1 -0
  11. package/communication/README.md +11 -0
  12. package/communication/example/index.js +43 -0
  13. package/communication/example/manifest.json +16 -0
  14. package/communication/karma.conf.cjs +19 -0
  15. package/communication/package.json +52 -0
  16. package/communication/rollup.common-config.cjs +17 -0
  17. package/communication/rollup.config.cjs +10 -0
  18. package/communication/src/encoding.js +54 -0
  19. package/communication/src/errors.js +84 -0
  20. package/communication/src/index.js +76 -0
  21. package/communication/src/logger.js +41 -0
  22. package/communication/src/padding.js +60 -0
  23. package/communication/src/proxied-http.js +231 -0
  24. package/communication/src/server-public-key-accessor.js +123 -0
  25. package/communication/src/timestamps.js +37 -0
  26. package/communication/src/trusted-clock.js +58 -0
  27. package/communication/src/utils.js +28 -0
  28. package/communication/src/zlib.js +17 -0
  29. package/communication/test/helpers/in-memory-database.js +43 -0
  30. package/communication/test/server-public-key-accessor.spec.js +135 -0
  31. package/communication/test/utils.spec.js +43 -0
  32. package/package.json +50 -0
  33. package/reporting/TODO.md +2 -0
  34. package/reporting/assets/request/bloom_filter.dat +0 -0
  35. package/reporting/assets/request/update.json +1 -0
  36. package/reporting/example/content.js +11 -0
  37. package/reporting/example/index.js +132 -0
  38. package/reporting/example/inspector/index.html +17 -0
  39. package/reporting/example/inspector/index.js +27 -0
  40. package/reporting/example/manifests/chromium.json +37 -0
  41. package/reporting/example/manifests/firefox.json +35 -0
  42. package/reporting/example/rules.json +62 -0
  43. package/reporting/example/setup.js +1 -0
  44. package/reporting/example/tests/test1.html +10 -0
  45. package/reporting/karma.conf.cjs +22 -0
  46. package/reporting/package.json +63 -0
  47. package/reporting/rollup.common-config.cjs +19 -0
  48. package/reporting/rollup.config.cjs +20 -0
  49. package/reporting/src/LRU.js +149 -0
  50. package/reporting/src/activity-estimator.js +298 -0
  51. package/reporting/src/alive-check.js +139 -0
  52. package/reporting/src/alive-message-generator.js +142 -0
  53. package/reporting/src/bloom-filters.js +345 -0
  54. package/reporting/src/country-provider.js +295 -0
  55. package/reporting/src/cyrb53.js +32 -0
  56. package/reporting/src/digest.js +33 -0
  57. package/reporting/src/doublefetch-page-handler.js +548 -0
  58. package/reporting/src/duplicate-detector.js +233 -0
  59. package/reporting/src/errors.js +84 -0
  60. package/reporting/src/event-listener-queue.js +121 -0
  61. package/reporting/src/fixed-size-cache.js +63 -0
  62. package/reporting/src/hash-detector.js +1526 -0
  63. package/reporting/src/html-parser.js +17 -0
  64. package/reporting/src/http.js +265 -0
  65. package/reporting/src/index.js +14 -0
  66. package/reporting/src/job-scheduler.js +912 -0
  67. package/reporting/src/logger.js +121 -0
  68. package/reporting/src/md5.js +334 -0
  69. package/reporting/src/message-sender.js +51 -0
  70. package/reporting/src/network.js +140 -0
  71. package/reporting/src/new-page-approver.js +119 -0
  72. package/reporting/src/page-aggregator.js +185 -0
  73. package/reporting/src/page-quorum-check-handler.js +200 -0
  74. package/reporting/src/page-structure.js +136 -0
  75. package/reporting/src/pagedb.js +671 -0
  76. package/reporting/src/pages.js +1798 -0
  77. package/reporting/src/patterns-updater.js +310 -0
  78. package/reporting/src/patterns.js +416 -0
  79. package/reporting/src/persisted-bitarray.js +265 -0
  80. package/reporting/src/persisted-hashes.js +189 -0
  81. package/reporting/src/quorum-checker.js +327 -0
  82. package/reporting/src/random.js +39 -0
  83. package/reporting/src/reporting.js +290 -0
  84. package/reporting/src/request/config.js +116 -0
  85. package/reporting/src/request/content-script.js +77 -0
  86. package/reporting/src/request/database.js +147 -0
  87. package/reporting/src/request/dnt.js +24 -0
  88. package/reporting/src/request/hash.js +101 -0
  89. package/reporting/src/request/index.js +874 -0
  90. package/reporting/src/request/page-telemetry.js +42 -0
  91. package/reporting/src/request/qs-whitelist2.js +247 -0
  92. package/reporting/src/request/resources/prob.js +601 -0
  93. package/reporting/src/request/steps/block-rules.js +40 -0
  94. package/reporting/src/request/steps/check-context.js +37 -0
  95. package/reporting/src/request/steps/cookie-context.js +209 -0
  96. package/reporting/src/request/steps/oauth-detector.js +101 -0
  97. package/reporting/src/request/steps/page-logger.js +177 -0
  98. package/reporting/src/request/steps/redirect-tagger.js +75 -0
  99. package/reporting/src/request/steps/subdomain-check.js +34 -0
  100. package/reporting/src/request/steps/token-checker/index.js +189 -0
  101. package/reporting/src/request/steps/token-checker/token-domain.js +129 -0
  102. package/reporting/src/request/steps/token-examiner.js +182 -0
  103. package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +210 -0
  104. package/reporting/src/request/steps/token-telemetry/index.js +234 -0
  105. package/reporting/src/request/steps/token-telemetry/key-pipeline.js +109 -0
  106. package/reporting/src/request/steps/token-telemetry/token-pipeline.js +105 -0
  107. package/reporting/src/request/time.js +73 -0
  108. package/reporting/src/request/utils/bloom-filter-packed.js +107 -0
  109. package/reporting/src/request/utils/chrome-storage-map.js +282 -0
  110. package/reporting/src/request/utils/subject.js +37 -0
  111. package/reporting/src/request/utils/temp-set.js +56 -0
  112. package/reporting/src/request/utils/tlds.js +55 -0
  113. package/reporting/src/request/utils.js +41 -0
  114. package/reporting/src/request-reporter.js +111 -0
  115. package/reporting/src/sanitizer.js +519 -0
  116. package/reporting/src/search-extractor.js +338 -0
  117. package/reporting/src/self-check.js +105 -0
  118. package/reporting/src/seq-executor.js +43 -0
  119. package/reporting/src/session-storage.js +399 -0
  120. package/reporting/src/url-analyzer.js +161 -0
  121. package/reporting/src/url-cleaner.js +60 -0
  122. package/reporting/src/utils/pacemaker.js +279 -0
  123. package/reporting/src/utils/url.js +114 -0
  124. package/reporting/src/utils.js +345 -0
  125. package/reporting/src/webrequest-pipeline/cname-uncloak.js +110 -0
  126. package/reporting/src/webrequest-pipeline/index.js +287 -0
  127. package/reporting/src/webrequest-pipeline/logger.js +14 -0
  128. package/reporting/src/webrequest-pipeline/page-store.js +282 -0
  129. package/reporting/src/webrequest-pipeline/page.js +140 -0
  130. package/reporting/src/webrequest-pipeline/pipeline.js +249 -0
  131. package/reporting/src/webrequest-pipeline/utils/webrequest.js +113 -0
  132. package/reporting/src/webrequest-pipeline/webrequest-context.js +153 -0
  133. package/reporting/test/README.md +2 -0
  134. package/reporting/test/activity-estimator.spec.js +356 -0
  135. package/reporting/test/alive-check.spec.js +156 -0
  136. package/reporting/test/alive-message-generator.spec.js +186 -0
  137. package/reporting/test/country-provider.spec.js +263 -0
  138. package/reporting/test/doublefetch-page-handler.spec.js +818 -0
  139. package/reporting/test/duplicate-detector.spec.js +689 -0
  140. package/reporting/test/helpers/dom-parsers.js +41 -0
  141. package/reporting/test/helpers/fake-session-storage.js +69 -0
  142. package/reporting/test/helpers/fast-check-utils.js +28 -0
  143. package/reporting/test/helpers/fetch-mock.js +57 -0
  144. package/reporting/test/helpers/in-memory-database.js +14 -0
  145. package/reporting/test/helpers/memory-map.js +72 -0
  146. package/reporting/test/helpers/pagedb-mocks.js +41 -0
  147. package/reporting/test/index.js +47 -0
  148. package/reporting/test/job-scheduler.spec.js +691 -0
  149. package/reporting/test/network.spec.js +72 -0
  150. package/reporting/test/page-aggregator.spec.js +104 -0
  151. package/reporting/test/page-quorum-check-handler.spec.js +86 -0
  152. package/reporting/test/pagedb.spec.js +250 -0
  153. package/reporting/test/pages.spec.js +693 -0
  154. package/reporting/test/patterns-updater.spec.js +446 -0
  155. package/reporting/test/patterns.spec.js +751 -0
  156. package/reporting/test/persisted-hashes.spec.js +169 -0
  157. package/reporting/test/reporting.spec.js +205 -0
  158. package/reporting/test/request/database.spec.js +59 -0
  159. package/reporting/test/request/hash.spec.js +108 -0
  160. package/reporting/test/request/index.spec.js +378 -0
  161. package/reporting/test/request/qs-whitelist2.spec.js +189 -0
  162. package/reporting/test/request/steps/check-context.spec.js +51 -0
  163. package/reporting/test/request/steps/oauth-detector.spec.js +339 -0
  164. package/reporting/test/request/test-pages.js +1246 -0
  165. package/reporting/test/request/utils/bloom-filter-packed.spec.js +37 -0
  166. package/reporting/test/request/utils/chrome-storage-map.spec.js +28 -0
  167. package/reporting/test/request/utils/tldts.spec.js +62 -0
  168. package/reporting/test/request/utils.spec.js +168 -0
  169. package/reporting/test/sanitizer.spec.js +1087 -0
  170. package/reporting/test/search-extractor.spec.js +590 -0
  171. package/reporting/test/seq-executor.spec.js +158 -0
  172. package/reporting/test/session-storage.spec.js +400 -0
  173. package/reporting/test/setup.js +24 -0
  174. package/reporting/test/url-analyzer.spec.js +451 -0
  175. package/reporting/test/url-cleaner.spec.js +102 -0
  176. package/reporting/test/utils/pacemaker.spec.js +222 -0
  177. package/reporting/test/utils/url.spec.js +660 -0
  178. package/reporting/test/utils.spec.js +299 -0
  179. package/reporting/test/webrequest-pipeline/pipeline.spec.js +251 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * WhoTracks.Me
3
+ * https://whotracks.me/
4
+ *
5
+ * Copyright 2017-present Ghostery GmbH. All rights reserved.
6
+ *
7
+ * This Source Code Form is subject to the terms of the Mozilla Public
8
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
9
+ * file, You can obtain one at http://mozilla.org/MPL/2.0
10
+ */
11
+
12
+ /**
13
+ * Implements the IndexedDBKeyValueStore interface.
14
+ */
15
+ export default class InMemoryDatabase {
16
+ constructor() {
17
+ this.db = new Map();
18
+ }
19
+
20
+ async open() {}
21
+
22
+ async close() {}
23
+
24
+ async get(key) {
25
+ return this.db.get(key);
26
+ }
27
+
28
+ async set(key, value) {
29
+ this.db.set(key, value);
30
+ }
31
+
32
+ async remove(key) {
33
+ return this.db.delete(key);
34
+ }
35
+
36
+ async clear() {
37
+ this.db.clear();
38
+ }
39
+
40
+ async keys() {
41
+ return [...this.db.keys()];
42
+ }
43
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * WhoTracks.Me
3
+ * https://whotracks.me/
4
+ *
5
+ * Copyright 2017-present Ghostery GmbH. All rights reserved.
6
+ *
7
+ * This Source Code Form is subject to the terms of the Mozilla Public
8
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
9
+ * file, You can obtain one at http://mozilla.org/MPL/2.0
10
+ */
11
+
12
+ import { expect } from 'chai';
13
+ import sinon from 'sinon';
14
+ import { Buffer } from 'buffer';
15
+
16
+ import InMemoryDatabase from './helpers/in-memory-database.js';
17
+
18
+ import ServerPublicKeyAccessor from '../src/server-public-key-accessor.js';
19
+ import logger from '../src/logger.js';
20
+
21
+ logger.disable();
22
+
23
+ async function mockedResponse({ body = '', error = false } = {}) {
24
+ return {
25
+ ok: !error,
26
+ statusText: error ? 500 : 200,
27
+ async json() {
28
+ return JSON.parse(body);
29
+ },
30
+ };
31
+ }
32
+
33
+ const MOCKS = {
34
+ reset() {
35
+ this.dates = ['20200101', '20200102', '20200103', '20200104'];
36
+ this.today = '20200102';
37
+ this.fakeKey =
38
+ 'BARClm1SExH0+0gDAVZzuo0h13y433m5aiLcOdD0EZ5Gpvh1MNqQO86NncHM75pQiosg4629b2Pqst5VG6jAY6M=';
39
+ this.fakeImportedKey = 'faked-imported-key';
40
+ this.fetch = async () => {
41
+ this.fetch._numCalls += 1;
42
+ const pubKeys = {};
43
+ this.dates.forEach((d) => {
44
+ pubKeys[d] = this.fakeKey;
45
+ });
46
+ const body = JSON.stringify({ pubKeys });
47
+ return mockedResponse({ body });
48
+ };
49
+ this.fetch._numCalls = 0;
50
+ this.importKey = async () => this.fakeImportedKey;
51
+ },
52
+ };
53
+
54
+ describe('#ServerPublicKeyAccessor', function () {
55
+ let database;
56
+ let uut;
57
+
58
+ const assumeKeysOnDisk = async (storedKeys) => {
59
+ const entry = storedKeys.map(({ date, key }) => [
60
+ date,
61
+ Buffer.from(key, 'base64'),
62
+ ]);
63
+ await database.set(uut.storageKey, entry);
64
+ };
65
+
66
+ beforeEach(async function () {
67
+ database = new InMemoryDatabase();
68
+ const config = {
69
+ COLLECTOR_DIRECT_URL: '192.0.2.0', // TEST-NET-1 address
70
+ };
71
+ uut = new ServerPublicKeyAccessor({
72
+ config,
73
+ database,
74
+ });
75
+ MOCKS.reset();
76
+ sinon.stub(window, 'fetch').callsFake(MOCKS.fetch);
77
+ sinon.stub(crypto.subtle, 'importKey').callsFake(MOCKS.importKey);
78
+ });
79
+
80
+ afterEach(function () {
81
+ window.fetch.restore();
82
+ crypto.subtle.importKey.restore();
83
+ });
84
+
85
+ it('should be able to retrieve a key and cache it (happy path)', async function () {
86
+ expect(await uut.getKey(MOCKS.today)).to.deep.equal({
87
+ date: MOCKS.today,
88
+ publicKey: MOCKS.fakeImportedKey,
89
+ });
90
+ });
91
+
92
+ it('should be able to retrieve a key and cache it (race during initialization)', async function () {
93
+ const results = await Promise.all([
94
+ uut.getKey(MOCKS.today),
95
+ uut.getKey(MOCKS.today),
96
+ Promise.resolve().then(() => uut.getKey(MOCKS.today)),
97
+ uut.getKey(MOCKS.today),
98
+ ]);
99
+
100
+ for (const result of results) {
101
+ expect(result).to.deep.equal({
102
+ date: MOCKS.today,
103
+ publicKey: MOCKS.fakeImportedKey,
104
+ });
105
+ }
106
+ expect(MOCKS.fetch._numCalls).to.equal(1);
107
+ });
108
+
109
+ it('should persist loaded keys to disk', async function () {
110
+ await assumeKeysOnDisk([{ date: MOCKS.today, key: MOCKS.fakeKey }]);
111
+ expect(await uut.getKey(MOCKS.today)).to.deep.equal({
112
+ date: MOCKS.today,
113
+ publicKey: MOCKS.fakeImportedKey,
114
+ });
115
+ expect(MOCKS.fetch._numCalls).to.equal(0);
116
+ });
117
+
118
+ it('should fetch newer keys if the cached ones are outdated', async function () {
119
+ const oneYearAgo = (MOCKS.today - '00010000').toString();
120
+ await assumeKeysOnDisk([{ date: oneYearAgo, key: MOCKS.fakeKey }]);
121
+ expect(await uut.getKey(MOCKS.today)).to.deep.equal({
122
+ date: MOCKS.today,
123
+ publicKey: MOCKS.fakeImportedKey,
124
+ });
125
+ expect(MOCKS.fetch._numCalls).to.equal(1);
126
+
127
+ // also check that the new keys were properly cached
128
+ MOCKS.fetch._numCalls = 0;
129
+ expect(await uut.getKey(MOCKS.today)).to.deep.equal({
130
+ date: MOCKS.today,
131
+ publicKey: MOCKS.fakeImportedKey,
132
+ });
133
+ expect(MOCKS.fetch._numCalls).to.equal(0);
134
+ });
135
+ });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * WhoTracks.Me
3
+ * https://whotracks.me/
4
+ *
5
+ * Copyright 2017-present Ghostery GmbH. All rights reserved.
6
+ *
7
+ * This Source Code Form is subject to the terms of the Mozilla Public
8
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
9
+ * file, You can obtain one at http://mozilla.org/MPL/2.0
10
+ */
11
+
12
+ import * as fc from 'fast-check';
13
+ import { expect } from 'chai';
14
+ import { sortObjectKeys } from '../src/utils.js';
15
+
16
+ describe('#sortObjectKeys', function () {
17
+ it('should ignore the creation order of keys', function () {
18
+ const obj1 = {
19
+ one: 'eins',
20
+ two: 'zwei',
21
+ three: 'drei',
22
+ };
23
+ const obj2 = {
24
+ two: 'zwei',
25
+ three: 'drei',
26
+ one: 'eins',
27
+ };
28
+
29
+ const obj1Json = JSON.stringify(sortObjectKeys(obj1));
30
+ const obj2Json = JSON.stringify(sortObjectKeys(obj2));
31
+ expect(obj1Json).to.eql(obj2Json);
32
+ });
33
+
34
+ it('should be idempotent', function () {
35
+ fc.assert(
36
+ fc.property(fc.object(), (obj) => {
37
+ const once = sortObjectKeys(obj);
38
+ const twice = sortObjectKeys(once);
39
+ expect(JSON.stringify(once)).to.eql(JSON.stringify(twice));
40
+ }),
41
+ );
42
+ });
43
+ });
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@whotracksme/reporting",
3
+ "version": "5.1.17",
4
+ "type": "module",
5
+ "description": "",
6
+ "scripts": {
7
+ "lint": "eslint reporting/ communication/",
8
+ "lint.fix": "eslint --fix reporting/ communication/",
9
+ "test": "npm run lint && npm run test --workspaces --if-present",
10
+ "release": "auto shipit"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/whotracksme/webextension-packages.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/whotracksme/webextension-packages/issues"
21
+ },
22
+ "homepage": "https://github.com/whotracksme/webextension-packages#readme",
23
+ "author": "Ghostery GmbH",
24
+ "license": "MPL-2.0",
25
+ "auto": {
26
+ "baseBranch": "main",
27
+ "plugins": [
28
+ "npm"
29
+ ]
30
+ },
31
+ "workspaces": [
32
+ "reporting",
33
+ "communication"
34
+ ],
35
+ "devDependencies": {
36
+ "auto": "^11.1.1",
37
+ "eslint": "^8.8.0",
38
+ "eslint-config-prettier": "^8.3.0",
39
+ "eslint-plugin-prettier": "^4.0.0",
40
+ "prettier": "2.5.1"
41
+ },
42
+ "dependencies": {
43
+ "@cliqz/url-parser": "^1.1.5",
44
+ "date-fns": "^2.29.3",
45
+ "idb": "^7.1.1",
46
+ "linkedom": "^0.16.11",
47
+ "pako": "^2.1.0",
48
+ "tldts-experimental": "^6.0.11"
49
+ }
50
+ }
@@ -0,0 +1,2 @@
1
+ * make pacemaker work in MV3 short leaving contextes
2
+ * bring back oauth detector
@@ -0,0 +1 @@
1
+ {"version":"2020-12-14","useDiff":false}
@@ -0,0 +1,11 @@
1
+ import { recordMouseDown } from '../src/request/content-script.js';
2
+
3
+ window.addEventListener('mousedown', (ev) => {
4
+ const { event, context, href } = recordMouseDown(ev);
5
+ chrome.runtime.sendMessage({
6
+ action: 'mousedown',
7
+ event,
8
+ context,
9
+ href,
10
+ });
11
+ });
@@ -0,0 +1,132 @@
1
+ /**
2
+ * WhoTracks.Me
3
+ * https://whotracks.me/
4
+ *
5
+ * Copyright 2017-present Ghostery GmbH. All rights reserved.
6
+ *
7
+ * This Source Code Form is subject to the terms of the Mozilla Public
8
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
9
+ * file, You can obtain one at http://mozilla.org/MPL/2.0
10
+ */
11
+ import './setup.js';
12
+ import {
13
+ UrlReporter,
14
+ RequestReporter,
15
+ WebRequestPipeline,
16
+ setLogLevel,
17
+ } from '../src/index.js';
18
+ import rules from './rules.json';
19
+
20
+ (chrome.action || chrome.browserAction).onClicked.addListener(() => {
21
+ chrome.tabs.create({
22
+ active: true,
23
+ url: chrome.runtime.getURL('inspector/index.html'),
24
+ });
25
+ });
26
+
27
+ setLogLevel('debug');
28
+
29
+ function createStorage() {
30
+ const storage = {
31
+ storage: {},
32
+ async get(key) {
33
+ return this.storage[key];
34
+ },
35
+ async set(key, value) {
36
+ this.storage[key] = value;
37
+ },
38
+ async remove(key) {
39
+ delete this.storage[key];
40
+ },
41
+ async clear() {
42
+ this.storage = {};
43
+ },
44
+ async keys() {
45
+ return Object.keys(this.storage);
46
+ },
47
+ open() {},
48
+ close() {},
49
+ };
50
+ return storage;
51
+ }
52
+
53
+ const communication = {
54
+ send(msg) {
55
+ console.warn('[Communication]', msg);
56
+ },
57
+ // TODO: use actuall anonymous-communication to access quorum
58
+ sendInstant(msg) {
59
+ console.warn('[Communication instant]', msg);
60
+ return Promise.resolve({
61
+ ok: true,
62
+ json: () => Promise.resolve({ result: true }),
63
+ });
64
+ },
65
+ trustedClock: {
66
+ getTimeAsYYYYMMDD() {
67
+ return '';
68
+ },
69
+ getTimeAsYYYYMMDDHH() {
70
+ return '';
71
+ },
72
+ },
73
+ };
74
+
75
+ const config = {
76
+ url: {
77
+ ALLOWED_COUNTRY_CODES: ['de'],
78
+ PATTERNS_URL: '',
79
+ CONFIG_URL: 'https://api.ghostery.net/api/v1/config',
80
+ },
81
+ request: {
82
+ configUrl: 'https://cdn.ghostery.com/antitracking/config.json',
83
+ remoteWhitelistUrl: 'https://cdn.ghostery.com/antitracking/whitelist/2',
84
+ localWhitelistUrl: '/base/assets/request',
85
+ },
86
+ };
87
+
88
+ const webRequestPipeline = new WebRequestPipeline();
89
+
90
+ const urlReporter = new UrlReporter({
91
+ config: config.url,
92
+ storage: createStorage(),
93
+ connectDatabase: createStorage,
94
+ communication,
95
+ browserInfoProvider: async () => ({ browser: 'test' }),
96
+ });
97
+
98
+ const requestReporter = new RequestReporter(config.request, {
99
+ communication,
100
+ webRequestPipeline,
101
+ countryProvider: urlReporter.countryProvider,
102
+ trustedClock: communication.trustedClock,
103
+ getBrowserInfo: () => ({ name: 'xx' }),
104
+ });
105
+
106
+ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
107
+ if (request.action === 'mousedown') {
108
+ requestReporter.recordClick(
109
+ request.event,
110
+ request.context,
111
+ request.href,
112
+ sender,
113
+ );
114
+ } else if (request.action === 'debug') {
115
+ sendResponse({
116
+ tabs: [...webRequestPipeline.pageStore.tabs._inMemoryMap.values()],
117
+ });
118
+ }
119
+ });
120
+
121
+ (async function () {
122
+ await webRequestPipeline.init();
123
+ await urlReporter.init();
124
+ await urlReporter.patterns.updatePatterns(rules);
125
+ await urlReporter.analyzeUrl('https://www.google.com/search?q=shoes');
126
+ await urlReporter.processPendingJobs();
127
+ await requestReporter.init();
128
+ })();
129
+
130
+ globalThis.webRequestPipeline = webRequestPipeline;
131
+ globalThis.urlReporter = urlReporter;
132
+ globalThis.requestReporter = requestReporter;
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>wtm/reporting inspector</title>
6
+ <script type="module" src="./index.js"></script>
7
+ </head>
8
+ <body>
9
+ <h1>WTM Reporting Inspector</h1>
10
+ <label for="filter">Filter:</label><input id="filter" type="text"/>
11
+ <section>
12
+ <h2>Page Store</h2>
13
+ <pre id="page-store"></pre>
14
+ </section>
15
+
16
+ </body>
17
+ </html>
@@ -0,0 +1,27 @@
1
+ const browser = globalThis.browser || globalThis.chrome;
2
+ const $container = document.querySelector('#page-store');
3
+ const $filter = document.querySelector('#filter');
4
+
5
+ $filter.value = localStorage.filter || '';
6
+ $filter.addEventListener('input', () => {
7
+ localStorage.filter = $filter.value;
8
+ });
9
+
10
+ async function render() {
11
+ let { tabs } = await browser.runtime.sendMessage({ action: 'debug' });
12
+
13
+ if (localStorage.filter) {
14
+ const matchById = tabs.find(
15
+ (tab) => tab.id === Number(localStorage.filter),
16
+ );
17
+
18
+ tabs = matchById
19
+ ? [matchById]
20
+ : tabs.filter((tab) => tab.url.includes(localStorage.filter));
21
+ }
22
+ $container.innerHTML = JSON.stringify(tabs, null, 2);
23
+ }
24
+
25
+ await render();
26
+
27
+ setInterval(render, 500);
@@ -0,0 +1,37 @@
1
+ {
2
+ "manifest_version": 3,
3
+ "author": "Ghostery",
4
+ "name": "WhoTracks.Me Reporting",
5
+ "short_name": "communication",
6
+ "version": "1.0.0",
7
+ "version_name": "1.0.0",
8
+ "description": "",
9
+ "permissions": [
10
+ "webNavigation",
11
+ "webRequest",
12
+ "tabs",
13
+ "storage",
14
+ "scripting",
15
+ "windows"
16
+ ],
17
+ "action": {
18
+ "default_title": "WTM/Reporting Inspector"
19
+ },
20
+ "background": {
21
+ "service_worker": "index.bundle.js",
22
+ "type": "module"
23
+ },
24
+ "content_scripts": [
25
+ {
26
+ "matches": ["http://*/*", "https://*/*"],
27
+ "js": ["content.bundle.js"],
28
+ "all_frames": true
29
+ }
30
+ ],
31
+ "host_permissions": [
32
+ "https://collector-hpn.ghostery.net/*",
33
+ "http://localhost:3001/*",
34
+ "http://*/*",
35
+ "https://*/*"
36
+ ]
37
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "manifest_version": 2,
3
+ "author": "Ghostery",
4
+ "name": "WhoTracks.Me Reporting",
5
+ "short_name": "communication",
6
+ "version": "1.0.0",
7
+ "description": "",
8
+ "permissions": [
9
+ "webNavigation",
10
+ "webRequest",
11
+ "webRequestBlocking",
12
+ "tabs",
13
+ "storage",
14
+ "scripting",
15
+ "http://*/*",
16
+ "https://*/*",
17
+ "ws://*/*",
18
+ "wss://*/*"
19
+ ],
20
+ "browser_action": {
21
+ "default_title": "WTM/Reporting Inspector",
22
+ "default_area": "navbar"
23
+ },
24
+ "content_scripts": [
25
+ {
26
+ "matches": ["http://*/*", "https://*/*"],
27
+ "js": ["content.bundle.js"],
28
+ "all_frames": true
29
+ }
30
+ ],
31
+ "background": {
32
+ "scripts": ["index.bundle.js"],
33
+ "persistent": false
34
+ }
35
+ }
@@ -0,0 +1,62 @@
1
+ {
2
+ "search-go": {
3
+ "doublefetch": {
4
+ "headers": {
5
+ "Cookie": "CONSENT=YES+cb-m.20220301-1-p0.de+FX+1;"
6
+ },
7
+ "followRedirects": true
8
+ },
9
+ "input": {
10
+ "#main div[data-text-ad=\"1\"]": {
11
+ "all": {
12
+ "u": {
13
+ "select": "a div[role=\"link\"]",
14
+ "attr": "aria-label"
15
+ },
16
+ "t": {
17
+ "select": "a div[role=\"heading\"] > span",
18
+ "attr": "textContent"
19
+ }
20
+ }
21
+ }
22
+ },
23
+ "output": {
24
+ "hwlite.query0": {
25
+ "fields": [
26
+ {
27
+ "key": "q"
28
+ },
29
+ {
30
+ "key": "qurl"
31
+ },
32
+ {
33
+ "key": "ctry"
34
+ }
35
+ ],
36
+ "deduplicateBy": "q"
37
+ },
38
+ "hwlite.ads_A": {
39
+ "fields": [
40
+ {
41
+ "key": "r",
42
+ "source": "#main div[data-text-ad=\"1\"]",
43
+ "requiredKeys": [
44
+ "t",
45
+ "u"
46
+ ]
47
+ },
48
+ {
49
+ "key": "q"
50
+ },
51
+ {
52
+ "key": "qurl"
53
+ },
54
+ {
55
+ "key": "ctry"
56
+ }
57
+ ],
58
+ "deduplicateBy": "q"
59
+ }
60
+ }
61
+ }
62
+ }
@@ -0,0 +1 @@
1
+ globalThis.chrome = browser || chrome;
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>wtm/reporting test1</title>
6
+ </head>
7
+ <body>
8
+ <a href="https://ghostery.com" id="a">go to ghostery.com (forces process switch on Firefox)</a>
9
+ </body>
10
+ </html>
@@ -0,0 +1,22 @@
1
+ const rollupPreprocessor = require('./rollup.common-config.cjs');
2
+
3
+ module.exports = function (config) {
4
+ config.set({
5
+ frameworks: ['mocha', 'chai', 'sinon'],
6
+ files: [{ pattern: 'test/index.js', watched: false }],
7
+ preprocessors: {
8
+ 'test/index.js': ['rollup'],
9
+ },
10
+ reporters: ['mocha'],
11
+ port: 9876,
12
+ colors: true,
13
+ logLevel: config.LOG_INFO,
14
+ autoWatch: false,
15
+ concurrency: 0,
16
+ rollupPreprocessor,
17
+ client: {
18
+ TEST_FIXTURES_URL: process.env.TEST_FIXTURES_URL, // for test/search-extractor.spec.js
19
+ REPLAY_FIXTURES_URL: process.env.REPLAY_FIXTURES_URL, // for test/pages.spec.js
20
+ },
21
+ });
22
+ };