@whotracksme/reporting 7.2.0 โ†’ 7.4.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ # v7.4.0 (Tue Jul 01 2025)
2
+
3
+ #### ๐Ÿš€ Enhancement
4
+
5
+ - Remove browserInfoProvider dependency [#162](https://github.com/whotracksme/webextension-packages/pull/162) ([@philipp-classen](https://github.com/philipp-classen))
6
+
7
+ #### ๐Ÿ  Internal
8
+
9
+ - Uses the staging patterns for the example extension [#161](https://github.com/whotracksme/webextension-packages/pull/161) ([@philipp-classen](https://github.com/philipp-classen))
10
+
11
+ #### Authors: 1
12
+
13
+ - Philipp ClaรŸen ([@philipp-classen](https://github.com/philipp-classen))
14
+
15
+ ---
16
+
17
+ # v7.3.0 (Wed May 21 2025)
18
+
19
+ #### ๐Ÿš€ Enhancement
20
+
21
+ - Added missing header overwrite in doublefetch [#160](https://github.com/whotracksme/webextension-packages/pull/160) ([@philipp-classen](https://github.com/philipp-classen))
22
+
23
+ #### Authors: 1
24
+
25
+ - Philipp ClaรŸen ([@philipp-classen](https://github.com/philipp-classen))
26
+
27
+ ---
28
+
1
29
  # v7.2.0 (Mon May 19 2025)
2
30
 
3
31
  #### ๐Ÿš€ Enhancement
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "7.2.0",
3
+ "version": "7.4.0",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {
@@ -46,6 +46,7 @@
46
46
  "idb": "^7.1.1",
47
47
  "linkedom": "^0.18.10",
48
48
  "pako": "^2.1.0",
49
- "tldts-experimental": "^6.0.11"
49
+ "tldts-experimental": "^6.0.11",
50
+ "bowser": "^2.11.0"
50
51
  }
51
52
  }
@@ -73,7 +73,8 @@ const communication = {
73
73
  const config = {
74
74
  url: {
75
75
  ALLOWED_COUNTRY_CODES: ['de'],
76
- PATTERNS_URL: 'https://cdn2.ghostery.com/wtm-chrome-desktop/patterns.json',
76
+ PATTERNS_URL:
77
+ 'https://cdn2.ghostery.com/staging-patterns/wtm-chrome-desktop/patterns.json',
77
78
  CONFIG_URL: 'https://api.ghostery.net/api/v1/config',
78
79
  },
79
80
  request: {
@@ -88,7 +89,6 @@ const urlReporter = new UrlReporter({
88
89
  storage: createStorage(),
89
90
  connectDatabase: createStorage,
90
91
  communication,
91
- browserInfoProvider: async () => ({ browser: 'test' }),
92
92
  });
93
93
 
94
94
  const requestReporter = new RequestReporter(config.request, {
@@ -1619,7 +1619,7 @@
1619
1619
  },
1620
1620
  "ts": "",
1621
1621
  "type": "wtm.request",
1622
- "userAgent": "xx"
1622
+ "userAgent": ""
1623
1623
  },
1624
1624
  {
1625
1625
  "action": "wtm.attrack.tp_events",
@@ -3251,7 +3251,7 @@
3251
3251
  },
3252
3252
  "ts": "",
3253
3253
  "type": "wtm.request",
3254
- "userAgent": "xx"
3254
+ "userAgent": ""
3255
3255
  },
3256
3256
  {
3257
3257
  "action": "wtm.attrack.tokensv2",
@@ -3272,7 +3272,7 @@
3272
3272
  },
3273
3273
  "ts": "",
3274
3274
  "type": "wtm.request",
3275
- "userAgent": "xx"
3275
+ "userAgent": ""
3276
3276
  },
3277
3277
  {
3278
3278
  "action": "wtm.attrack.keysv2",
@@ -3462,7 +3462,7 @@
3462
3462
  },
3463
3463
  "ts": "",
3464
3464
  "type": "wtm.request",
3465
- "userAgent": "xx"
3465
+ "userAgent": ""
3466
3466
  },
3467
3467
  {
3468
3468
  "action": "wtm.attrack.keysv2",
@@ -3652,7 +3652,7 @@
3652
3652
  },
3653
3653
  "ts": "",
3654
3654
  "type": "wtm.request",
3655
- "userAgent": "xx"
3655
+ "userAgent": ""
3656
3656
  },
3657
3657
  {
3658
3658
  "action": "wtm.attrack.keysv2",
@@ -3678,7 +3678,7 @@
3678
3678
  },
3679
3679
  "ts": "",
3680
3680
  "type": "wtm.request",
3681
- "userAgent": "xx"
3681
+ "userAgent": ""
3682
3682
  },
3683
3683
  {
3684
3684
  "action": "wtm.attrack.keysv2",
@@ -3704,7 +3704,7 @@
3704
3704
  },
3705
3705
  "ts": "",
3706
3706
  "type": "wtm.request",
3707
- "userAgent": "xx"
3707
+ "userAgent": ""
3708
3708
  },
3709
3709
  {
3710
3710
  "action": "wtm.attrack.keysv2",
@@ -3730,7 +3730,7 @@
3730
3730
  },
3731
3731
  "ts": "",
3732
3732
  "type": "wtm.request",
3733
- "userAgent": "xx"
3733
+ "userAgent": ""
3734
3734
  },
3735
3735
  {
3736
3736
  "action": "wtm.attrack.keysv2",
@@ -3756,7 +3756,7 @@
3756
3756
  },
3757
3757
  "ts": "",
3758
3758
  "type": "wtm.request",
3759
- "userAgent": "xx"
3759
+ "userAgent": ""
3760
3760
  },
3761
3761
  {
3762
3762
  "action": "wtm.attrack.keysv2",
@@ -3782,7 +3782,7 @@
3782
3782
  },
3783
3783
  "ts": "",
3784
3784
  "type": "wtm.request",
3785
- "userAgent": "xx"
3785
+ "userAgent": ""
3786
3786
  },
