@whotracksme/reporting 5.1.30 → 5.1.31

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.
@@ -300,11 +300,7 @@ export default class RequestReporter {
300
300
  }
301
301
 
302
302
  onBeforeRequest = (details) => {
303
- const state = WebRequestContext.fromDetails(
304
- details,
305
- this.pageStore,
306
- 'onBeforeRequest',
307
- );
303
+ const state = WebRequestContext.fromDetails(details, this.pageStore);
308
304
  const response = new BlockingResponse(details, 'onBeforeRequest');
309
305
  // checkState
310
306
  if (checkValidContext(state) === false) {
@@ -391,11 +387,7 @@ export default class RequestReporter {
391
387
  };
392
388
 
393
389
  onBeforeSendHeaders = (details) => {
394
- const state = WebRequestContext.fromDetails(
395
- details,
396
- this.pageStore,
397
- 'onBeforeSendHeaders',
398
- );
390
+ const state = WebRequestContext.fromDetails(details, this.pageStore);
399
391
  const response = new BlockingResponse(details, 'onBeforeSendHeaders');
400
392
  // checkState
401
393
  if (checkValidContext(state) === false) {
@@ -489,11 +481,7 @@ export default class RequestReporter {
489
481
  };
490
482
 
491
483
  onHeadersReceived = (details) => {
492
- const state = WebRequestContext.fromDetails(
493
- details,
494
- this.pageStore,
495
- 'onHeadersReceived',
496
- );
484
+ const state = WebRequestContext.fromDetails(details, this.pageStore);
497
485
  const response = new BlockingResponse(details, 'onHeadersReceived');
498
486
  // checkState
499
487
  if (checkValidContext(state) === false) {
@@ -560,11 +548,7 @@ export default class RequestReporter {
560
548
  };
561
549
 
562
550
  onCompleted = (details) => {
563
- const state = WebRequestContext.fromDetails(
564
- details,
565
- this.pageStore,
566
- 'onCompleted',
567
- );
551
+ const state = WebRequestContext.fromDetails(details, this.pageStore);
568
552
  // checkState
569
553
  if (checkValidContext(state) === false) {
570
554
  return false;
@@ -586,11 +570,7 @@ export default class RequestReporter {
586
570
  };
587
571
 
588
572
  onErrorOccurred = (details) => {
589
- const state = WebRequestContext.fromDetails(
590
- details,
591
- this.pageStore,
592
- 'onErrorOccurred',
593
- );
573
+ const state = WebRequestContext.fromDetails(details, this.pageStore);
594
574
  // checkState
595
575
  if (checkValidContext(state) === false) {
596
576
  return false;
@@ -263,32 +263,6 @@ export default class PageStore {
263
263
  this.#pages.set(tabId, page);
264
264
  };
265
265
 
266
- onMainFrame = (details, event) => {
267
- const { tabId, url } = details;
268
- // main frame from tabId -1 is from service worker and should not be saved
269
- if (tabId === -1) {
270
- return;
271
- }
272
-
273
- // Update last request id from the tab
274
- const page =
275
- this.#pages.get(tabId) ||
276
- createPageFromTab({ url, incognito: false, id: tabId });
277
-
278
- if (event === 'onBeforeRequest') {
279
- page.frames = {};
280
- }
281
-
282
- // Update context of tab with `url` and main frame information
283
- page.url = url;
284
- page.frames[0] = {
285
- parentFrameId: -1,
286
- url,
287
- };
288
-
289
- this.#pages.set(tabId, page);
290
- };
291
-
292
266
  onSubFrame = (details) => {
293
267
  const { tabId, frameId, parentFrameId, url } = details;
294
268
  const page = this.#pages.get(tabId);
@@ -117,7 +117,7 @@ export class WebRequestContext {
117
117
  * well as provide convenient helpers for parsed URLs, etc. It will also not
118
118
  * return a wrapper for background requests.
119
119
  */
120
- static fromDetails(details, pageStore, event) {
120
+ static fromDetails(details, pageStore) {
121
121
  const context = details;
122
122
 
123
123
  // Check if we have a URL
@@ -125,11 +125,6 @@ export class WebRequestContext {
125
125
  return null;
126
126
  }
127
127
 
128
- // Main frames book keeping
129
- if (context.type === 'main_frame') {
130
- pageStore.onMainFrame(context, event);
131
- }
132
-
133
128
  // Sub frames book keeping
134
129
  if (context.type === 'sub_frame') {
135
130
  pageStore.onSubFrame(context);
@@ -57,7 +57,22 @@ export function recordSnapshot(name, messages) {
57
57
  getSnapshotScenarioPath(name),
58
58
  'snapshot.json',
59
59
  );
60
- fs.writeFileSync(snapshotPath, JSON.stringify(messages, null, 2));
60
+ function sortObjectKeys(obj) {
61
+ if (Array.isArray(obj)) {
62
+ return obj.map(sortObjectKeys);
63
+ } else if (obj !== null && typeof obj === 'object') {
64
+ const sortedObj = {};
65
+ const keys = Object.keys(obj).sort(); // Sort keys alphabetically
66
+ for (const key of keys) {
67
+ sortedObj[key] = sortObjectKeys(obj[key]); // Recursively sort nested objects
68
+ }
69
+ return sortedObj;
70
+ } else {
71
+ return obj; // Return the value if obj is not an object or array
72
+ }
73
+ }
74
+ const sortedMessages = sortObjectKeys(messages);
75
+ fs.writeFileSync(snapshotPath, JSON.stringify(sortedMessages, null, 2));
61
76
  }
62
77
 
63
78
  export function readSnapshot(name) {
@@ -264,18 +264,10 @@ describe('request/index', function () {
264
264
  });
265
265
 
266
266
  it('removes all occurances of uid in the request', function () {
267
- const mainDoc = attrack.onBeforeRequest({
268
- tabId: 34,
269
- frameId: 0,
270
- parentFrameId: -1,
271
- method: 'GET',
272
- type: 'main_frame',
267
+ chrome.tabs.onCreated.dispatch({
268
+ id: 34,
273
269
  url: 'http://cliqztest.com/',
274
- requestHeaders: mockRequestHeaders,
275
270
  });
276
- chai.expect(mainDoc).to.not.have.property('cancel');
277
- chai.expect(mainDoc).to.not.have.property('redirectUrl');
278
- chai.expect(mainDoc).to.not.have.property('requestHeaders');
279
271
  const response = attrack.onBeforeRequest({
280
272
  tabId: 34,
281
273
  frameId: 0,
@@ -295,20 +287,10 @@ describe('request/index', function () {
295
287
  });
296
288
 
297
289
  it('removes also after subsequent redirect with same uid', function () {
298
- const mainDoc = attrack.onBeforeRequest({
299
- tabId: 34,
300
- frameId: 0,
301
- parentFrameId: -1,
302
- method: 'GET',
303
- type: 'main_frame',
290
+ chrome.tabs.onCreated.dispatch({
291
+ id: 34,
304
292
  url: 'http://cliqztest.com/',
305
- requestHeaders: mockRequestHeaders,
306
- originUrl: '',
307
- tabUrl: '',
308
293
  });
309
- chai.expect(mainDoc).to.not.have.property('cancel');
310
- chai.expect(mainDoc).to.not.have.property('redirectUrl');
311
- chai.expect(mainDoc).to.not.have.property('requestHeaders');
312
294
  let response = attrack.onBeforeRequest({
313
295
  tabId: 34,
314
296
  frameId: 0,