@whotracksme/reporting 12.1.13 → 12.1.15

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/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ # v12.1.15 (Thu Nov 19 2026)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Fixed bloom filter cleanup [#257](https://github.com/whotracksme/webextension-packages/pull/257) ([@philipp-classen](https://github.com/philipp-classen))
6
+
7
+ #### Authors: 1
8
+
9
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
10
+
11
+ ---
12
+
13
+ # v12.1.14 (Thu Nov 19 2026)
14
+
15
+ #### 🐛 Bug Fix
16
+
17
+ - fixed: Firefox on Android might have missed page loads [#256](https://github.com/whotracksme/webextension-packages/pull/256) ([@philipp-classen](https://github.com/philipp-classen))
18
+
19
+ #### Authors: 1
20
+
21
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
22
+
23
+ ---
24
+
1
25
  # v12.1.13 (Thu Nov 19 2026)
2
26
 
3
27
  #### 🐛 Bug Fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "12.1.13",
3
+ "version": "12.1.15",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./sanitizer": "./reporting/src/sanitizer.js",
@@ -192,7 +192,7 @@ export class BloomFilter {
192
192
  try {
193
193
  await Promise.all(
194
194
  [...corruptedKeys, ...obsoleteKeys].map((key) =>
195
- this.db.delete(key),
195
+ this.db.remove(key),
196
196
  ),
197
197
  );
198
198
  this._info('Successfully cleaned up keys');
@@ -238,7 +238,7 @@ export class BloomFilter {
238
238
  if (this.maxGenerations > 1) {
239
239
  const isTooOld = (ts) =>
240
240
  ts < now - this.rotationIntervalInMs * this.maxGenerations;
241
- while (currentGens.size > 0 && isTooOld(currentGens[0])) {
241
+ while (currentGens.length > 0 && isTooOld(currentGens[0])) {
242
242
  const oldestGen = currentGens.shift();
243
243
  gensToDelete.push(oldestGen);
244
244
  this._info('detected old generation:', oldestGen);
@@ -269,7 +269,7 @@ export class BloomFilter {
269
269
  this._info('Deleting generation', gen);
270
270
  const keys = keysByGen.get(gen);
271
271
  try {
272
- await Promise.all(keys.map((key) => this.db.delete(key)));
272
+ await Promise.all(keys.map((key) => this.db.remove(key)));
273
273
  this._info(
274
274
  `Generation ${gen} successfully deleted (${keys.length} keys in total)`,
275
275
  );
@@ -278,7 +278,7 @@ export class BloomFilter {
278
278
  }
279
279
  });
280
280
  }
281
- await Promise.all(pendingCleanups);
281
+ await Promise.all(pendingCleanups.map((cleanup) => cleanup()));
282
282
 
283
283
  this.generations = currentGens.map(
284
284
  (gen) =>
@@ -1146,6 +1146,12 @@ export default class Pages {
1146
1146
  }
1147
1147
  }
1148
1148
  this.openTabs.set(tabId, entry);
1149
+
1150
+ // webNavigation.onCommitted came before this update (see there)
1151
+ const pendingCommit = oldTabEntry?._pendingCommit;
1152
+ if (pendingCommit?.url === entry.url) {
1153
+ this._finishCommit(tabId, entry, pendingCommit);
1154
+ }
1149
1155
  return;
1150
1156
  }
1151
1157
 
@@ -1389,25 +1395,12 @@ export default class Pages {
1389
1395
  const { tabId, frameId, url } = details;
1390
1396
  if (frameId !== 0) return; // not top-level frame (of the active page)
1391
1397
 
1392
- let entry = this.openTabs.get(tabId);
1398
+ const entry = this.openTabs.get(tabId);
1393
1399
  if (!entry) {
1394
1400
  logger.debug('Skipping navigation to', url, 'in private tab with', tabId);
1395
1401
  return;
1396
1402
  }
1397
1403
 
1398
- const now = Date.now();
1399
- entry = {
1400
- ...entry,
1401
- lastUpdated: now,
1402
-
1403
- // Some pages trigger a history navigation with the identical URL
1404
- // immediately after loading. Remember the context here to be
1405
- // able to skip it later.
1406
- _previous_webNavigation_onCommitted: {
1407
- url,
1408
- lastUpdated: now,
1409
- },
1410
- };
1411
1404
  const isBackOrForward =
1412
1405
  details.transitionQualifiers?.includes('forward_back');
1413
1406
 
@@ -1422,6 +1415,37 @@ export default class Pages {
1422
1415
  // See also https://stackoverflow.com/q/25542015/783510
1423
1416
  forgetOpenedFrom = true;
1424
1417
  }
1418
+
1419
+ // The order of events depends on the browser. Chrome first updates the
1420
+ // URL of the tab (tabs.onUpdated). Firefox 160 sends this event first;
1421
+ // then wait for the update of the tab (see chrome_tabs_onUpdated).
1422
+ if (isRealPage(url) && entry.url !== url) {
1423
+ this.openTabs.set(tabId, {
1424
+ ...entry,
1425
+ _pendingCommit: { url, forgetOpenedFrom },
1426
+ });
1427
+ return;
1428
+ }
1429
+ this._finishCommit(tabId, entry, { url, forgetOpenedFrom });
1430
+ }
1431
+
1432
+ _finishCommit(tabId, oldEntry, { url, forgetOpenedFrom }) {
1433
+ const now = Date.now();
1434
+ // this creates a copy, but omits "_pendingCommit" (the commit is handled now)
1435
+ // eslint-disable-next-line no-unused-vars
1436
+ const { _pendingCommit, ...oldEntry_ } = oldEntry;
1437
+ let entry = {
1438
+ ...oldEntry_,
1439
+ lastUpdated: now,
1440
+
1441
+ // Some pages trigger a history navigation with the identical URL
1442
+ // immediately after loading. Remember the context here to be
1443
+ // able to skip it later.
1444
+ _previous_webNavigation_onCommitted: {
1445
+ url,
1446
+ lastUpdated: now,
1447
+ },
1448
+ };
1425
1449
  if (forgetOpenedFrom && (entry.previousUrl || entry.openedFrom)) {
1426
1450
  // this creates a copy, but omits the fields related to "opened from"
1427
1451
  // eslint-disable-next-line no-unused-vars
@@ -78,11 +78,11 @@ export default class PersistedBitarray {
78
78
  const unmatchedKeys = [...remainingKeys];
79
79
  this._warn(
80
80
  'Found',
81
- unmatchedKeys.size,
81
+ unmatchedKeys.length,
82
82
  'unmatched keys (will be deleted):',
83
83
  unmatchedKeys,
84
84
  );
85
- Promise.all(unmatchedKeys.map((key) => this.db.deleteKey(key)))
85
+ Promise.all(unmatchedKeys.map((key) => this.db.remove(key)))
86
86
  .then(() => this._info('Unmatched keys successfully removed'))
87
87
  .catch((e) => this._warn('Failed to delete keys', e));
88
88
  }
@@ -28,9 +28,13 @@ describe('#BloomFilter', function () {
28
28
  });
29
29
  }
30
30
 
31
+ async function flushToDisk(bloomFilter) {
32
+ await Promise.all(bloomFilter.generations.map((gen) => gen.flush()));
33
+ }
34
+
31
35
  // simulates a restart of the extension at the given time
32
36
  async function restartBloomFilter(oldBloomFilter, { now, ...options }) {
33
- await Promise.all(oldBloomFilter.generations.map((gen) => gen.flush()));
37
+ await flushToDisk(oldBloomFilter);
34
38
  const uut = newBloomFilter(options);
35
39
  await uut.ready(now);
36
40
  return uut;
@@ -115,4 +119,65 @@ describe('#BloomFilter', function () {
115
119
  });
116
120
  });
117
121
  });
122
+
123
+ describe('#ready (cleanup of the database)', function () {
124
+ describe('with two generations on disk', function () {
125
+ const rotationIntervalInMs = 30 * DAY;
126
+ const options = { maxGenerations: 2, rotationIntervalInMs };
127
+ let now;
128
+ let uut;
129
+ let keysOfGen2;
130
+
131
+ beforeEach(async function () {
132
+ now = Date.now();
133
+ uut = newBloomFilter(options);
134
+ await uut.ready(now);
135
+ await uut.add('foo');
136
+
137
+ uut = await restartBloomFilter(uut, {
138
+ now: now + rotationIntervalInMs + DAY,
139
+ ...options,
140
+ });
141
+ await uut.add('bar');
142
+ await flushToDisk(uut);
143
+
144
+ const keys = await database.keys();
145
+ keysOfGen2 = keys.filter((key) => !key.includes(`|${now}|`));
146
+ expect(keys).to.have.lengthOf(2);
147
+ expect(keysOfGen2).to.have.lengthOf(1);
148
+ });
149
+
150
+ it('should delete the keys of a generation that was rotated out', async function () {
151
+ // The third generation starts. Two generations are the limit.
152
+ uut = await restartBloomFilter(uut, {
153
+ now: now + 2 * rotationIntervalInMs + 2 * DAY,
154
+ ...options,
155
+ });
156
+
157
+ expect(uut.generations).to.have.lengthOf(2);
158
+ expect(await database.keys()).to.eql(keysOfGen2);
159
+ });
160
+
161
+ it('should delete all generations that are too old', async function () {
162
+ // Both generations are older than their maximum age (two intervals).
163
+ uut = await restartBloomFilter(uut, {
164
+ now: now + 10 * rotationIntervalInMs,
165
+ ...options,
166
+ });
167
+
168
+ expect(uut.generations).to.have.lengthOf(1);
169
+ expect(await database.keys()).to.eql([]);
170
+ });
171
+ });
172
+
173
+ it('should delete keys from an old version and corrupted keys', async function () {
174
+ await database.set('bf|test|v0|123|some-shard', 'old version');
175
+ await database.set('bf|test|v1|no-timestamp|some-shard', 'corrupted');
176
+
177
+ const uut = newBloomFilter();
178
+ await uut.ready();
179
+
180
+ expect(await database.keys()).to.eql([]);
181
+ });
182
+ });
118
183
  });
@@ -9,6 +9,7 @@ import './patterns.spec.js';
9
9
  import './patterns-updater.spec.js';
10
10
  import './job-scheduler.spec.js';
11
11
  import './bloom-filters.spec.js';
12
+ import './persisted-bitarray.spec.js';
12
13
  import './country-provider.spec.js';
13
14
  import './persisted-hashes.spec.js';
14
15
  import './doublefetch-unbreak.spec.js';
@@ -0,0 +1,35 @@
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
+
14
+ import PersistedBitarray from '../src/persisted-bitarray.js';
15
+ import InMemoryDatabase from './helpers/in-memory-database.js';
16
+
17
+ describe('#PersistedBitarray', function () {
18
+ let database;
19
+
20
+ beforeEach(function () {
21
+ database = new InMemoryDatabase();
22
+ });
23
+
24
+ describe('#ready (cleanup of the database)', function () {
25
+ it('should delete keys that do not match the shard configuration', async function () {
26
+ await database.set('arr|test|v0|0', 'shard from an old version');
27
+
28
+ const uut = new PersistedBitarray({ database, name: 'test', size: 1024 });
29
+ await uut.ready();
30
+ await new Promise((resolve) => setTimeout(resolve, 0));
31
+
32
+ expect(await database.keys()).to.eql([]);
33
+ });
34
+ });
35
+ });