3787
3787
  {
3788
3788
  "action": "wtm.attrack.keysv2",
@@ -3808,7 +3808,7 @@
3808
3808
  },
3809
3809
  "ts": "",
3810
3810
  "type": "wtm.request",
3811
- "userAgent": "xx"
3811
+ "userAgent": ""
3812
3812
  },
3813
3813
  {
3814
3814
  "action": "wtm.attrack.keysv2",
@@ -3834,7 +3834,7 @@
3834
3834
  },
3835
3835
  "ts": "",
3836
3836
  "type": "wtm.request",
3837
- "userAgent": "xx"
3837
+ "userAgent": ""
3838
3838
  },
3839
3839
  {
3840
3840
  "action": "wtm.attrack.keysv2",
@@ -3860,6 +3860,6 @@
3860
3860
  },
3861
3861
  "ts": "",
3862
3862
  "type": "wtm.request",
3863
- "userAgent": "xx"
3863
+ "userAgent": ""
3864
3864
  }
3865
- ]
3865
+ ]
@@ -1108,7 +1108,7 @@
1108
1108
  },
1109
1109
  "ts": "",
1110
1110
  "type": "wtm.request",
1111
- "userAgent": "xx"
1111
+ "userAgent": ""
1112
1112
  },
1113
1113
  {
1114
1114
  "action": "wtm.attrack.tp_events",
@@ -2225,7 +2225,7 @@
2225
2225
  },
2226
2226
  "ts": "",
2227
2227
  "type": "wtm.request",
2228
- "userAgent": "xx"
2228
+ "userAgent": ""
2229
2229
  },
2230
2230
  {
2231
2231
  "action": "wtm.attrack.tokensv2",
@@ -2246,7 +2246,7 @@
2246
2246
  },
2247
2247
  "ts": "",
2248
2248
  "type": "wtm.request",
2249
- "userAgent": "xx"
2249
+ "userAgent": ""
2250
2250
  },
2251
2251
  {
2252
2252
  "action": "wtm.attrack.keysv2",
@@ -2272,7 +2272,7 @@
2272
2272
  },
2273
2273
  "ts": "",
2274
2274
  "type": "wtm.request",
2275
- "userAgent": "xx"
2275
+ "userAgent": ""
2276
2276
  },
2277
2277
  {
2278
2278
  "action": "wtm.attrack.keysv2",
@@ -2298,7 +2298,7 @@
2298
2298
  },
2299
2299
  "ts": "",
2300
2300
  "type": "wtm.request",
2301
- "userAgent": "xx"
2301
+ "userAgent": ""
2302
2302
  },
2303
2303
  {
2304
2304
  "action": "wtm.attrack.keysv2",
@@ -2324,7 +2324,7 @@
2324
2324
  },
2325
2325
  "ts": "",
2326
2326
  "type": "wtm.request",
2327
- "userAgent": "xx"
2327
+ "userAgent": ""
2328
2328
  },
2329
2329
  {
2330
2330
  "action": "wtm.attrack.keysv2",
@@ -2350,7 +2350,7 @@
2350
2350
  },
2351
2351
  "ts": "",
2352
2352
  "type": "wtm.request",
2353
- "userAgent": "xx"
2353
+ "userAgent": ""
2354
2354
  },
2355
2355
  {
2356
2356
  "action": "wtm.attrack.keysv2",
@@ -2376,7 +2376,7 @@
2376
2376
  },
2377
2377
  "ts": "",
2378
2378
  "type": "wtm.request",
2379
- "userAgent": "xx"
2379
+ "userAgent": ""
2380
2380
  },
2381
2381
  {
2382
2382
  "action": "wtm.attrack.keysv2",
@@ -2402,7 +2402,7 @@
2402
2402
  },
2403
2403
  "ts": "",
2404
2404
  "type": "wtm.request",
2405
- "userAgent": "xx"
2405
+ "userAgent": ""
2406
2406
  },
2407
2407
  {
2408
2408
  "action": "wtm.attrack.keysv2",
@@ -2428,7 +2428,7 @@
2428
2428
  },
2429
2429
  "ts": "",
2430
2430
  "type": "wtm.request",
2431
- "userAgent": "xx"
2431
+ "userAgent": ""
2432
2432
  },
2433
2433
  {
2434
2434
  "action": "wtm.attrack.keysv2",
@@ -2454,7 +2454,7 @@
2454
2454
  },
2455
2455
  "ts": "",
2456
2456
  "type": "wtm.request",
2457
- "userAgent": "xx"
2457
+ "userAgent": ""
2458
2458
  },
2459
2459
  {
2460
2460
  "action": "wtm.attrack.keysv2",
@@ -2480,7 +2480,7 @@
2480
2480
  },
2481
2481
  "ts": "",
2482
2482
  "type": "wtm.request",
2483
- "userAgent": "xx"
2483
+ "userAgent": ""
2484
2484
  },
2485
2485
  {
2486
2486
  "action": "wtm.attrack.keysv2",
@@ -2506,6 +2506,6 @@
2506
2506
  },
2507
2507
  "ts": "",
2508
2508
  "type": "wtm.request",
2509
- "userAgent": "xx"
2509
+ "userAgent": ""
2510
2510
  }
2511
- ]
2511
+ ]
@@ -196,7 +196,7 @@
196
196
  },
197
197
  "ts": "",
198
198
  "type": "wtm.request",
199
- "userAgent": "xx"
199
+ "userAgent": ""
200
200
  },
201
201
  {
202
202
  "action": "wtm.attrack.tp_events",
@@ -398,7 +398,7 @@
398
398
  },
399
399
  "ts": "",
400
400
  "type": "wtm.request",
401
- "userAgent": "xx"
401
+ "userAgent": ""
402
402
  },
