@whotracksme/reporting 5.1.22 → 5.1.24
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 +28 -0
- package/package.json +1 -1
- package/reporting/example/setup.js +1 -1
- package/reporting/src/alive-message-generator.js +10 -3
- package/reporting/src/pages.js +25 -14
- package/reporting/src/patterns.js +12 -1
- package/reporting/test/alive-message-generator.spec.js +10 -3
- package/reporting/test/pages.spec.js +79 -0
- package/reporting/test/patterns.spec.js +90 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# v5.1.24 (Fri Sep 13 2024)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- When parsing JSON, we should no attempt to extract implicitly [#96](https://github.com/whotracksme/webextension-packages/pull/96) ([@philipp-classen](https://github.com/philipp-classen))
|
|
6
|
+
- Test fixed: lifted the unintended dependency on the LANG environment [#95](https://github.com/whotracksme/webextension-packages/pull/95) ([@philipp-classen](https://github.com/philipp-classen))
|
|
7
|
+
|
|
8
|
+
#### Authors: 1
|
|
9
|
+
|
|
10
|
+
- Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# v5.1.23 (Wed Sep 11 2024)
|
|
15
|
+
|
|
16
|
+
#### 🐛 Bug Fix
|
|
17
|
+
|
|
18
|
+
- New builtin: "trim" [#92](https://github.com/whotracksme/webextension-packages/pull/92) ([@philipp-classen](https://github.com/philipp-classen))
|
|
19
|
+
- Fix chrome example [#93](https://github.com/whotracksme/webextension-packages/pull/93) ([@chrmod](https://github.com/chrmod))
|
|
20
|
+
- Fixes a problem where the in-memory session could not be restored: [#90](https://github.com/whotracksme/webextension-packages/pull/90) ([@philipp-classen](https://github.com/philipp-classen))
|
|
21
|
+
|
|
22
|
+
#### Authors: 2
|
|
23
|
+
|
|
24
|
+
- Krzysztof Modras ([@chrmod](https://github.com/chrmod))
|
|
25
|
+
- Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
1
29
|
# v5.1.22 (Wed Sep 04 2024)
|
|
2
30
|
|
|
3
31
|
#### 🐛 Bug Fix
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
globalThis.chrome = browser || chrome;
|
|
1
|
+
globalThis.chrome = globalThis.browser || globalThis.chrome;
|
|
@@ -24,11 +24,18 @@ import { requireParam, requireString, lazyInitAsync } from './utils';
|
|
|
24
24
|
* breaks something on Windows.
|
|
25
25
|
*/
|
|
26
26
|
export default class AliveMessageGenerator {
|
|
27
|
-
constructor({
|
|
27
|
+
constructor({
|
|
28
|
+
browserInfoProvider,
|
|
29
|
+
navigatorApi,
|
|
30
|
+
quorumChecker,
|
|
31
|
+
storage,
|
|
32
|
+
storageKey,
|
|
33
|
+
}) {
|
|
28
34
|
requireParam(browserInfoProvider);
|
|
29
35
|
this.quorumChecker = requireParam(quorumChecker);
|
|
30
36
|
this.storage = requireParam(storage);
|
|
31
37
|
this.storageKey = requireString(storageKey);
|
|
38
|
+
this.navigatorApi = navigatorApi || globalThis.navigator;
|
|
32
39
|
|
|
33
40
|
this.staticConfigProvider = lazyInitAsync(async () =>
|
|
34
41
|
this._generateBaseConfig(await browserInfoProvider()),
|
|
@@ -81,10 +88,10 @@ export default class AliveMessageGenerator {
|
|
|
81
88
|
|
|
82
89
|
let language;
|
|
83
90
|
try {
|
|
84
|
-
language =
|
|
91
|
+
language = this.navigatorApi.language;
|
|
85
92
|
} catch (e) {
|
|
86
93
|
logger.warn(
|
|
87
|
-
'
|
|
94
|
+
'"navigator" API unavailable (should only happen when run in NodeJs 20 or lower)',
|
|
88
95
|
);
|
|
89
96
|
}
|
|
90
97
|
language = language || '';
|
package/reporting/src/pages.js
CHANGED
|
@@ -53,7 +53,11 @@ export const WINDOW_ID_CURRENT = -2;
|
|
|
53
53
|
*
|
|
54
54
|
* For more details on lazy variables, see Pages#_setLazyVar.
|
|
55
55
|
*
|
|
56
|
-
*
|
|
56
|
+
* Notes:
|
|
57
|
+
* - the implementation assumes that objects are free of cycles
|
|
58
|
+
* - as part of the serialization, explicit mappings to "undefined" will be omitted
|
|
59
|
+
* (this is consistent with JSON.stringify; if you need keys with optional values,
|
|
60
|
+
* you can map to "null" instead)
|
|
57
61
|
*
|
|
58
62
|
* (exported for tests only)
|
|
59
63
|
*/
|
|
@@ -70,14 +74,21 @@ export function stripLazyVars(obj) {
|
|
|
70
74
|
if (Object(obj) !== obj || obj.constructor === Date) {
|
|
71
75
|
return obj;
|
|
72
76
|
}
|
|
77
|
+
|
|
73
78
|
const result = {};
|
|
79
|
+
const set = (key, val) => {
|
|
80
|
+
const v = stripLazyVars(val);
|
|
81
|
+
if (v !== undefined) {
|
|
82
|
+
result[key] = v;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
74
85
|
for (const [key, val] of Object.entries(obj)) {
|
|
75
86
|
if (val?._pending) {
|
|
76
87
|
if (val.result && val.result !== CANCEL_LAZY_VAR) {
|
|
77
|
-
|
|
88
|
+
set(key, val.result);
|
|
78
89
|
}
|
|
79
90
|
} else {
|
|
80
|
-
|
|
91
|
+
set(key, val);
|
|
81
92
|
}
|
|
82
93
|
}
|
|
83
94
|
return result;
|
|
@@ -527,7 +538,13 @@ export default class Pages {
|
|
|
527
538
|
_deserializeTabContent(tabContent) {
|
|
528
539
|
const result = {};
|
|
529
540
|
Object.entries(tabContent).forEach(([key, val]) => {
|
|
530
|
-
if (val
|
|
541
|
+
if (val === undefined) {
|
|
542
|
+
logger.warn(
|
|
543
|
+
'"undefined" mappings should not have been serialized:',
|
|
544
|
+
key,
|
|
545
|
+
'(drop and continue...)',
|
|
546
|
+
);
|
|
547
|
+
} else if (val?._pending) {
|
|
531
548
|
logger.warn(
|
|
532
549
|
'Lazy variable should not have been serialized (since they are promises):',
|
|
533
550
|
key,
|
|
@@ -552,7 +569,6 @@ export default class Pages {
|
|
|
552
569
|
|
|
553
570
|
_restoreTabs(openTabs) {
|
|
554
571
|
if (openTabs) {
|
|
555
|
-
// TODO: maybe merge together?
|
|
556
572
|
const deserializedTabs = Object.entries(openTabs).map(
|
|
557
573
|
([tabId, tabContent]) => [
|
|
558
574
|
tabId,
|
|
@@ -1582,11 +1598,6 @@ export default class Pages {
|
|
|
1582
1598
|
}
|
|
1583
1599
|
}
|
|
1584
1600
|
|
|
1585
|
-
// TODO:
|
|
1586
|
-
// Maybe extract this functionality.
|
|
1587
|
-
// Caching old values could also help. Not primarily for performance
|
|
1588
|
-
// (though it could make help for that as well), but to put "unknown"
|
|
1589
|
-
// into the right visibility category if possible.
|
|
1590
1601
|
_checkPageVisibility(url) {
|
|
1591
1602
|
if (!isRealPage(url)) {
|
|
1592
1603
|
return {
|
|
@@ -1626,19 +1637,19 @@ export default class Pages {
|
|
|
1626
1637
|
// This provides a low-level mechanism to safely deal with values
|
|
1627
1638
|
// that need asynchronous initialization.
|
|
1628
1639
|
// Other classes should not be aware of it, since they should only
|
|
1629
|
-
// operate on snapshots (which don't export
|
|
1640
|
+
// operate on snapshots (which don't export pending async operations).
|
|
1630
1641
|
// Neither should it be needed to understand it while accessing values
|
|
1631
|
-
// during debugging; once the operations are finished,
|
|
1642
|
+
// during debugging; once the operations are finished, then only
|
|
1632
1643
|
// the actual results will be preserved.
|
|
1633
1644
|
//
|
|
1634
1645
|
// Notes:
|
|
1635
|
-
// - "asyncInit" is not expected
|
|
1646
|
+
// - "asyncInit" is not expected to throw. If it may fail, define an
|
|
1636
1647
|
// explicit error state (e.g. CANCEL_LAZY_VAR) and resolve with that.
|
|
1637
1648
|
// - To safely read the value, you can use the "_tryUnwrapLazyVar" helper.
|
|
1638
1649
|
// Note that "CANCEL_LAZY_VAR" will be interpreted as error cases
|
|
1639
1650
|
// and results in missing values (i.e. the callback does not trigger).
|
|
1640
1651
|
// - There is limited support for lazy vars to depend on each other
|
|
1641
|
-
// (see _awaitLazyVar)
|
|
1652
|
+
// (see _awaitLazyVar); but be careful when using it since you get
|
|
1642
1653
|
// only weak guarantees (e.g. the lazy var might not be present yet).
|
|
1643
1654
|
// If you have important dependencies, consider merging them together
|
|
1644
1655
|
// in one big lazy var (within the async init, dependencies are
|
|
@@ -288,6 +288,9 @@ const TRANSFORMS = new Map(
|
|
|
288
288
|
try {
|
|
289
289
|
let obj = JSON.parse(text);
|
|
290
290
|
for (const field of path.split('.')) {
|
|
291
|
+
if (!Object.hasOwn(obj, field)) {
|
|
292
|
+
return '';
|
|
293
|
+
}
|
|
291
294
|
obj = obj[field];
|
|
292
295
|
}
|
|
293
296
|
if (typeof obj === 'string') {
|
|
@@ -305,6 +308,14 @@ const TRANSFORMS = new Map(
|
|
|
305
308
|
return '';
|
|
306
309
|
}
|
|
307
310
|
},
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @since: 3
|
|
314
|
+
*/
|
|
315
|
+
trim: (text) => {
|
|
316
|
+
requireString(text);
|
|
317
|
+
return text.trim();
|
|
318
|
+
},
|
|
308
319
|
}),
|
|
309
320
|
);
|
|
310
321
|
|
|
@@ -325,7 +336,7 @@ export function lookupBuiltinTransform(name) {
|
|
|
325
336
|
* to disable clients that do not meet the minimum requirements of the
|
|
326
337
|
* current patterns.
|
|
327
338
|
*/
|
|
328
|
-
const PATTERN_DSL_VERSION =
|
|
339
|
+
const PATTERN_DSL_VERSION = 3;
|
|
329
340
|
|
|
330
341
|
/**
|
|
331
342
|
* "Magic" empty rule set, which exists only if patterns were loaded, but
|
|
@@ -19,6 +19,7 @@ describe('#AliveMessageGenerator', function () {
|
|
|
19
19
|
|
|
20
20
|
const storageKey = 'some-storage-key';
|
|
21
21
|
let browserInfoProvider;
|
|
22
|
+
let navigatorApi;
|
|
22
23
|
let quorumChecker;
|
|
23
24
|
let storage;
|
|
24
25
|
let uut;
|
|
@@ -29,6 +30,7 @@ describe('#AliveMessageGenerator', function () {
|
|
|
29
30
|
function newAliveMessageGenerator() {
|
|
30
31
|
return new AliveMessageGenerator({
|
|
31
32
|
browserInfoProvider,
|
|
33
|
+
navigatorApi,
|
|
32
34
|
quorumChecker,
|
|
33
35
|
storage,
|
|
34
36
|
storageKey,
|
|
@@ -56,6 +58,9 @@ describe('#AliveMessageGenerator', function () {
|
|
|
56
58
|
os: 'Linux',
|
|
57
59
|
language: 'en-US',
|
|
58
60
|
};
|
|
61
|
+
navigatorApi = {
|
|
62
|
+
language: 'en-US',
|
|
63
|
+
};
|
|
59
64
|
browserInfoProvider = async () => _browserInfo;
|
|
60
65
|
|
|
61
66
|
quorumChecker = {
|
|
@@ -155,12 +160,14 @@ describe('#AliveMessageGenerator', function () {
|
|
|
155
160
|
os: 'Linux',
|
|
156
161
|
language: 'en-US',
|
|
157
162
|
};
|
|
163
|
+
navigatorApi.language = 'de-DE';
|
|
164
|
+
|
|
158
165
|
const message = await uut.generateMessage('de', '2024010203');
|
|
159
|
-
expect(message).to.
|
|
166
|
+
expect(message).to.eql({
|
|
160
167
|
browser: 'Firefox',
|
|
161
168
|
version: '122', // only major version
|
|
162
169
|
os: 'Linux',
|
|
163
|
-
language: '
|
|
170
|
+
language: 'de-DE', // from window.navigator
|
|
164
171
|
ctry: 'de',
|
|
165
172
|
t: '2024010203',
|
|
166
173
|
});
|
|
@@ -173,7 +180,7 @@ describe('#AliveMessageGenerator', function () {
|
|
|
173
180
|
|
|
174
181
|
it('should not share the config', async function () {
|
|
175
182
|
const message = await uut.generateMessage('de', '2024010203');
|
|
176
|
-
expect(message).to.
|
|
183
|
+
expect(message).to.eql({
|
|
177
184
|
browser: '',
|
|
178
185
|
version: '',
|
|
179
186
|
os: '',
|
|
@@ -569,6 +569,10 @@ describe('#stripLazyVars', function () {
|
|
|
569
569
|
{ foo: 1 },
|
|
570
570
|
{ foo: 1, bar: { baz: 2 } },
|
|
571
571
|
{ foo: NaN },
|
|
572
|
+
{ foo: null },
|
|
573
|
+
[null],
|
|
574
|
+
[NaN],
|
|
575
|
+
[undefined],
|
|
572
576
|
])) {
|
|
573
577
|
it(`- example ${pos}: ${JSON.stringify(value)}`, async function () {
|
|
574
578
|
expect(stripLazyVars(value)).to.eql(value);
|
|
@@ -576,6 +580,40 @@ describe('#stripLazyVars', function () {
|
|
|
576
580
|
}
|
|
577
581
|
});
|
|
578
582
|
|
|
583
|
+
describe('should omit keys that map to "undefined"', async function () {
|
|
584
|
+
for (const [pos, { before, after }] of Object.entries([
|
|
585
|
+
{
|
|
586
|
+
before: {
|
|
587
|
+
foo: undefined,
|
|
588
|
+
},
|
|
589
|
+
after: {},
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
before: {
|
|
593
|
+
foo: {
|
|
594
|
+
bar: undefined,
|
|
595
|
+
},
|
|
596
|
+
},
|
|
597
|
+
after: {
|
|
598
|
+
foo: {},
|
|
599
|
+
},
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
before: {
|
|
603
|
+
foo: 42,
|
|
604
|
+
bar: undefined,
|
|
605
|
+
},
|
|
606
|
+
after: {
|
|
607
|
+
foo: 42,
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
])) {
|
|
611
|
+
it(`- example ${pos}: ${JSON.stringify(before)}`, async function () {
|
|
612
|
+
expect(stripLazyVars(before)).to.eql(after);
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
|
|
579
617
|
describe('should should remove pending lazy vars', async function () {
|
|
580
618
|
for (const [pos, { before, after }] of Object.entries([
|
|
581
619
|
{
|
|
@@ -627,6 +665,47 @@ describe('#stripLazyVars', function () {
|
|
|
627
665
|
foo: {},
|
|
628
666
|
},
|
|
629
667
|
},
|
|
668
|
+
{
|
|
669
|
+
before: {
|
|
670
|
+
pageStructure: CANCEL_LAZY_VAR,
|
|
671
|
+
},
|
|
672
|
+
after: {},
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
before: {
|
|
676
|
+
status: 'complete',
|
|
677
|
+
title:
|
|
678
|
+
'A comparison of the Gauss–Newton and quasi-Newton methods in resistivity imaging inversion - ScienceDirect',
|
|
679
|
+
url: 'https://www.sciencedirect.com/science/article/abs/pii/S0926985101001069',
|
|
680
|
+
windowId: 1500,
|
|
681
|
+
lastUpdatedAt: 1724851933284,
|
|
682
|
+
pageId: 1354398384,
|
|
683
|
+
visibility: 'unknown',
|
|
684
|
+
pageStructure: CANCEL_LAZY_VAR,
|
|
685
|
+
language: 'en',
|
|
686
|
+
},
|
|
687
|
+
after: {
|
|
688
|
+
status: 'complete',
|
|
689
|
+
title:
|
|
690
|
+
'A comparison of the Gauss–Newton and quasi-Newton methods in resistivity imaging inversion - ScienceDirect',
|
|
691
|
+
url: 'https://www.sciencedirect.com/science/article/abs/pii/S0926985101001069',
|
|
692
|
+
windowId: 1500,
|
|
693
|
+
lastUpdatedAt: 1724851933284,
|
|
694
|
+
pageId: 1354398384,
|
|
695
|
+
visibility: 'unknown',
|
|
696
|
+
language: 'en',
|
|
697
|
+
},
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
before: {
|
|
701
|
+
foo: {
|
|
702
|
+
pageStructure: CANCEL_LAZY_VAR,
|
|
703
|
+
},
|
|
704
|
+
},
|
|
705
|
+
after: {
|
|
706
|
+
foo: {},
|
|
707
|
+
},
|
|
708
|
+
},
|
|
630
709
|
])) {
|
|
631
710
|
it(`- example ${pos}: ${JSON.stringify(before)}`, async function () {
|
|
632
711
|
expect(stripLazyVars(before)).to.eql(after);
|
|
@@ -801,6 +801,54 @@ describe('Test builtin primitives', function () {
|
|
|
801
801
|
});
|
|
802
802
|
});
|
|
803
803
|
|
|
804
|
+
describe('handling of native properties', function () {
|
|
805
|
+
// The observation is that some property names are implicitly provided:
|
|
806
|
+
//
|
|
807
|
+
// x = '';
|
|
808
|
+
// !!x['foo'] --> false
|
|
809
|
+
// !!x['bar'] --> false
|
|
810
|
+
// !!x['toString'] --> true
|
|
811
|
+
// !!x['__proto__'] --> true
|
|
812
|
+
[
|
|
813
|
+
// this list is incomplete, but should cover all primitive
|
|
814
|
+
'__proto__',
|
|
815
|
+
'constructor',
|
|
816
|
+
'hasOwnProperty',
|
|
817
|
+
'isPrototypeOf',
|
|
818
|
+
'propertyIsEnumerable',
|
|
819
|
+
'toLocaleString',
|
|
820
|
+
'toString',
|
|
821
|
+
'valueOf',
|
|
822
|
+
'toExponential',
|
|
823
|
+
'toFixed',
|
|
824
|
+
'toPrecision',
|
|
825
|
+
].forEach((field) => {
|
|
826
|
+
it(`should ignore the inherited ${field} field`, function () {
|
|
827
|
+
expect(uut('"a"', field, true)).to.eql('');
|
|
828
|
+
expect(uut('["a"]', field, true)).to.eql('');
|
|
829
|
+
expect(uut('{"a":"b"}', field, true)).to.eql('');
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// This is mostly documenting the status quo, which results from
|
|
834
|
+
// Object.has('foo', 'length') being true.
|
|
835
|
+
//
|
|
836
|
+
// Since this is so obscure, we should not built behavior on top of it.
|
|
837
|
+
// However, it is not opening up attacks, so there is also not much
|
|
838
|
+
// benefit in having extra logic to handle this situation.
|
|
839
|
+
it('should gracefully handle the implicit "length" field', function () {
|
|
840
|
+
expect(uut('"foo"', 'length')).to.eql('3');
|
|
841
|
+
expect(uut('"foo"', 'length', true)).to.eql('3');
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
it('should support an explicit "length" field', function () {
|
|
845
|
+
expect(uut('{"height": 17, "length": 42}', 'length')).to.eql('42');
|
|
846
|
+
expect(uut('{"height": 17, "length": 42}', 'length', true)).to.eql(
|
|
847
|
+
'42',
|
|
848
|
+
);
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
|
|
804
852
|
describe('robustness on untrusted data', function () {
|
|
805
853
|
it('should fail if input is not [string, string, [bool]]', function () {
|
|
806
854
|
expect(() => uut()).to.throw();
|
|
@@ -825,4 +873,46 @@ describe('Test builtin primitives', function () {
|
|
|
825
873
|
});
|
|
826
874
|
});
|
|
827
875
|
});
|
|
876
|
+
|
|
877
|
+
describe('#trim', function () {
|
|
878
|
+
let trim;
|
|
879
|
+
|
|
880
|
+
beforeEach(function () {
|
|
881
|
+
trim = lookupBuiltinTransform('trim');
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
describe('core functionality', function () {
|
|
885
|
+
it('"foo" -> "foo"', function () {
|
|
886
|
+
expect(trim('foo')).to.eql('foo');
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
it('"foo bar" -> "foo bar"', function () {
|
|
890
|
+
expect(trim('foo bar')).to.eql('foo bar');
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
it('" foo " -> "foo"', function () {
|
|
894
|
+
expect(trim(' foo ', '_', 0)).to.eql('foo');
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
it('"" -> ""', function () {
|
|
898
|
+
expect(trim('')).to.eql('');
|
|
899
|
+
});
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
describe('robustness on untrusted data', function () {
|
|
903
|
+
it('should fail if input is not [string] (more parameters are ignored)', function () {
|
|
904
|
+
expect(() => trim()).to.throw();
|
|
905
|
+
expect(() => trim({ wrong: 'types' })).to.throw();
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
it('should work on arbitrary strings and behave like String.trim', function () {
|
|
909
|
+
fc.assert(
|
|
910
|
+
fc.property(fc.fullUnicodeString(), (untrustedText) => {
|
|
911
|
+
const result = trim(untrustedText);
|
|
912
|
+
expect(result).to.be.a('string').and.to.eql(untrustedText.trim());
|
|
913
|
+
}),
|
|
914
|
+
);
|
|
915
|
+
});
|
|
916
|
+
});
|
|
917
|
+
});
|
|
828
918
|
});
|