@whotracksme/reporting 11.1.0 β†’ 12.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/package.json +1 -1
  3. package/reporting/README.md +13 -0
  4. package/reporting/example/README.md +4 -0
  5. package/reporting/example/e2e/README.md +263 -0
  6. package/reporting/example/e2e/console-capture.js +67 -0
  7. package/reporting/example/e2e/control.js +423 -0
  8. package/reporting/example/e2e/hub.mjs +380 -0
  9. package/reporting/example/e2e/launch.mjs +92 -0
  10. package/reporting/example/e2e/mock-extension.mjs +106 -0
  11. package/reporting/example/e2e/pages/private-fixture.html +16 -0
  12. package/reporting/example/e2e/run.mjs +187 -0
  13. package/reporting/example/e2e/scenarios/privacy-guards.json +26 -0
  14. package/reporting/example/e2e/scenarios/smoke.json +15 -0
  15. package/reporting/example/e2e/verify.mjs +159 -0
  16. package/reporting/example/index.js +55 -46
  17. package/reporting/example/manifests/chromium.json +1 -0
  18. package/reporting/example/storage.js +65 -0
  19. package/reporting/package.json +5 -1
  20. package/reporting/rollup.config.cjs +1 -1
  21. package/reporting/src/doublefetch-page-handler.js +24 -0
  22. package/reporting/src/doublefetch-unbreak.js +186 -0
  23. package/reporting/src/http.js +197 -19
  24. package/reporting/src/job-scheduler.js +1 -1
  25. package/reporting/src/logger.js +1 -1
  26. package/reporting/src/offscreen/doublefetch/capture.js +90 -0
  27. package/reporting/src/patterns.js +5 -2
  28. package/reporting/src/search-extractor.js +2 -0
  29. package/reporting/test/doublefetch-unbreak.spec.js +133 -0
  30. package/reporting/test/http.spec.js +113 -0
  31. package/reporting/test/index.js +1 -0
  32. package/reporting/test/patterns.spec.js +10 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ # v12.0.0 (Wed Aug 19 2026)
