@whotracksme/reporting 12.1.14 → 12.1.16

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.16 (Thu Nov 19 2026)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Fixed: After a restart of the service worker, the state of all tabs is lost [#258](https://github.com/whotracksme/webextension-packages/pull/258) ([@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.15 (Thu Nov 19 2026)
14
+
15
+ #### 🐛 Bug Fix
16
+
17
+ - Fixed bloom filter cleanup [#257](https://github.com/whotracksme/webextension-packages/pull/257) ([@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.14 (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.14",
3
+ "version": "12.1.16",
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) =>
@@ -599,7 +599,7 @@ export default class Pages {
599
599
  if (openTabs) {
600
600
  const deserializedTabs = Object.entries(openTabs).map(
601
601
  ([tabId, tabContent]) => [
602
- tabId,
602
+ Number(tabId), // tab ids are numbers, but object keys are strings
603
603
  this._deserializeTabContent(tabContent),
604
604
  ],
605
605
  );
@@ -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';
@@ -15,6 +15,7 @@ import Pages, { stripLazyVars, CANCEL_LAZY_VAR } from '../src/pages.js';
15
15
  import UrlAnalyzer from '../src/url-analyzer.js';
16
16
  import SessionStorageWrapper from '../src/session-storage.js';
17
17
  import Patterns from '../src/patterns.js';
18
+ import FakeSessionApi from './helpers/fake-session-storage.js';
18
19
 
19
20
  function waitForPendingMicrotasks() {
20
21
  return new Promise((resolve) => {
@@ -860,6 +861,107 @@ ${total} tests run: ${passed} passed, ${failed} failed (${ratio}% passed)
860
861
  });
861
862
  }
862
863
  });
864
+
865
+ describe('after a restart of the service worker', function () {
866
+ const TAB_ID = 7;
867
+ const WINDOW_ID = 1;
868
+ const URL_A = 'https://www.example.com/start';
869
+ const URL_B = 'https://www.example.com/article';
870
+ let sessionApi;
871
+
872
+ function tab(url, status) {
873
+ return {
874
+ id: TAB_ID,
875
+ windowId: WINDOW_ID,
876
+ incognito: false,
877
+ active: true,
878
+ status,
879
+ title: `Title of ${url}`,
880
+ url,
881
+ };
882
+ }
883
+
884
+ function navigate(url, transitionType) {
885
+ chromeApiMock.tabs.onUpdated.dispatch(
886
+ TAB_ID,
887
+ { status: 'loading', url },
888
+ tab(url, 'loading'),
889
+ );
890
+ chromeApiMock.webNavigation.onCommitted.dispatch({
891
+ tabId: TAB_ID,
892
+ frameId: 0,
893
+ parentFrameId: -1,
894
+ url,
895
+ transitionType,
896
+ });
897
+ chromeApiMock.tabs.onUpdated.dispatch(
898
+ TAB_ID,
899
+ { status: 'complete' },
900
+ tab(url, 'complete'),
901
+ );
902
+ }
903
+
904
+ // like "initMocks", but the state is kept in the (fake) session storage
905
+ async function startPages({ openTabs }) {
906
+ chromeApiMock.tabs.query = async () => openTabs;
907
+ uut = new Pages({
908
+ config: { pages: { chrome: chromeApiMock } },
909
+ urlAnalyzer,
910
+ newPageApprover: stubNewPageApprover(),
911
+ pageSessionStore: new SessionStorageWrapper({
912
+ sessionApi,
913
+ namespace: 'test',
914
+ }),
915
+ });
916
+ await uut.init();
917
+ await uut.blockUntilFullInit();
918
+ }
919
+
920
+ async function restart({ openTabs }) {
921
+ await uut.sessionStore.flush();
922
+ uut.unload();
923
+ await startPages({ openTabs });
924
+ }
925
+
926
+ beforeEach(async function () {
927
+ sessionApi = new FakeSessionApi();
928
+ await startPages({ openTabs: [] });
929
+
930
+ // the user opens a page, and then follows a link to another page
931
+ chromeApiMock.tabs.onActivated.dispatch({
932
+ tabId: TAB_ID,
933
+ windowId: WINDOW_ID,
934
+ });
935
+ navigate(URL_A, 'typed');
936
+ navigate(URL_B, 'link');
937
+ expect(uut.describeTab(TAB_ID)).to.include({ url: URL_B, ref: URL_A });
938
+ });
939
+
940
+ it('should keep the information about a tab that is still open', async function () {
941
+ await restart({ openTabs: [tab(URL_B, 'complete')] });
942
+
943
+ expect([...uut.openTabs.keys()]).to.eql([TAB_ID]);
944
+ expect(uut.describeTab(TAB_ID)).to.include({
945
+ url: URL_B,
946
+ ref: URL_A,
947
+ pageLoadMethod: 'full-page-load',
948
+ });
949
+ });
950
+
951
+ it('should drop the information if the tab shows another page now', async function () {
952
+ await restart({ openTabs: [tab(URL_A, 'complete')] });
953
+
954
+ expect([...uut.openTabs.keys()]).to.eql([TAB_ID]);
955
+ expect(uut.describeTab(TAB_ID).url).to.eql(URL_A);
956
+ expect(uut.describeTab(TAB_ID).ref).to.be.undefined;
957
+ });
958
+
959
+ it('should drop a tab that was closed', async function () {
960
+ await restart({ openTabs: [] });
961
+
962
+ expect([...uut.openTabs.keys()]).to.eql([]);
963
+ });
964
+ });
863
965
  });
864
966
  });
865
967
 
@@ -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
+ });