403
403
  {
404
404
  "action": "wtm.attrack.tokensv2",
@@ -419,7 +419,7 @@
419
419
  },
420
420
  "ts": "",
421
421
  "type": "wtm.request",
422
- "userAgent": "xx"
422
+ "userAgent": ""
423
423
  },
424
424
  {
425
425
  "action": "wtm.attrack.keysv2",
@@ -609,7 +609,7 @@
609
609
  },
610
610
  "ts": "",
611
611
  "type": "wtm.request",
612
- "userAgent": "xx"
612
+ "userAgent": ""
613
613
  },
614
614
  {
615
615
  "action": "wtm.attrack.keysv2",
@@ -799,6 +799,6 @@
799
799
  },
800
800
  "ts": "",
801
801
  "type": "wtm.request",
802
- "userAgent": "xx"
802
+ "userAgent": ""
803
803
  }
804
- ]
804
+ ]
@@ -183,7 +183,7 @@
183
183
  },
184
184
  "ts": "",
185
185
  "type": "wtm.request",
186
- "userAgent": "xx"
186
+ "userAgent": ""
187
187
  },
188
188
  {
189
189
  "action": "wtm.attrack.tp_events",
@@ -369,7 +369,7 @@
369
369
  },
370
370
  "ts": "",
371
371
  "type": "wtm.request",
372
- "userAgent": "xx"
372
+ "userAgent": ""
373
373
  },
374
374
  {
375
375
  "action": "wtm.attrack.tokensv2",
@@ -390,7 +390,7 @@
390
390
  },
391
391
  "ts": "",
392
392
  "type": "wtm.request",
393
- "userAgent": "xx"
393
+ "userAgent": ""
394
394
  },
395
395
  {
396
396
  "action": "wtm.attrack.keysv2",
@@ -572,7 +572,7 @@
572
572
  },
573
573
  "ts": "",
574
574
  "type": "wtm.request",
575
- "userAgent": "xx"
575
+ "userAgent": ""
576
576
  },
577
577
  {
578
578
  "action": "wtm.attrack.keysv2",
@@ -754,6 +754,6 @@
754
754
  },
755
755
  "ts": "",
756
756
  "type": "wtm.request",
757
- "userAgent": "xx"
757
+ "userAgent": ""
758
758
  }
759
- ]
759
+ ]
@@ -130,7 +130,7 @@
130
130
  },
131
131
  "ts": "",
132
132
  "type": "wtm.request",
133
- "userAgent": "xx"
133
+ "userAgent": ""
134
134
  },
135
135
  {
136
136
  "action": "wtm.attrack.tp_events",
@@ -252,7 +252,7 @@
252
252
  },
253
253
  "ts": "",
254
254
  "type": "wtm.request",
255
- "userAgent": "xx"
255
+ "userAgent": ""
256
256
  },
257
257
  {
258
258
  "action": "wtm.attrack.tp_events",
@@ -693,7 +693,7 @@
693
693
  },
694
694
  "ts": "",
695
695
  "type": "wtm.request",
696
- "userAgent": "xx"
696
+ "userAgent": ""
697
697
  },
698
698
  {
699
699
  "action": "wtm.attrack.tp_events",
@@ -1142,7 +1142,7 @@
1142
1142
  },
1143
1143
  "ts": "",
1144
1144
  "type": "wtm.request",
1145
- "userAgent": "xx"
1145
+ "userAgent": ""
1146
1146
  },
1147
1147
  {
1148
1148
  "action": "wtm.attrack.tp_events",
@@ -1275,7 +1275,7 @@
1275
1275
  },
1276
1276
  "ts": "",
1277
1277
  "type": "wtm.request",
1278
- "userAgent": "xx"
1278
+ "userAgent": ""
1279
1279
  },
1280
1280
  {
1281
1281
  "action": "wtm.attrack.tp_events",
@@ -1397,7 +1397,7 @@
1397
1397
  },
1398
1398
  "ts": "",
1399
1399
  "type": "wtm.request",
1400
- "userAgent": "xx"
1400
+ "userAgent": ""
1401
1401
  },
1402
1402
  {
1403
1403
  "action": "wtm.attrack.tp_events",
@@ -1838,7 +1838,7 @@
1838
1838
  },
1839
1839
  "ts": "",
1840
1840
  "type": "wtm.request",
1841
- "userAgent": "xx"
1841
+ "userAgent": ""
1842
1842
  },
1843
1843
  {
1844
1844
  "action": "wtm.attrack.tp_events",
@@ -2287,7 +2287,7 @@
2287
2287
  },
2288
2288
  "ts": "",
2289
2289
  "type": "wtm.request",
2290
- "userAgent": "xx"
2290
+ "userAgent": ""
2291
2291
  },
2292
2292
  {
2293
2293
  "action": "wtm.attrack.tokensv2",
@@ -2308,7 +2308,7 @@
2308
2308
  },
2309
2309
  "ts": "",
2310
2310
  "type": "wtm.request",
2311
- "userAgent": "xx"
2311
+ "userAgent": ""
2312
2312
  },
2313
2313
  {
2314
2314
  "action": "wtm.attrack.keysv2",
@@ -4590,7 +4590,7 @@
4590
4590
  },
4591
4591
  "ts": "",
4592
4592
  "type": "wtm.request",
4593
- "userAgent": "xx"
4593
+ "userAgent": ""
4594
4594
  },
4595
4595
  {
4596
4596
  "action": "wtm.attrack.keysv2",
@@ -6876,7 +6876,7 @@
6876
6876
  },
6877
6877
  "ts": "",
6878
6878
  "type": "wtm.request",
6879
- "userAgent": "xx"
6879
+ "userAgent": ""
6880
6880
  },
6881
6881
  {
6882
6882
  "action": "wtm.attrack.keysv2",
@@ -6902,7 +6902,7 @@
6902
6902
  },
6903
6903
  "ts": "",
6904
6904
  "type": "wtm.request",
