@whotracksme/reporting 5.1.21 → 5.1.23

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,30 @@
1
+ # v5.1.23 (Wed Sep 11 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - New builtin: "trim" [#92](https://github.com/whotracksme/webextension-packages/pull/92) ([@philipp-classen](https://github.com/philipp-classen))
6
+ - Fix chrome example [#93](https://github.com/whotracksme/webextension-packages/pull/93) ([@chrmod](https://github.com/chrmod))
7
+ - 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))
8
+
9
+ #### Authors: 2
10
+
11
+ - Krzysztof Modras ([@chrmod](https://github.com/chrmod))
12
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
13
+
14
+ ---
15
+
16
+ # v5.1.22 (Wed Sep 04 2024)
17
+
18
+ #### 🐛 Bug Fix
19
+
20
+ - Update web-ext [#91](https://github.com/whotracksme/webextension-packages/pull/91) ([@chrmod](https://github.com/chrmod))
21
+
22
+ #### Authors: 1
23
+
24
+ - Krzysztof Modras ([@chrmod](https://github.com/chrmod))
25
+
26
+ ---
27
+
1
28
  # v5.1.21 (Mon Aug 26 2024)
2
29
 
3
30
  #### 🐛 Bug Fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "5.1.21",
3
+ "version": "5.1.23",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {
@@ -1 +1 @@
1
- globalThis.chrome = browser || chrome;
1
+ globalThis.chrome = globalThis.browser || globalThis.chrome;
@@ -32,7 +32,7 @@
32
32
  "sinon": "^15.2.0",
33
33
  "sinon-chai": "^3.7.0",
34
34
  "sinon-chrome": "^3.0.1",
35
- "web-ext": "^6.8.0"
35
+ "web-ext": "^8.2.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "@cliqz/url-parser": "^1.1.5",
@@ -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
- * Note: the implementation assumes that objects are free of cycles
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
- result[key] = stripLazyVars(val.result);
88
+ set(key, val.result);
78
89
  }
79
90
  } else {
80
- result[key] = stripLazyVars(val);
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._pending) {
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 myChecks operations).
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, they only
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 not throw. If it may fail, define an
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), but be careful when using it since you get
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
@@ -305,6 +305,14 @@ const TRANSFORMS = new Map(
305
305
  return '';
306
306
  }
307
307
  },
308
+
309
+ /**
310
+ * @since: 3
311
+ */
312
+ trim: (text) => {
313
+ requireString(text);
314
+ return text.trim();
315
+ },
308
316
  }),
309
317
  );
310
318
 
@@ -325,7 +333,7 @@ export function lookupBuiltinTransform(name) {
325
333
  * to disable clients that do not meet the minimum requirements of the
326
334
  * current patterns.
327
335
  */
328
- const PATTERN_DSL_VERSION = 2;
336
+ const PATTERN_DSL_VERSION = 3;
329
337
 
330
338
  /**
331
339
  * "Magic" empty rule set, which exists only if patterns were loaded, but
@@ -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);
@@ -825,4 +825,46 @@ describe('Test builtin primitives', function () {
825
825
  });
826
826
  });
827
827
  });
828
+
829
+ describe('#trim', function () {
830
+ let trim;
831
+
832
+ beforeEach(function () {
833
+ trim = lookupBuiltinTransform('trim');
834
+ });
835
+
836
+ describe('core functionality', function () {
837
+ it('"foo" -> "foo"', function () {
838
+ expect(trim('foo')).to.eql('foo');
839
+ });
840
+
841
+ it('"foo bar" -> "foo bar"', function () {
842
+ expect(trim('foo bar')).to.eql('foo bar');
843
+ });
844
+
845
+ it('" foo " -> "foo"', function () {
846
+ expect(trim(' foo ', '_', 0)).to.eql('foo');
847
+ });
848
+
849
+ it('"" -> ""', function () {
850
+ expect(trim('')).to.eql('');
851
+ });
852
+ });
853
+
854
+ describe('robustness on untrusted data', function () {
855
+ it('should fail if input is not [string] (more parameters are ignored)', function () {
856
+ expect(() => trim()).to.throw();
857
+ expect(() => trim({ wrong: 'types' })).to.throw();
858
+ });
859
+
860
+ it('should work on arbitrary strings and behave like String.trim', function () {
861
+ fc.assert(
862
+ fc.property(fc.fullUnicodeString(), (untrustedText) => {
863
+ const result = trim(untrustedText);
864
+ expect(result).to.be.a('string').and.to.eql(untrustedText.trim());
865
+ }),
866
+ );
867
+ });
868
+ });
869
+ });
828
870
  });