@whotracksme/reporting 12.1.16 → 12.1.18

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.18 (Thu Nov 19 2026)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - fixed: doublefetch ignored the download limit [#260](https://github.com/whotracksme/webextension-packages/pull/260) ([@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.17 (Thu Nov 19 2026)
14
+
15
+ #### 🐛 Bug Fix
16
+
17
+ - fixed: activity detection missed URLs with fragments [#259](https://github.com/whotracksme/webextension-packages/pull/259) ([@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.16 (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.16",
3
+ "version": "12.1.18",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./sanitizer": "./reporting/src/sanitizer.js",
@@ -312,7 +312,8 @@ function unbreakConfig(url) {
312
312
  }
313
313
 
314
314
  class CachedPageFetcher {
315
- constructor() {
315
+ constructor({ downloadLimit } = {}) {
316
+ this.downloadLimit = downloadLimit;
316
317
  this.urlToAsyncPageStructure = new Map();
317
318
  }
318
319
 
@@ -380,7 +381,7 @@ export default class DoublefetchPageHandler {
380
381
  newPageApprover,
381
382
 
382
383
  // by default, use a separate fetcher cache per job
383
- pageFetcherProvider = () => new CachedPageFetcher(),
384
+ pageFetcherProvider = (options) => new CachedPageFetcher(options),
384
385
  }) {
385
386
  this.sanitizer = requireParam(sanitizer);
386
387
  this.newPageApprover = requireParam(newPageApprover);
@@ -420,7 +421,9 @@ export default class DoublefetchPageHandler {
420
421
  throw new BadJobError('preDoublefetch missing');
421
422
  }
422
423
 
423
- const pageFetcher = this.pageFetcherProvider();
424
+ const pageFetcher = this.pageFetcherProvider({
425
+ downloadLimit: this.downloadLimit,
426
+ });
424
427
  const log = logger.debug.bind(logger.debug, `[doublefetch=${url}]`);
425
428
  const logWarn = logger.warn.bind(logger.warn, `[doublefetch=${url}]`);
426
429
  const withBaseUrl = (baseUrl) => ({ baseUrl, log, logWarn });
@@ -308,7 +308,9 @@ export default class PageDB {
308
308
  const url = normalizeUrl(url_);
309
309
  const persistedKey = this.urlsToPersistedKeys.get(url);
310
310
  if (persistedKey) {
311
- const score = activityEstimator.estimate(url, now);
311
+ // The estimator knows the page by the URL of the tab
312
+ // (it can have a fragment), not by the normalized URL.
313
+ const score = activityEstimator.estimate(url_, now);
312
314
  if (score > 0.0) {
313
315
  const updateScore = (entry) => {
314
316
  if (score > entry.aggregator.activity) {
@@ -10,6 +10,7 @@
10
10
  */
11
11
 
12
12
  import { expect, assert } from 'chai';
13
+ import sinon from 'sinon';
13
14
  import * as fc from 'fast-check';
14
15
 
15
16
  import Sanitizer from '../src/sanitizer';
@@ -990,6 +991,75 @@ describe('DoublefetchPageHandler', function () {
990
991
  expect(details).to.be.a('string').that.is.not.empty;
991
992
  });
992
993
  });
994
+
995
+ describe('with the default page fetcher', function () {
996
+ const url = 'https://example.com/some/article';
997
+ let fetchStub;
998
+ let numDownloads;
999
+
1000
+ function mockServerResponse({ contentLength }) {
1001
+ fetchStub.callsFake(async (requestedUrl) => ({
1002
+ ok: true,
1003
+ status: 200,
1004
+ type: 'basic',
1005
+ url: requestedUrl,
1006
+ headers: new Headers({
1007
+ 'content-type': 'text/html',
1008
+ 'content-length': String(contentLength),
1009
+ }),
1010
+ async text() {
1011
+ numDownloads += 1;
1012
+ return '<!doctype html><html><head><title>Some article</title></head></html>';
1013
+ },
1014
+ }));
1015
+ }
1016
+
1017
+ function somePage() {
1018
+ return {
1019
+ url,
1020
+ title: 'Some article',
1021
+ status: 'complete',
1022
+ pageLoadMethod: 'full-page-load',
1023
+ preDoublefetch: {
1024
+ title: 'Some article',
1025
+ url,
1026
+ noindex: false,
1027
+ meta: {},
1028
+ },
1029
+ aggregator: { activity: 0.1 },
1030
+ };
1031
+ }
1032
+
1033
+ beforeEach(function () {
1034
+ numDownloads = 0;
1035
+ fetchStub = sinon.stub(globalThis, 'fetch');
1036
+ uut = new DoublefetchPageHandler({
1037
+ jobScheduler,
1038
+ sanitizer,
1039
+ newPageApprover,
1040
+ });
1041
+ });
1042
+
1043
+ afterEach(function () {
1044
+ fetchStub.restore();
1045
+ });
1046
+
1047
+ it('should download a page that is smaller than the download limit', async function () {
1048
+ mockServerResponse({ contentLength: uut.downloadLimit - 1 });
1049
+
1050
+ await uut.runJob(somePage());
1051
+ expect(numDownloads).to.eql(1);
1052
+ });
1053
+
1054
+ it('should not download a page that is bigger than the download limit', async function () {
1055
+ mockServerResponse({ contentLength: uut.downloadLimit + 1 });
1056
+
1057
+ const { ok, details } = await uut.runJob(somePage());
1058
+ expect(ok).to.be.false;
1059
+ expect(details).to.include('Exceeded size limit');
1060
+ expect(numDownloads).to.eql(0);
1061
+ });
1062
+ });
993
1063
  });
994
1064
 
995
1065
  describe('#titlesMatchAfterDoublefetch', function () {
@@ -267,6 +267,21 @@ describe('#PageDB', function () {
267
267
  await expectUrlsInDb([simplUrl]);
268
268
  await passesSelfChecks();
269
269
  });
270
+
271
+ it('should update the activity of a page that has a URL fragment', async function () {
272
+ const simpleUrl = 'https://de.wikipedia.test/wiki/Elefanten';
273
+ const urlInTab = `${simpleUrl}#Verbreitung`;
274
+ await uut.updatePages([somePage({ url: urlInTab })], undefined);
275
+
276
+ // the activity estimator knows only the URL of the tab
277
+ const activityEstimator = {
278
+ estimate: (url) => (url === urlInTab ? 0.5 : 0.0),
279
+ };
280
+ await uut.updateActivity([urlInTab], activityEstimator);
281
+
282
+ const { memory } = await uut.describeState({ inMemoryOnly: true });
283
+ expect(memory[simpleUrl].aggregator.activity).to.eql(0.5);
284
+ });
270
285
  });
271
286
 
272
287
  describe('emergency cleanup', function () {