6905
- "userAgent": "xx"
6905
+ "userAgent": ""
6906
6906
  },
6907
6907
  {
6908
6908
  "action": "wtm.attrack.keysv2",
@@ -6928,6 +6928,6 @@
6928
6928
  },
6929
6929
  "ts": "",
6930
6930
  "type": "wtm.request",
6931
- "userAgent": "xx"
6931
+ "userAgent": ""
6932
6932
  }
6933
- ]
6933
+ ]
@@ -111,7 +111,7 @@
111
111
  },
112
112
  "ts": "",
113
113
  "type": "wtm.request",
114
- "userAgent": "xx"
114
+ "userAgent": ""
115
115
  },
116
116
  {
117
117
  "action": "wtm.attrack.tp_events",
@@ -237,7 +237,7 @@
237
237
  },
238
238
  "ts": "",
239
239
  "type": "wtm.request",
240
- "userAgent": "xx"
240
+ "userAgent": ""
241
241
  },
242
242
  {
243
243
  "action": "wtm.attrack.tp_events",
@@ -408,7 +408,7 @@
408
408
  },
409
409
  "ts": "",
410
410
  "type": "wtm.request",
411
- "userAgent": "xx"
411
+ "userAgent": ""
412
412
  },
413
413
  {
414
414
  "action": "wtm.attrack.tp_events",
@@ -526,7 +526,7 @@
526
526
  },
527
527
  "ts": "",
528
528
  "type": "wtm.request",
529
- "userAgent": "xx"
529
+ "userAgent": ""
530
530
  },
531
531
  {
532
532
  "action": "wtm.attrack.tp_events",
@@ -1006,7 +1006,7 @@
1006
1006
  },
1007
1007
  "ts": "",
1008
1008
  "type": "wtm.request",
1009
- "userAgent": "xx"
1009
+ "userAgent": ""
1010
1010
  },
1011
1011
  {
1012
1012
  "action": "wtm.attrack.tp_events",
@@ -1120,7 +1120,7 @@
1120
1120
  },
1121
1121
  "ts": "",
1122
1122
  "type": "wtm.request",
1123
- "userAgent": "xx"
1123
+ "userAgent": ""
1124
1124
  },
1125
1125
  {
1126
1126
  "action": "wtm.attrack.tp_events",
@@ -1246,7 +1246,7 @@
1246
1246
  },
1247
1247
  "ts": "",
1248
1248
  "type": "wtm.request",
1249
- "userAgent": "xx"
1249
+ "userAgent": ""
1250
1250
  },
1251
1251
  {
1252
1252
  "action": "wtm.attrack.tp_events",
@@ -1417,7 +1417,7 @@
1417
1417
  },
1418
1418
  "ts": "",
1419
1419
  "type": "wtm.request",
1420
- "userAgent": "xx"
1420
+ "userAgent": ""
1421
1421
  },
1422
1422
  {
1423
1423
  "action": "wtm.attrack.tp_events",
@@ -1535,7 +1535,7 @@
1535
1535
  },
1536
1536
  "ts": "",
1537
1537
  "type": "wtm.request",
1538
- "userAgent": "xx"
1538
+ "userAgent": ""
1539
1539
  },
1540
1540
  {
1541
1541
  "action": "wtm.attrack.tp_events",
@@ -2015,7 +2015,7 @@
2015
2015
  },
2016
2016
  "ts": "",
2017
2017
  "type": "wtm.request",
2018
- "userAgent": "xx"
2018
+ "userAgent": ""
2019
2019
  },
2020
2020
  {
2021
2021
  "action": "wtm.attrack.tokensv2",
@@ -2036,7 +2036,7 @@
2036
2036
  },
2037
2037
  "ts": "",
2038
2038
  "type": "wtm.request",
2039
- "userAgent": "xx"
2039
+ "userAgent": ""
2040
2040
  },
2041
2041
  {
2042
2042
  "action": "wtm.attrack.keysv2",
@@ -3734,7 +3734,7 @@
3734
3734
  },
3735
3735
  "ts": "",
3736
3736
  "type": "wtm.request",
3737
- "userAgent": "xx"
3737
+ "userAgent": ""
3738
3738
  },
3739
3739
  {
3740
3740
  "action": "wtm.attrack.keysv2",
@@ -5432,7 +5432,7 @@
5432
5432
  },
5433
5433
  "ts": "",
5434
5434
  "type": "wtm.request",
5435
- "userAgent": "xx"
5435
+ "userAgent": ""
5436
5436
  },
5437
5437
  {
5438
5438
  "action": "wtm.attrack.keysv2",
@@ -5458,7 +5458,7 @@
5458
5458
  },
5459
5459
  "ts": "",
5460
5460
  "type": "wtm.request",
5461
- "userAgent": "xx"
5461
+ "userAgent": ""
5462
5462
  },
5463
5463
  {
5464
5464
  "action": "wtm.attrack.keysv2",
@@ -5484,6 +5484,6 @@
5484
5484
  },
5485
5485
  "ts": "",
5486
5486
  "type": "wtm.request",
5487
- "userAgent": "xx"
5487
+ "userAgent": ""
5488
5488
  }
5489
- ]
5489
+ ]
@@ -10,7 +10,8 @@
10
10
  */
11
11
 
12
12
  import logger from './logger';
13
- import { requireParam, requireString, lazyInitAsync } from './utils';
13
+ import { requireParam, requireString } from './utils';
14
+ import Bowser from 'bowser';
14
15
 
15
16
  /**
16
17
  * Responsible for generating information to be included in the "alive" message.
@@ -24,27 +25,21 @@ import { requireParam, requireString, lazyInitAsync } from './utils';
24
25
  * breaks something on Windows.
25
26
  */