2
+
3
+ #### πŸ’₯ Breaking Change
4
+
5
+ - Improve wtm.page coverage [#225](https://github.com/whotracksme/webextension-packages/pull/225) ([@philipp-classen](https://github.com/philipp-classen))
6
+
7
+ #### 🏠 Internal
8
+
9
+ - Add end-to-end harness [#223](https://github.com/whotracksme/webextension-packages/pull/223) ([@chrmod](https://github.com/chrmod))
10
+
11
+ #### Authors: 2
12
+
13
+ - Krzysztof Modras ([@chrmod](https://github.com/chrmod))
14
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
15
+
16
+ ---
17
+
18
+ # v11.1.1 (Tue Aug 11 2026)
19
+
20
+ #### πŸ› Bug Fix
21
+
22
+ - Fix Logger#setLevel [#218](https://github.com/whotracksme/webextension-packages/pull/218) ([@philipp-classen](https://github.com/philipp-classen))
23
+ - job-scheduler: fix update of the flush timer [#221](https://github.com/whotracksme/webextension-packages/pull/221) ([@philipp-classen](https://github.com/philipp-classen))
24
+
25
+ #### Authors: 1
26
+
27
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
28
+
29
+ ---
30
+
1
31
  # v11.1.0 (Mon Aug 10 2026)
2
32
 
3
33
  #### πŸš€ Enhancement
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "11.1.0",
3
+ "version": "12.0.0",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {
@@ -19,6 +19,19 @@ npm --workspace=reporting run start.firefox
19
19
  For a scripted runner with log capture and an HTTP control surface,
20
20
  see `example/README.md`.
21
21
 
22
+ ## End-to-end runs
23
+
24
+ `example/e2e/` drives page & search reporting in a real, un-automated Chrome
25
+ and captures the outgoing messages for verification:
26
+
27
+ ```
28
+ npm --workspace=reporting run e2e.launch # once: opens the WTM-E2E profile
29
+ npm --workspace=reporting run e2e.hub # terminal 1
30
+ npm --workspace=reporting run e2e -- smoke # terminal 2
31
+ ```
32
+
33
+ See `example/e2e/README.md`.
34
+
22
35
  ## Tests
23
36
 
24
37
  See `test/README.md` for the two test suites (node-mocha + karma),
@@ -3,6 +3,10 @@
3
3
  Scripted extension runner with log capture. For the interactive
4
4
  `web-ext run` loop, see the package-level `../README.md`.
5
5
 
6
+ > For end-to-end runs against search engines, use `e2e/` instead β€” this
7
+ > runner drives Chrome over WebDriver/CDP, which search engines detect.
8
+ > See `e2e/README.md`.
9
+
6
10
  ## Usage
7
11
 
8
12
  ```
@@ -0,0 +1,263 @@
1
+ # reporting/example/e2e
2
+
3
+ End-to-end harness for `UrlReporter` (page & search reporting) that drives a
4
+ real, un-automated Chrome.
5
+
6
+ ## Why it is built this way
7
+
8
+ Search engines fingerprint WebDriver and CDP, so the browser cannot be driven
9
+ from the outside. Control is inverted instead: **the extension dials out** to a
10
+ local hub over a WebSocket, and everything else talks to the hub over plain
11
+ HTTP.
12
+
13
+ ```
14
+ Claude Code / shell --curl--> hub (127.0.0.1:7878) <--WebSocket--> example extension
15
+ | |
16
+ out/messages.jsonl chrome.tabs.create(...)
17
+ ```
18
+
19
+ Consequences worth knowing:
20
+
21
+ - Navigation happens through `chrome.tabs`, which is what a user clicking a
22
+ link produces. No `navigator.webdriver`, no `--enable-automation`, no
23
+ debugger attached.
24
+ - Nothing injects synthetic keyboard or mouse events. Those carry
25
+ `isTrusted: false` and are a *stronger* bot signal than a plain navigation.
26
+ If a scenario genuinely needs human-like interaction, drive that part with
27
+ the Claude in Chrome extension and leave the rest to the hub.
28
+ - The WebSocket keeps the MV3 service worker alive between steps, so commands
29
+ do not have to wake it first.
30
+
31
+ `../run.mjs` (webdriverio + puppeteer) still exists for log capture on sites
32
+ that do not care about automation. Do not point it at a search engine.
33
+
34
+ ## Setup (once)
35
+
36
+ ```
37
+ npm ci # repo root, if you have not already
38
+ npm --workspace=reporting run build
39
+ npm --workspace=reporting run e2e.launch
40
+ ```
41
+
42
+ `e2e.launch` opens a dedicated `WTM-E2E` profile in your regular Chrome and
43
+ prints the one-time steps: `chrome://extensions` β†’ Developer mode β†’ Load
44
+ unpacked β†’ `reporting/example`. The extension stays loaded in that profile
45
+ afterwards.
46
+
47
+ The profile is deliberately persistent: a brand new one has no cookies or
48
+ history, which is itself a mild bot signal. Let it age normally.
49
+
50
+ ## Running
51
+
52
+ ```
53
+ npm --workspace=reporting run e2e.hub # terminal 1, keep running
54
+ npm --workspace=reporting run e2e -- smoke # terminal 2
55
+ ```
56
+
57
+ Scenarios live in `scenarios/*.json`.
58
+
59
+ | Scenario | What it proves |
60
+ | --- | --- |
61
+ | `smoke` | Hub ↔ extension wiring, and one public page reaching a `wtm.page` message |
62
+ | `privacy-guards` | A private-host URL is dropped, and denying quorum suppresses page messages |
63
+
64
+ Exit code is `0` only when every step ran and every expectation held.
65
+
66
+ ### After changing `src/`
67
+
68
+ ```
69
+ npm --workspace=reporting run build
70
+ ```
71
+
72
+ …then **reload the extension** at `chrome://extensions`. The service worker
73
+ runs the bundle, so a rebuild alone changes nothing β€” this is the most common
74
+ reason a fix appears to have no effect.
75
+
76
+ ### Flags
77
+
78
+ Everything after `--` is passed through by npm:
79
+
80
+ ```
81
+ npm --workspace=reporting run e2e -- smoke --json
82
+ ```
83
+
84
+ | Script | Flag | Default | Purpose |
85
+ | --- | --- | --- | --- |
86
+ | `e2e` | `<scenario>` | `smoke` | Name, or a path to a JSON file |
87
+ | | `--json` | off | Full capture + step trace instead of the summary |
88
+ | | `--keep-messages` | off | Do not clear captures first β€” accumulate across runs |
89
+ | | `--hub <url>` | `http://127.0.0.1:7878` | Where the hub is |
90
+ | `e2e.hub` | `--port <n>` | `7878` | See the caveat below |
91
+ | | `--out-dir <path>` | `example/e2e/out` | Where captures are written |
92
+ | | `--quiet` | off | Suppress per-message logging |
93
+ | `e2e.launch` | `--profile <name>` | `WTM-E2E` | Chrome profile directory |
94
+ | | `--chrome <path>` | auto-detected | Explicit Chrome binary |
95
+
96
+ > **`--port` caveat.** The extension's hub URL is baked into the bundle
97
+ > (`example/index.js`), so changing the hub port also needs that constant
98
+ > changed and a rebuild. Only useful if `7878` is already taken.
99
+
100
+ ## Talking to the hub directly
101
+
102
+ ```
103
+ curl -s 127.0.0.1:7878/health
104
+ curl -s 127.0.0.1:7878/cmd -H 'content-type: application/json' -d '{"name":"flush"}'
105
+ curl -s '127.0.0.1:7878/messages?action=wtm.page'
106
+ curl -s '127.0.0.1:7878/events?since=0'
107
+ curl -s '127.0.0.1:7878/logs?tail=50'
108
+ ```
109
+
110
+ Everything is appended to `out/messages.jsonl`, `out/events.jsonl` and
111
+ `out/console.log`.
112
+
113
+ ### Routes
114
+
115
+ | Route | Purpose |
116
+ | --- | --- |
117
+ | `GET /health` | Is the extension connected, and the current `seq` |
118
+ | `POST /cmd {name, args?, timeout?}` | Run a command, wait for its result |
119
+ | `GET /messages?since=&action=` | Captured messages, filtered |
120
+ | `POST /messages/clear` | Drop captures and truncate the JSONL files |
121
+ | `GET /events?since=` | Job lifecycle events |
122
+ | `GET /logs?tail=` | Service worker console |
123
+ | `GET /pages/<name>` | Negative-fixture HTML pages from `pages/` |
124
+ | `POST /shutdown` | Stop the hub |
125
+
126
+ ### Commands
127
+
128
+ | Command | Purpose |
129
+ | --- | --- |
130
+ | `navigate {url, tabId?, newTab?, waitForLoad?, timeoutInMs?, settleInMs?}` | Open a URL in a tab |
131
+ | `flush {maxRounds?, settleInMs?, forceExpiration?}` | Force everything through to messages β€” see below |
132
+ | `processPendingJobs` / `expirePages` | The individual halves of `flush` |
133
+ | `state` / `dumpJobs` / `selfChecks` | Inspect without guessing |
134
+ | `reset` | Clear storage and **restart the worker** β€” a true fresh install (see note) |
135
+ | `reload` | Restart the worker without clearing storage; picks up a rebuilt bundle |
136
+ | `setQuorum {mode}` | `always` or `never` |
137
+ | `closeTabs {urlContains?}` | Tidy between scenarios |
138
+ | `ping` | Liveness check |
139
+
140
+ ### `reset` restarts the worker
141
+
142
+ `reset` clears `chrome.storage.local` and then calls `chrome.runtime.reload()`
143
+ rather than `unload()` + `init()`. That is not a stylistic choice: `Pages#init`
144
+ guards its whole setup with `if (!this._ready)` and installs the
145
+ `chrome.tabs`/`webNavigation` listeners *inside* that guard
146
+ (`src/pages.js:411`), so a second `init()` leaves `isActive === true` with no
147
+ listeners attached and nothing is ever tracked again. `Pages` is effectively
148
+ one-shot; a worker restart is also a more faithful fresh install.
149
+
150
+ Resetting matters for correctness, not just tidiness: `PersistedHashes`
151
+ deduplicates messages, so re-running a scenario without a reset silently drops
152
+ every message it already sent.
153
+
154
+ The hub waits for the worker to reconnect before the next step runs, so
155
+ scenarios do not need to sleep after a `reset`.
156
+
157
+ ### `flush`
158
+
159
+ The reporter is built to spread work out over time: pages wait an hour in
160
+ `PageDB` before they expire, jobs get randomized `readyIn` delays, and
161
+ `doublefetch-page` has a per-type cooldown. `flush` collapses all of that β€”
162
+ it force-expires pages and drains the job queue in a loop until nothing is
163
+ pending, then reports how many rounds it took.
164
+
165
+ If a message you expected never arrives, check `/events` before anything else.
166
+ `jobRejected`, `jobFailed` and `jobExpired` distinguish "never scheduled" from
167
+ "rejected by a privacy check" from "doublefetch failed", which is otherwise
168
+ indistinguishable from the outside.
169
+
170
+ ## Behaviour worth knowing before writing scenarios
171
+
172
+ - **Search result pages never produce a `wtm.page`.** The log says
173
+ `Mark page as private ... reason: "ignore search engine result pages"`.
174
+ Do not go looking for one.
175
+ - **Tabs already open before the worker started never produce page messages.**
176
+ They are dropped with `incomplete information: preDoublefetch missing`,
177
+ because page structure is injected on navigation. Always `closeTabs` and
178
+ navigate within the scenario rather than relying on whatever the browser had
179
+ open.
180
+ - **Whether any given engine returns extractable content to an anonymous
181
+ refetch is a property of that engine and your network, not of the harness.**
182
+ A scenario that stops passing has not necessarily regressed β€” check
183
+ `/events` for `jobFailed` before assuming a code change broke it.
184
+
185
+ ## Writing scenarios
186
+
187
+ ```json
188
+ {
189
+ "name": "my-scenario",
190
+ "steps": [
191
+ { "reset": {} },
192
+ { "navigate": { "url": "https://example.com/" } },
193
+ { "flush": {} }
194
+ ],
195
+ "expect": {
196
+ "messages": { "wtm.page": [{ "url": "~example.com" }] },
197
+ "mustNotAppear": ["some-secret"],
198
+ "forbiddenActions": []
199
+ }
200
+ }
201
+ ```
202
+
203
+ - A step's command is its one non-reserved key. `timeout` (ms, per step) and
204
+ `continueOnError` (keep going after a failed step) are reserved and may sit
205
+ alongside it:
206
+ `{ "navigate": { "url": "..." }, "timeout": 90000, "continueOnError": true }`
207
+ - In `expect.messages`, `~foo` means "contains", a plain string means equality,
208
+ and dotted keys (`qr.q`) walk into the payload.
209
+ - Action keys match by **prefix**, so a primary action also accepts a fallback
210
+ whose name extends it. Prefix `=` for an exact match when that matters.
211
+ - `mustNotAppear` is scanned across every string **and every object key** in
212
+ every captured message. This is the assertion that matters most: it is the
213
+ only one that fails when a privacy guard regresses.
214
+ - `forbiddenActions` asserts an action was never sent at all.
215
+ - Payload shape is checked on every run whether or not the scenario asks β€”
216
+ `REQUIRED_FIELDS` in `verify.mjs` lists the fields each action must carry.
217
+ A `[shape]` failure comes from there, not from the scenario.
218
+
219
+ Pages under `pages/` are served from `127.0.0.1:7878`, which `sanitizeUrl`
220
+ must reject on two independent grounds (private hostname, uncommon port). That
221
+ makes them a dependable negative fixture.
222
+
223
+ ## Troubleshooting
224
+
225
+ | Symptom | Where to look |
226
+ | --- | --- |
227
+ | `hub is up but the extension has not connected` | Is the extension enabled in the `WTM-E2E` profile? Reload it at `chrome://extensions` β€” the worker connects on startup |
228
+ | Connected, but a command times out | `GET /logs?tail=100` for the worker console; an exception in `init()` leaves commands registered but the reporter inactive |
229
+ | A `wtm.page` never arrives | `GET /events` β€” `jobRejected` means a privacy check dropped it, `jobFailed` on `doublefetch-page` means the anonymous refetch failed, no event at all means the page never entered `PageDB` |
230
+ | `flush` returns `drained: false` | Raise `maxRounds`; check `dumpJobs` for a job stuck in `retryable` |
231
+ | A code change had no effect | Rebuild **and** reload the extension |
232
+ | Got a fallback action instead of the primary one | Extraction found less than the pattern expected β€” the selectors may have drifted, or the page was not the expected shape |
233
+
234
+ ## Testing the harness itself
235
+
236
+ `mock-extension.mjs` speaks the same protocol without a browser, so the hub,
237
+ runner and verifier can be checked in isolation:
238
+
239
+ ```
240
+ node example/e2e/hub.mjs --quiet &
241
+ node example/e2e/mock-extension.mjs &
242
+ node example/e2e/run.mjs smoke # expect PASSED
243
+ node example/e2e/run.mjs privacy-guards # expect PASSED
244
+
245
+ pkill -f mock-extension.mjs # only one may be connected
246
+ node example/e2e/mock-extension.mjs --leak & # emits a page it should not
247
+ node example/e2e/run.mjs privacy-guards # expect FAILED
248
+ ```
249
+
250
+ The last two lines are the important ones: they prove the leak assertions
251
+ actually fire. A verifier that never fails is indistinguishable from one that
252
+ has nothing to check.
253
+
254
+ ## Known gaps
255
+
256
+ - **Quorum is stubbed.** The example has no hpnv2 transport, so
257
+ `sendInstant` returns a canned verdict. Runs exercise message construction
258
+ and the quorum *gate*, not the quorum protocol.
259
+ - **Doublefetch hits the live web.** Search engines may answer a cookieless
260
+ fetch with a consent wall or a 429. That is a real signal, not a harness
261
+ bug β€” look for `jobFailed` on `doublefetch-query` in `/events`.
262
+ - **`CountryProvider` calls the live config endpoint**, so `ctry` depends on
263
+ network and on `ALLOWED_COUNTRY_CODES`.
@@ -0,0 +1,67 @@
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
+ // Must be imported before src/: Logger binds console.* in its constructor.
13
+ const MAX_BUFFERED_LINES = 1000;
14
+
15
+ const buffer = [];
16
+ let sink = null;
17
+ let insideForward = false;
18
+
19
+ function stringify(arg) {
20
+ if (typeof arg === 'string') {
21
+ return arg;
22
+ }
23
+ if (arg instanceof Error) {
24
+ return arg.stack || arg.message;
25
+ }
26
+ try {
27
+ return JSON.stringify(arg);
28
+ } catch {
29
+ return String(arg);
30
+ }
31
+ }
32
+
33
+ function emit(level, args) {
34
+ if (insideForward) {
35
+ return;
36
+ }
37
+ insideForward = true;
38
+ try {
39
+ const text = args.map(stringify).join(' ');
40
+ if (sink) {
41
+ sink(level, text);
42
+ } else {
43
+ buffer.push([level, text]);
44
+ if (buffer.length > MAX_BUFFERED_LINES) {
45
+ buffer.shift();
46
+ }
47
+ }
48
+ } finally {
49
+ insideForward = false;
50
+ }
51
+ }
52
+
53
+ for (const level of ['debug', 'log', 'info', 'warn', 'error']) {
54
+ const original = console[level].bind(console);
55
+ console[level] = (...args) => {
56
+ original(...args);
57
+ emit(level, args);
58
+ };
59
+ }
60
+
61
+ export function attachConsoleSink(fn) {
62
+ sink = fn;
63
+ const pending = buffer.splice(0, buffer.length);
64
+ for (const [level, text] of pending) {
65
+ fn(level, text);
66
+ }
67
+ }