26
27
  export default class AliveMessageGenerator {
27
- constructor({
28
- browserInfoProvider,
29
- navigatorApi,
30
- quorumChecker,
31
- storage,
32
- storageKey,
33
- }) {
34
- requireParam(browserInfoProvider);
28
+ constructor({ navigatorApi, quorumChecker, storage, storageKey }) {
35
29
  this.quorumChecker = requireParam(quorumChecker);
36
30
  this.storage = requireParam(storage);
37
31
  this.storageKey = requireString(storageKey);
38
32
  this.navigatorApi = navigatorApi || globalThis.navigator;
33
+ }
39
34
 
40
- this.staticConfigProvider = lazyInitAsync(async () =>
41
- this._generateBaseConfig(await browserInfoProvider()),
42
- );
35
+ get staticConfig() {
36
+ this._staticConfig ||= this._generateBaseConfig();
37
+ return this._staticConfig;
43
38
  }
44
39
 
45
40
  async generateMessage(ctry, hour) {
46
41
  const config = {
47
- ...(await this.staticConfigProvider()),
42
+ ...this.staticConfig,
48
43
  ctry,
49
44
  };
50
45
 
@@ -71,35 +66,37 @@ export default class AliveMessageGenerator {
71
66
  browser: '',
72
67
  version: '',
73
68
  os: '',
69
+ platform: '',
70
+ engine: '',
74
71
  language: '',
75
72
  ctry: '--',
76
73
  t: hour,
77
74
  };
78
75
  }
79
76
 
80
- _generateBaseConfig(browserInfo) {
81
- // extracts only the major version (e.g. "96.0.1" -> 96)
82
- let version = parseInt(browserInfo.version, 10);
83
- if (isNaN(version)) {
84
- version = '';
85
- } else {
86
- version = String(version);
87
- }
77
+ _generateBaseConfig() {
78
+ let browser, version, os, platform, engine;
79
+ const { language, userAgent } = this.navigatorApi;
80
+ if (userAgent) {
81
+ const browserInfo = Bowser.parse(userAgent);
82
+ browser = browserInfo.browser?.name;
83
+ os = browserInfo.os?.name;
84
+ platform = browserInfo.platform?.type;
85
+ engine = browserInfo.engine?.name;
88
86
 
89
- let language;
90
- try {
91
- language = this.navigatorApi.language;
92
- } catch (e) {
93
- logger.warn(
94
- '"navigator" API unavailable (should only happen when run in NodeJs 20 or lower)',
95
- );
87
+ // extracts only the major version (e.g. "96.0.1" -> 96)
88
+ const majorVersion = parseInt(browserInfo.browser?.version, 10);
89
+ if (!isNaN(majorVersion)) {
90
+ version = String(majorVersion);
91
+ }
96
92
  }
97
- language = language || '';
98
93
 
99
94
  return {
100
- browser: browserInfo.browser || '',
101
- version, // major version
102
- os: browserInfo.os || '',
95
+ browser: browser || '',
96
+ version: version || '', // major version
97
+ os: os || '',
98
+ platform: platform || '', // e.g. 'desktop'
99
+ engine: engine || '', // e.g. 'Blink'
103
100
  language: language || '', // e.g. 'en-US'
104
101
  };
105
102
  }
@@ -28,6 +28,39 @@ const SECOND = 1000;
28
28
  const RESERVED_DNR_RULE_ID_HEADER_OVERRIDE = 1333;
29
29
  const RESERVED_DNR_RULE_ID_OFFSCREEN = 1334;
30
30
 
31
+ /**
32
+ * Depending on the context, there are different ways how requests are being
33
+ * triggered. For instance, the normal one is to use the fetch API; but
34
+ * with dynamic rendering using offscreen, it will be technically triggered
35
+ * from an iframe. That impacts how APIs should be later interpreted.
36
+ */
37
+ const REQUEST_TYPE = {
38
+ FETCH_API: Symbol('FETCH_API'),
39
+ IFRAME: Symbol('IFRAME'),
40
+ };
41
+
42
+ // maps our REQUEST_TYPE to the type used in the webRequestAPI
43
+ function matchesWebRequestApiType(requestType, webRequestApiType) {
44
+ if (requestType === REQUEST_TYPE.FETCH_API) {
45
+ return webRequestApiType === 'xmlhttprequest';
46
+ }
47
+ if (requestType === REQUEST_TYPE.IFRAME) {
48
+ return webRequestApiType === 'sub_frame';
49
+ }
50
+ throw new Error(`Unexpected requestType: ${requestType}`);
51
+ }
52
+
53
+ // maps our REQUEST_TYPE to the resource Type array used by the DNR API
54
+ function requestTypeToDNRResourceTypes(requestType) {
55
+ if (requestType === REQUEST_TYPE.FETCH_API) {
56
+ return ['xmlhttprequest'];
57
+ }
58
+ if (requestType === REQUEST_TYPE.IFRAME) {
59
+ return ['sub_frame'];
60
+ }
61
+ throw new Error(`Unexpected requestType: ${requestType}`);
62
+ }
63
+
31
64
  function getExtensionDomain() {
32
65
  getExtensionDomain.cached =
33
66
  getExtensionDomain.cached || new URL(chrome.runtime.getURL('')).host;
@@ -110,6 +143,29 @@ const httpStatusCodesThatShouldBeRetried = [
110
143
  599, // Network Connect Timeout Error
111
144
  ];
112
145
 
146
+ // Overwrites the headers of the request to the given URL.
147
+ // It automatically selects the mechanism (e.g. webRequestAPI, DNR)
148
+ // based on the available APIs.
149
+ //
150
+ // Returns a cleanup callback to undo the changes.
151
+ async function headerOverride(params) {
152
+ const { headers } = params;
153
+ if (!headers || Object.keys(headers).length === 0) {
154
+ return () => {};
155
+ }
156
+
157
+ if (
158
+ chrome?.webRequest?.onBeforeSendHeaders &&
159
+ chrome.runtime.getManifest().permissions.includes('webRequestBlocking')
160
+ ) {
161
+ return headerOverrideViaWebRequestAPI(params);
162
+ } else if (chrome?.declarativeNetRequest?.updateSessionRules) {
163
+ return await headerOverrideViaDNR(params);
164
+ } else {
165
+ throw new UnableToOverrideHeadersError();
166
+ }
167
+ }
168
+
113
169
  // The following code overwrite the headers of the request.
114
170
  // Note that "fetch" allows to overwrite headers in a simple declarative way,
115
171
  // but unfortunately it is limited. For example, it is not possible to
@@ -122,13 +178,13 @@ const httpStatusCodesThatShouldBeRetried = [
122
178
  // side-effects. To mitigate the risk, uninstall the handler at the first
123
179
  // opportunity: either if it is called or if the request finished
124
180
  // (and we know the handle will never be called).
125
- function headerOverrideViaWebRequestAPI(url, headers) {
181
+ function headerOverrideViaWebRequestAPI({ url, headers, requestType }) {
126
182
  let uninstallHandler;
127
183
  let webRequestHandler = (details) => {
128
184
  if (
129
185
  details.url !== url ||
130
- details.type !== 'xmlhttprequest' ||
131
- details.method !== 'GET'
186
+ details.method !== 'GET' ||
187
+ !matchesWebRequestApiType(requestType, details.type)
132
188
  ) {
133
189
  // does that match the request that we intended to trigger
134
190
  return {};
@@ -177,7 +233,7 @@ function headerOverrideViaWebRequestAPI(url, headers) {
177
233
  }
178
234
 
179
235
  // Like headerOverrideViaWebRequestAPI, but using the DNR API.
180
- async function headerOverrideViaDNR(url, headers) {
236
+ async function headerOverrideViaDNR({ url, headers, requestType }) {
181
237
  const requestHeaders = Object.entries(headers).map(([header, value]) => ({
182
238
  header,
183
239
  operation: 'set',
@@ -192,22 +248,52 @@ async function headerOverrideViaDNR(url, headers) {
192
248
  },
193
249
  condition: {
194
250
  urlFilter: url,
195
- resourceTypes: ['xmlhttprequest'],
251
+ resourceTypes: requestTypeToDNRResourceTypes(requestType),
196
252
  initiatorDomains: [getExtensionDomain()],
197
253
  },
198
254
  };
255
+
199
256
  logger.debug('Installing temporary DNR rule for URL:', url);
200
- await chrome.declarativeNetRequest.updateSessionRules({
201
- addRules: [rule],
202
- });
257
+ const cleanup = await addDNRSessionRule(rule);
258
+
203
259
  return () => {
204
260
  logger.debug('Removing temporary DNR rule for URL:', url);
205
- chrome.declarativeNetRequest
261
+ return cleanup();
262
+ };
263
+ }
264
+
265
+ async function addDNRSessionRule(rule) {
266
+ try {
267
+ await chrome.declarativeNetRequest.updateSessionRules({ addRules: [rule] });
268
+ } catch (e) {
269
+ try {
270
+ logger.warn(
271
+ 'Unable to install DNR rule. Trying to delete rule first:',
272
+ rule,
273
+ e,
274
+ );
275
+ await chrome.declarativeNetRequest.updateSessionRules({
276
+ removeRuleIds: [rule.id],
277
+ });
278
+ } catch (e2) {
279
+ logger.warn('Retry not possible (unable to remove DNR rule):', rule, e2);
280
+ throw e;
281
+ }
282
+
283
+ logger.debug('Second attempt to install DNR rule:', rule);
284
+ await chrome.declarativeNetRequest.updateSessionRules({
285
+ addRules: [rule],
286
+ });
287
+ logger.debug('Succeed in install DNR rule on the second attempt:', rule);
288
+ }
289
+
290
+ return () => {
291
+ return chrome.declarativeNetRequest
206
292
  .updateSessionRules({
207
293
  removeRuleIds: [rule.id],
208
294
  })
209
295
  .catch((e) => {
210
- logger.warn('Failed to remove DNR rule', e);
296
+ logger.error('cleanup failed: unable to remove DNR rule:', rule, e);
211
297
  });
212
298
  };
213
299
  }
@@ -246,15 +332,15 @@ async function withOffscreenDocumentReady(url, headers, asyncCallback) {
246
332
  },
247
333
  };
248
334
 
249
- await chrome.declarativeNetRequest.updateSessionRules({
250
- removeRuleIds: [rule.id],
251
- addRules: [rule],
335
+ const undoDNRChange = await addDNRSessionRule(rule);
336
+ cleanups.push(undoDNRChange);
337
+
338
+ const undoHeaderOverride = await headerOverride({
339
+ headers,
340
+ url,
341
+ requestType: REQUEST_TYPE.IFRAME,
252
342
  });
253
- cleanups.push(() =>
254
- chrome.declarativeNetRequest.updateSessionRules({
255
- removeRuleIds: [rule.id],
256
- }),
257
- );
343
+ cleanups.push(undoHeaderOverride);
258
344
 
259
345
  const offscreenUrl = chrome.runtime.getURL(OFFSCREEN_DOCUMENT_PATH);
260
346
  const existingContexts = await chrome.runtime.getContexts({
@@ -330,22 +416,12 @@ async function singleHttpGetStep(url, params = {}) {
330
416
  }
331
417
 
332
418
  try {
333
- // optional cleanup operation that will be run after the request is completed
334
- let cleanup = () => {};
335
- if (headers && Object.keys(headers).length > 0) {
336
- if (
337
- chrome?.webRequest?.onBeforeSendHeaders &&
338
- chrome.runtime.getManifest().permissions.includes('webRequestBlocking')
339
- ) {
340
- cleanup = headerOverrideViaWebRequestAPI(url, headers);
341
- } else if (chrome?.declarativeNetRequest?.updateSessionRules) {
342
- cleanup = await headerOverrideViaDNR(url, headers);
343
- } else {
344
- throw new UnableToOverrideHeadersError();
345
- }
346
- }
347
-
348
419
  let response;
420
+ const undoHeaderOverride = await headerOverride({
421
+ headers,
422
+ url,
423
+ requestType: REQUEST_TYPE.FETCH_API,
424
+ });
349
425
  try {
350
426
  response = await fetch(url, options);
351
427
  } catch (e) {
@@ -353,8 +429,9 @@ async function singleHttpGetStep(url, params = {}) {
353
429
  cause: e,
354
430
  });
355
431
  } finally {
356
- cleanup();
432
+ await undoHeaderOverride();
357
433
  }
434
+
358
435
  if (
359
436
  response.status === 0 &&
360
437
  (response.type == 'opaqueredirect' || response.type == 'opaque')
@@ -647,45 +724,49 @@ export async function anonymousHttpGet(originalUrl, params = {}) {
647
724
  // If needed, one idea is to use content scripts in the offscreen document.
648
725
  content = '';
649
726
 
650
- await withOffscreenDocumentReady(localUrl, localParams, async () => {
651
- const { ok, error } = await chrome.runtime.sendMessage({
652
- target: 'offscreen:urlReporting',
653
- type: 'request',
654
- data: { url: localUrl },
655
- });
656
- if (!ok) {
657
- throw new Error(
658
- `Unexpected error (details: ${error || '<unavailable>'})`,
659
- );
660
- }
727
+ await withOffscreenDocumentReady(
728
+ localUrl,
729
+ localParams.headers,
730
+ async () => {
731
+ const { ok, error } = await chrome.runtime.sendMessage({
732
+ target: 'offscreen:urlReporting',
733
+ type: 'request',
734
+ data: { url: localUrl },
735
+ });
736
+ if (!ok) {
737
+ throw new Error(
738
+ `Unexpected error (details: ${error || '<unavailable>'})`,
739
+ );
740
+ }
661
741
 
662
- let timeout = null;
663
- const timedOut = new Promise((resolve, reject) => {
664
- const maxTime = params.timeout || 15 * SECOND;
665
- timeout = setTimeout(() => {
666
- timeout = null;
667
- logger.warn(
668
- 'Dynamic fetch of URL',
669
- localUrl,
670
- 'exceeded the timeout of',
671
- maxTime,
672
- 'ms. Details:',
673
- {
742
+ let timeout = null;
743
+ const timedOut = new Promise((resolve, reject) => {
744
+ const maxTime = params.timeout || 15 * SECOND;
745
+ timeout = setTimeout(() => {
746
+ timeout = null;
747
+ logger.warn(
748
+ 'Dynamic fetch of URL',
674
749
  localUrl,
675
- currentStep,
676
- nextStep,
677
- ctx,
678
- },
679
- );
680
- reject(`Timeout when dynamically fetching ${localUrl}`);
681
- }, maxTime);
682
- });
683
- try {
684
- await Promise.race([readyForNextStep, timedOut]);
685
- } finally {
686
- clearTimeout(timeout);
687
- }
688
- });
750
+ 'exceeded the timeout of',
751
+ maxTime,
752
+ 'ms. Details:',
753
+ {
754
+ localUrl,
755
+ currentStep,
756
+ nextStep,
757
+ ctx,
758
+ },
759
+ );
760
+ reject(`Timeout when dynamically fetching ${localUrl}`);
761
+ }, maxTime);
762
+ });
763
+ try {
764
+ await Promise.race([readyForNextStep, timedOut]);
765
+ } finally {
766
+ clearTimeout(timeout);
767
+ }
768
+ },
769
+ );
689
770
  } else {
690
771
  content = await singleHttpGetStep(localUrl, localParams);
691
772
  }
@@ -38,13 +38,7 @@ import { BloomFilter } from './bloom-filters';
38
38
  const SECOND = 1000;
39
39
 
40
40
  export default class Reporting {
41
- constructor({
42
- config,
43
- storage,
44
- communication,
45
- connectDatabase,
46
- browserInfoProvider,
47
- }) {
41
+ constructor({ config, storage, communication, connectDatabase }) {
48
42
  // Defines whether Reporting is fully initialized and has permission
49
43
  // to collect data.
50
44
  this.isActive = false;
@@ -152,7 +146,6 @@ export default class Reporting {
152
146
  });
153
147
 
154
148
  const aliveMessageGenerator = new AliveMessageGenerator({
155
- browserInfoProvider,
156
149
  quorumChecker: this.quorumChecker,
157
150
  storage,
158
151
  storageKey: 'alive_config',
@@ -9,6 +9,8 @@
9
9
  * file, You can obtain one at http://mozilla.org/MPL/2.0
10
10
  */
11
11
 
12
+ import Bowser from 'bowser';
13
+
12
14
  /* eslint-disable no-param-reassign */
13
15
  import { isLocalIP } from '../network.js';
14
16
  import Config from './config.js';
@@ -42,13 +44,14 @@ const DAY_CHANGE_INTERVAL = 20 * 1000;
42
44
  const RECENTLY_MODIFIED_TTL = 30 * 1000;
43
45
 
44
46
  export default class RequestReporter {
47
+ #userAgent;
48
+
45
49
  constructor(
46
50
  settings,
47
51
  {
48
52
  trustedClock,
49
53
  countryProvider,
50
54
  onMessageReady,
51
- getBrowserInfo,
52
55
  onTrackerInteraction = (event, state) => {
53
56
  logger.info('Tracker', event, 'with url:', state.url);
54
57
  },
@@ -61,7 +64,6 @@ export default class RequestReporter {
61
64
  this.trustedClock = trustedClock;
62
65
  this.countryProvider = countryProvider;
63
66
  this.onTrackerInteraction = onTrackerInteraction;
64
- this.getBrowserInfo = getBrowserInfo;
65
67
  this.isRequestAllowed = isRequestAllowed;
66
68
  if (dryRunMode) {
67
69
  logger.warn(
@@ -166,6 +168,30 @@ export default class RequestReporter {
166
168
  this.onMessageReady(message);
167
169
  }
168
170
 
171
+ get userAgent() {
172
+ if (this.#userAgent === undefined) {
173
+ try {
174
+ const userAgent = globalThis.navigator?.userAgent;
175
+ if (userAgent) {
176
+ const { browser } = Bowser.parse(userAgent);
177
+ this.#userAgent = {
178
+ 'Chrome': 'chrome',
179
+ 'Chromium': 'chrome',
180
+ 'Firefox': 'firefox',
181
+ 'Microsoft Edge': 'edge',
182
+ 'Opera': 'opera',
183
+ 'Safari': 'safari',
184
+ 'Yandex Browser': 'yandex',
185
+ }[browser?.name];
186
+ }
187
+ } catch (e) {
188
+ logger.warn('Failed to determine userAgent', e);
189
+ }
190
+ this.#userAgent ||= '';
191
+ }
192
+ return this.#userAgent;
193
+ }
194
+
169
195
  /** Global module initialisation.
170
196
  */
171
197
  async init() {
@@ -210,8 +236,6 @@ export default class RequestReporter {
210
236
 
211
237
  await this.pageStore.init();
212
238
 
213
- this.userAgent = (await this.getBrowserInfo()).name;
214
-
215
239
  this.pageLogger = new PageLogger(this.config.placeHolder);
216
240
  this.cookieContext = new CookieContext(this.config, this.qs_whitelist);
217
241
  await this.cookieContext.init();
@@ -313,7 +313,7 @@ export default class SearchExtractor {
313
313
  const body = {
314
314
  action,
315
315
  payload,
316
- ver: 3, // Note: no need to keep this number in sync among messages
316
+ ver: 4, // Note: no need to keep this number in sync among messages
317
317
  'anti-duplicates': Math.floor(random() * 10000000),
318
318
  };
319
319
  messages.push({ body, deduplicateBy });
@@ -18,18 +18,15 @@ describe('#AliveMessageGenerator', function () {
18
18
  const anotherHour = '2024030804';
19
19
 
20
20
  const storageKey = 'some-storage-key';
21
- let browserInfoProvider;
22
21
  let navigatorApi;
23
22
  let quorumChecker;
24
23
  let storage;
25
24
  let uut;
26
25
 
27
- let _browserInfo;
28
26
  let _shouldPassQuorum;
29
27
 
30
28
  function newAliveMessageGenerator() {
31
29
  return new AliveMessageGenerator({
32
- browserInfoProvider,
33
30
  navigatorApi,
34
31
  quorumChecker,
35
32
  storage,
@@ -37,8 +34,8 @@ describe('#AliveMessageGenerator', function () {
37
34
  });
38
35
  }
39
36
 
40
- // Helper that simulate an event like a restart of the service worker/background script:
41
- // it keeps the storage but purges everything that was in memory.
37
+ // Helper that simulates an event like a restart of the service worker/background script:
38
+ // it keeps the storage, but purges everything that was in memory.
42
39
  async function simulateRestart() {
43
40
  uut = newAliveMessageGenerator();
44
41
  }
@@ -52,16 +49,11 @@ describe('#AliveMessageGenerator', function () {
52
49
  }
53
50
 
54
51
  beforeEach(() => {
55
- _browserInfo = {
56
- browser: 'Firefox',
57
- version: '122',
58
- os: 'Linux',
59
- language: 'en-US',
60
- };
61
52
  navigatorApi = {
53
+ userAgent:
54
+ 'Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0',
62
55
  language: 'en-US',
63
56
  };
64
- browserInfoProvider = async () => _browserInfo;
65
57
 
66
58
  quorumChecker = {
67
59
  _incCalls: 0,
@@ -154,19 +146,17 @@ describe('#AliveMessageGenerator', function () {
154
146
  runGenericTests();
155
147
 
156
148
  it('should share the config', async function () {
157
- _browserInfo = {
158
- browser: 'Firefox',
159
- version: '122.1',
160
- os: 'Linux',
161
- language: 'en-US',
162
- };
149
+ navigatorApi.userAgent =
150
+ 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36';
163
151
  navigatorApi.language = 'de-DE';
164
152
 
165
153
  const message = await uut.generateMessage('de', '2024010203');
166
154
  expect(message).to.eql({
167
- browser: 'Firefox',
168
- version: '122', // only major version
155
+ browser: 'Chrome',
156
+ version: '138', // only major version
169
157
  os: 'Linux',
158
+ platform: 'desktop',
159
+ engine: 'Blink',
170
160
  language: 'de-DE', // from window.navigator
171
161
  ctry: 'de',
172
162
  t: '2024010203',
@@ -184,6 +174,8 @@ describe('#AliveMessageGenerator', function () {
184
174
  browser: '',
185
175
  version: '',
186
176
  os: '',
177
+ platform: '',
178
+ engine: '',
187
179
  language: '',
188
180
  ctry: '--',
189
181
  t: '2024010203',
@@ -45,7 +45,6 @@ describe('#Reporting', function () {
45
45
  storage,
46
46
  communication,
47
47
  connectDatabase,
48
- browserInfoProvider: async () => ({ browser: 'test' }),
49
48
  });
50
49
  });
51
50
 
@@ -103,7 +103,6 @@ describe('request/index', function () {
103
103
  countryProvider: {},
104
104
  trustedClock,
105
105
  communication: {},
106
- getBrowserInfo: () => ({ name: 'xx' }),
107
106
  },
108
107
  );
109
108
  await attrack.init();
@@ -106,7 +106,6 @@ describe('RequestReporter', function () {
106
106
  communicationEmitter.emit('send', msg);
107
107
  },
108
108
  trustedClock,
109
- getBrowserInfo: () => ({ name: 'xx' }),
110
109
  countryProvider: { getSafeCountryCode: () => 'en' },
111
110
  });
112
111
  await reporter.init();