@whotracksme/reporting 5.1.30 → 5.1.32

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.
@@ -30,7 +30,6 @@ import random from '../random.js';
30
30
  import BlockRules from './steps/block-rules.js';
31
31
  import CookieContext from './steps/cookie-context.js';
32
32
  import PageLogger from './steps/page-logger.js';
33
- import RedirectTagger from './steps/redirect-tagger.js';
34
33
  import TokenChecker from './steps/token-checker/index.js';
35
34
  import TokenExaminer from './steps/token-examiner.js';
36
35
  import TokenTelemetry from './steps/token-telemetry/index.js';
@@ -211,9 +210,8 @@ export default class RequestReporter {
211
210
 
212
211
  this.userAgent = (await this.getBrowserInfo()).name;
213
212
 
214
- this.pageLogger = new PageLogger(this.config);
213
+ this.pageLogger = new PageLogger(this.config.placeHolder);
215
214
  this.blockRules = new BlockRules(this.config);
216
- this.redirectTagger = new RedirectTagger();
217
215
  this.cookieContext = new CookieContext(this.config, this.qs_whitelist);
218
216
  await this.cookieContext.init();
219
217
 
@@ -280,11 +278,18 @@ export default class RequestReporter {
280
278
  }
281
279
 
282
280
  unload() {
283
- // Check is active usage, was sent
284
- this.qs_whitelist.destroy();
285
- this.cookieContext.unload();
286
- this.tokenExaminer.unload();
287
- this.tokenChecker.unload();
281
+ if (this.qs_whitelist) {
282
+ this.qs_whitelist.destroy();
283
+ }
284
+ if (this.cookieContext) {
285
+ this.cookieContext.unload();
286
+ }
287
+ if (this.tokenExaminer) {
288
+ this.tokenExaminer.unload();
289
+ }
290
+ if (this.tokenChecker) {
291
+ this.tokenChecker.unload();
292
+ }
288
293
 
289
294
  chrome.webRequest.onBeforeRequest.removeListener(this.onBeforeRequest);
290
295
  chrome.webRequest.onBeforeSendHeaders.removeListener(
@@ -294,17 +299,15 @@ export default class RequestReporter {
294
299
  chrome.webRequest.onCompleted.removeListener(this.onCompleted);
295
300
  chrome.webRequest.onErrorOccurred.removeListener(this.onErrorOccurred);
296
301
 
297
- this.db.unload();
302
+ if (this.db) {
303
+ this.db.unload();
304
+ }
298
305
  clearInterval(this.dayChangedInterval);
299
306
  this.dayChangedInterval = null;
300
307
  }
301
308
 
302
309
  onBeforeRequest = (details) => {
303
- const state = WebRequestContext.fromDetails(
304
- details,
305
- this.pageStore,
306
- 'onBeforeRequest',
307
- );
310
+ const state = WebRequestContext.fromDetails(details, this.pageStore);
308
311
  const response = new BlockingResponse(details, 'onBeforeRequest');
309
312
  // checkState
310
313
  if (checkValidContext(state) === false) {
@@ -326,10 +329,9 @@ export default class RequestReporter {
326
329
  if (this.cancelRecentlyModified(state, response) === false) {
327
330
  return response.toWebRequestResponse();
328
331
  }
329
- // pageLogger.onBeforeRequest
330
- if (this.pageLogger.onBeforeRequest(state) === false) {
331
- return response.toWebRequestResponse();
332
- }
332
+
333
+ this.pageLogger.onBeforeRequest(state);
334
+
333
335
  // logIsTracker
334
336
  if (
335
337
  this.qs_whitelist.isTrackerDomain(
@@ -391,11 +393,7 @@ export default class RequestReporter {
391
393
  };
392
394
 
393
395
  onBeforeSendHeaders = (details) => {
394
- const state = WebRequestContext.fromDetails(
395
- details,
396
- this.pageStore,
397
- 'onBeforeSendHeaders',
398
- );
396
+ const state = WebRequestContext.fromDetails(details, this.pageStore);
399
397
  const response = new BlockingResponse(details, 'onBeforeSendHeaders');
400
398
  // checkState
401
399
  if (checkValidContext(state) === false) {
@@ -412,18 +410,9 @@ export default class RequestReporter {
412
410
  if (checkSameGeneralDomain(state) === false) {
413
411
  return response.toWebRequestResponse();
414
412
  }
415
- // pageLogger.onBeforeSendHeaders
416
- if (this.pageLogger.onBeforeSendHeaders(state) === false) {
417
- return response.toWebRequestResponse();
418
- }
419
- // catchMissedOpenListener
420
- if (
421
- (state.reqLog && state.reqLog.c === 0) ||
422
- this.redirectTagger.isFromRedirect(state.url)
423
- ) {
424
- // take output from 'open' pipeline and copy into our response object
425
- this.onBeforeRequest(state, response);
426
- }
413
+
414
+ this.pageLogger.onBeforeSendHeaders(state);
415
+
427
416
  // overrideUserAgent
428
417
  if (this.config.overrideUserAgent === true) {
429
418
  const domainHash = truncatedHash(state.urlParts.generalDomain);
@@ -489,11 +478,7 @@ export default class RequestReporter {
489
478
  };
490
479
 
491
480
  onHeadersReceived = (details) => {
492
- const state = WebRequestContext.fromDetails(
493
- details,
494
- this.pageStore,
495
- 'onHeadersReceived',
496
- );
481
+ const state = WebRequestContext.fromDetails(details, this.pageStore);
497
482
  const response = new BlockingResponse(details, 'onHeadersReceived');
498
483
  // checkState
499
484
  if (checkValidContext(state) === false) {
@@ -507,14 +492,10 @@ export default class RequestReporter {
507
492
  if (checkSameGeneralDomain(state) === false) {
508
493
  return response.toWebRequestResponse();
509
494
  }
510
- // redirectTagger.checkRedirectStatus
511
- if (this.redirectTagger.checkRedirectStatus(state) === false) {
512
- return response.toWebRequestResponse();
513
- }
495
+
514
496
  // pageLogger.onHeadersReceived
515
- if (this.pageLogger.onHeadersReceived(state) === false) {
516
- return response.toWebRequestResponse();
517
- }
497
+ this.pageLogger.onHeadersReceived(state);
498
+
518
499
  // checkSetCookie
519
500
  if ((state.hasSetCookie === true) === false) {
520
501
  return response.toWebRequestResponse();
@@ -560,11 +541,8 @@ export default class RequestReporter {
560
541
  };
561
542
 
562
543
  onCompleted = (details) => {
563
- const state = WebRequestContext.fromDetails(
564
- details,
565
- this.pageStore,
566
- 'onCompleted',
567
- );
544
+ this.whitelistedRequestCache.delete(details.requestId);
545
+ const state = WebRequestContext.fromDetails(details, this.pageStore);
568
546
  // checkState
569
547
  if (checkValidContext(state) === false) {
570
548
  return false;
@@ -574,36 +552,11 @@ export default class RequestReporter {
574
552
  if (isLocalIP(state.ip)) {
575
553
  state.page.isPrivateServer = true;
576
554
  }
577
- return false;
578
555
  }
579
- // pageLogger.reattachStatCounter
580
- if (this.pageLogger.reattachStatCounter(state) === false) {
581
- return false;
582
- }
583
- // logIsCached
584
- this.whitelistedRequestCache.delete(state.requestId);
585
- state.incrementStat(state.fromCache ? 'cached' : 'not_cached');
586
556
  };
587
557
 
588
558
  onErrorOccurred = (details) => {
589
- const state = WebRequestContext.fromDetails(
590
- details,
591
- this.pageStore,
592
- 'onErrorOccurred',
593
- );
594
- // checkState
595
- if (checkValidContext(state) === false) {
596
- return false;
597
- }
598
- // pageLogger.reattachStatCounte
599
- if (this.pageLogger.reattachStatCounter(state) === false) {
600
- return false;
601
- }
602
- // logError
603
- this.whitelistedRequestCache.delete(state.requestId);
604
- if (state.error && state.error.indexOf('ABORT')) {
605
- state.incrementStat('error_abort');
606
- }
559
+ this.whitelistedRequestCache.delete(details.requestId);
607
560
  };
608
561
 
609
562
  async dayChanged() {
@@ -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);
@@ -11,8 +11,6 @@
11
11
 
12
12
  /* eslint no-param-reassign: 'off' */
13
13
 
14
- import { truncateDomain } from '../utils/utils.js';
15
-
16
14
  // maps string (web-ext) to int (FF cpt). Anti-tracking still uses these legacy types.
17
15
  const TYPE_LOOKUP = {
18
16
  other: 1,
@@ -38,76 +36,40 @@ const TYPE_LOOKUP = {
38
36
  };
39
37
 
40
38
  export default class PageLogger {
41
- constructor(config) {
42
- this.config = config;
43
- // maintain the request metadabase between pipeline steps
44
- this._requestCounters = new Map();
45
- }
46
-
47
- _attachCounters(state) {
48
- const domain = truncateDomain(state.urlParts.domainInfo, 2);
49
- const stats = (state.page.requestStats[domain] ||= {});
50
- state.reqLog = stats;
51
- const incrementStat = (statName, c) => {
52
- stats[statName] = (stats[statName] || 0) + (c || 1);
53
- };
54
- const setStat = (statName, value) => {
55
- stats[statName] = value;
56
- };
57
- state.incrementStat = incrementStat;
58
- state.setStat = setStat;
59
-
60
- if (state.requestId) {
61
- this._requestCounters.set(state.requestId, {
62
- incrementStat,
63
- setStat,
64
- });
65
- }
66
- }
67
-
68
- _loadStatCounters(state) {
69
- const meta = this._requestCounters.get(state.requestId);
70
- Object.keys(meta).forEach((k) => {
71
- state[k] = meta[k];
72
- });
39
+ constructor(placeHolder) {
40
+ this.placeHolder = placeHolder;
73
41
  }
74
42
 
75
43
  onBeforeRequest(state) {
76
- this._attachCounters(state);
77
- const { incrementStat, urlParts } = state;
78
-
79
- incrementStat('c');
80
- if (urlParts.search.length > 0) {
81
- incrementStat('has_qs');
44
+ state.incrementStat('c');
45
+ if (state.urlParts.search.length > 0) {
46
+ state.incrementStat('has_qs');
82
47
  }
83
- if (urlParts.hasParameterString() > 0) {
84
- incrementStat('has_ps');
48
+ if (state.urlParts.hasParameterString() > 0) {
49
+ state.incrementStat('has_ps');
85
50
  }
86
- if (urlParts.hash.length > 0) {
87
- incrementStat('has_fragment');
51
+ if (state.urlParts.hash.length > 0) {
52
+ state.incrementStat('has_fragment');
88
53
  }
89
54
  if (state.method === 'POST') {
90
- incrementStat('has_post');
55
+ state.incrementStat('has_post');
91
56
  }
92
57
 
93
- incrementStat(`type_${TYPE_LOOKUP[state.type] || 'unknown'}`);
58
+ state.incrementStat(`type_${TYPE_LOOKUP[state.type] || 'unknown'}`);
94
59
 
95
60
  // log protocol (secure or not)
96
61
  const isHTTP = (protocol) => protocol === 'http:' || protocol === 'https:';
97
- const scheme = isHTTP(urlParts.protocol) ? urlParts.scheme : 'other';
98
- incrementStat(`scheme_${scheme}`);
62
+ const scheme = isHTTP(state.urlParts.protocol)
63
+ ? state.urlParts.scheme
64
+ : 'other';
65
+ state.incrementStat(`scheme_${scheme}`);
99
66
 
100
- if (state.url.indexOf(this.config.placeHolder) > -1) {
101
- incrementStat('hasPlaceHolder');
67
+ if (state.url.indexOf(this.placeHolder) > -1) {
68
+ state.incrementStat('hasPlaceHolder');
102
69
  }
103
70
  }
104
71
 
105
72
  onBeforeSendHeaders(state) {
106
- if (state.requestId && this._requestCounters.has(state.requestId)) {
107
- this._loadStatCounters(state);
108
- } else {
109
- this._attachCounters(state);
110
- }
111
73
  // referer stats
112
74
  const referrer = state.getReferrer();
113
75
  if (referrer && referrer.indexOf(state.tabUrl) > -1) {
@@ -132,15 +94,9 @@ export default class PageLogger {
132
94
  state.incrementStat('cookie_set');
133
95
  }
134
96
  state.hasCookie = hasCookie;
135
- return true;
136
97
  }
137
98
 
138
99
  onHeadersReceived(state) {
139
- if (state.requestId && this._requestCounters.has(state.requestId)) {
140
- this._loadStatCounters(state);
141
- } else {
142
- this._attachCounters(state);
143
- }
144
100
  state.incrementStat('resp_ob');
145
101
  state.incrementStat(
146
102
  'content_length',
@@ -158,17 +114,5 @@ export default class PageLogger {
158
114
  }
159
115
  }
160
116
  state.hasSetCookie = hasSetCookie;
161
-
162
- return true;
163
- }
164
-
165
- reattachStatCounter(state) {
166
- const { requestId } = state;
167
- if (requestId && this._requestCounters.has(requestId)) {
168
- this._loadStatCounters(state);
169
- this._requestCounters.delete(requestId);
170
- return true;
171
- }
172
- return false;
173
117
  }
174
118
  }
@@ -10,6 +10,7 @@
10
10
  */
11
11
 
12
12
  import { parse } from '../../utils/url.js';
13
+ import { truncateDomain } from './utils.js';
13
14
 
14
15
  const VALID_RESPONSE_PROPERTIES = {
15
16
  onBeforeRequest: ['cancel', 'redirectUrl'],
@@ -117,7 +118,7 @@ export class WebRequestContext {
117
118
  * well as provide convenient helpers for parsed URLs, etc. It will also not
118
119
  * return a wrapper for background requests.
119
120
  */
120
- static fromDetails(details, pageStore, event) {
121
+ static fromDetails(details, pageStore) {
121
122
  const context = details;
122
123
 
123
124
  // Check if we have a URL
@@ -125,11 +126,6 @@ export class WebRequestContext {
125
126
  return null;
126
127
  }
127
128
 
128
- // Main frames book keeping
129
- if (context.type === 'main_frame') {
130
- pageStore.onMainFrame(context, event);
131
- }
132
-
133
129
  // Sub frames book keeping
134
130
  if (context.type === 'sub_frame') {
135
131
  pageStore.onSubFrame(context);
@@ -161,6 +157,12 @@ export class WebRequestContext {
161
157
 
162
158
  this.urlParts = parse(this.url);
163
159
  this.tabUrlParts = parse(this.tabUrl);
160
+ this.truncatedDomain = truncateDomain(this.urlParts.domainInfo, 2);
161
+ }
162
+
163
+ incrementStat(statName, c) {
164
+ const stats = (this.page.requestStats[this.truncatedDomain] ||= {});
165
+ stats[statName] = (stats[statName] || 0) + (c || 1);
164
166
  }
165
167
 
166
168
  /**
@@ -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,
@@ -13,7 +13,7 @@
13
13
  import chrome from 'sinon-chrome';
14
14
  import sinon from 'sinon';
15
15
  import { expect } from 'chai';
16
- import EventEmitter from 'node:events';
16
+ import EventEmitter, { once } from 'node:events';
17
17
  import { IDBFactory } from 'fake-indexeddb';
18
18
 
19
19
  import {
@@ -126,6 +126,54 @@ describe('RequestReporter', function () {
126
126
  delete globalThis.indexedDB;
127
127
  });
128
128
 
129
+ context('synthetic events', function () {
130
+ it('records stats from redirects', async function () {
131
+ const events = once(communicationEmiter, 'send');
132
+
133
+ const tab = { id: 1, url: 'https://www.onet.pl/' };
134
+ // creates a page
135
+ chrome.tabs.onCreated.dispatch(tab)
136
+ // changes state to 'completed'
137
+ chrome.webNavigation.onCompleted.dispatch({ tabId: tab.id, frameId: 0, });
138
+
139
+ // prepare iframe
140
+ chrome.webNavigation.onCommitted.dispatch({ tabId: tab.id, parentFrameId: 0, frameId:15032385542, url: "https://pulsembed.eu/p2em/3VgyZUiWT/"});
141
+ chrome.webNavigation.onCommitted.dispatch({ tabId: tab.id, parentFrameId: 15032385542, frameId: 17179869195, url: "https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1"});
142
+
143
+ // Fragment of 0002 snapshot
144
+ chrome.webRequest.onBeforeRequest.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760357996,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","proxyInfo":null,"ip":null,"frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
145
+ chrome.webRequest.onBeforeSendHeaders.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760357997,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","proxyInfo":null,"ip":null,"frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
146
+ chrome.webRequest.onSendHeaders.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760357997,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","proxyInfo":null,"ip":null,"frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
147
+ chrome.webRequest.onHeadersReceived.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760358179,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","fromCache":false,"responseHeaders":[{"name":"p3p","value":"policyref=\"https://googleads.g.doubleclick.net/pagead/gcn_p3p_.xml\", CP=\"CURa ADMa DEVa TAIo PSAo PSDo OUR IND UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\""},{"name":"timing-allow-origin","value":"*"},{"name":"cross-origin-resource-policy","value":"cross-origin"},{"name":"location","value":"https://googleads.g.doubleclick.net/pagead/id?slf_rd=1"},{"name":"access-control-allow-credentials","value":"true"},{"name":"access-control-allow-origin","value":"https://www.youtube.com"},{"name":"date","value":"Thu, 24 Oct 2024 08:59:18 GMT"},{"name":"pragma","value":"no-cache"},{"name":"expires","value":"Fri, 01 Jan 1990 00:00:00 GMT"},{"name":"cache-control","value":"no-cache, no-store, must-revalidate"},{"name":"content-type","value":"text/html; charset=UTF-8"},{"name":"x-content-type-options","value":"nosniff"},{"name":"server","value":"cafe"},{"name":"content-length","value":"0"},{"name":"x-xss-protection","value":"0"},{"name":"alt-svc","value":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"},{"name":"X-Firefox-Spdy","value":"h2"}],"statusCode":302,"statusLine":"HTTP/2.0 302 ","proxyInfo":null,"ip":"172.217.16.162","frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
148
+ chrome.webRequest.onBeforeRedirect.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760358180,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","fromCache":false,"responseHeaders":[{"name":"p3p","value":"policyref=\"https://googleads.g.doubleclick.net/pagead/gcn_p3p_.xml\", CP=\"CURa ADMa DEVa TAIo PSAo PSDo OUR IND UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\""},{"name":"timing-allow-origin","value":"*"},{"name":"cross-origin-resource-policy","value":"cross-origin"},{"name":"location","value":"https://googleads.g.doubleclick.net/pagead/id?slf_rd=1"},{"name":"access-control-allow-credentials","value":"true"},{"name":"access-control-allow-origin","value":"https://www.youtube.com"},{"name":"date","value":"Thu, 24 Oct 2024 08:59:18 GMT"},{"name":"pragma","value":"no-cache"},{"name":"expires","value":"Fri, 01 Jan 1990 00:00:00 GMT"},{"name":"cache-control","value":"no-cache, no-store, must-revalidate"},{"name":"content-type","value":"text/html; charset=UTF-8"},{"name":"x-content-type-options","value":"nosniff"},{"name":"server","value":"cafe"},{"name":"content-length","value":"0"},{"name":"x-xss-protection","value":"0"},{"name":"alt-svc","value":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"},{"name":"X-Firefox-Spdy","value":"h2"}],"statusCode":302,"statusLine":"HTTP/2.0 302 ","redirectUrl":"https://googleads.g.doubleclick.net/pagead/id?slf_rd=1","proxyInfo":null,"ip":"172.217.16.162","frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
149
+ chrome.webRequest.onBeforeRequest.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id?slf_rd=1","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760358181,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","proxyInfo":null,"ip":null,"frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
150
+ chrome.webRequest.onBeforeSendHeaders.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id?slf_rd=1","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760358182,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","proxyInfo":null,"ip":null,"frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
151
+ chrome.webRequest.onSendHeaders.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id?slf_rd=1","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760358182,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","proxyInfo":null,"ip":null,"frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
152
+ chrome.webRequest.onHeadersReceived.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id?slf_rd=1","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760358221,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","fromCache":false,"responseHeaders":[{"name":"p3p","value":"policyref=\"https://googleads.g.doubleclick.net/pagead/gcn_p3p_.xml\", CP=\"CURa ADMa DEVa TAIo PSAo PSDo OUR IND UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\""},{"name":"timing-allow-origin","value":"*"},{"name":"cross-origin-resource-policy","value":"cross-origin"},{"name":"access-control-allow-credentials","value":"true"},{"name":"access-control-allow-origin","value":"https://www.youtube.com"},{"name":"content-type","value":"application/json; charset=UTF-8"},{"name":"date","value":"Thu, 24 Oct 2024 08:59:18 GMT"},{"name":"pragma","value":"no-cache"},{"name":"expires","value":"Fri, 01 Jan 1990 00:00:00 GMT"},{"name":"cache-control","value":"no-cache, no-store, must-revalidate"},{"name":"x-content-type-options","value":"nosniff"},{"name":"content-disposition","value":"attachment; filename=\"f.txt\""},{"name":"content-encoding","value":"gzip"},{"name":"server","value":"cafe"},{"name":"content-length","value":"120"},{"name":"x-xss-protection","value":"0"},{"name":"alt-svc","value":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"},{"name":"X-Firefox-Http3","value":"h3"}],"statusCode":200,"statusLine":"HTTP/3.0 200 ","proxyInfo":null,"ip":"172.217.16.162","frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
153
+ chrome.webRequest.onResponseStarted.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id?slf_rd=1","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760358221,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","fromCache":false,"responseHeaders":[{"name":"p3p","value":"policyref=\"https://googleads.g.doubleclick.net/pagead/gcn_p3p_.xml\", CP=\"CURa ADMa DEVa TAIo PSAo PSDo OUR IND UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\""},{"name":"timing-allow-origin","value":"*"},{"name":"cross-origin-resource-policy","value":"cross-origin"},{"name":"access-control-allow-credentials","value":"true"},{"name":"access-control-allow-origin","value":"https://www.youtube.com"},{"name":"content-type","value":"application/json; charset=UTF-8"},{"name":"date","value":"Thu, 24 Oct 2024 08:59:18 GMT"},{"name":"pragma","value":"no-cache"},{"name":"expires","value":"Fri, 01 Jan 1990 00:00:00 GMT"},{"name":"cache-control","value":"no-cache, no-store, must-revalidate"},{"name":"x-content-type-options","value":"nosniff"},{"name":"content-disposition","value":"attachment; filename=\"f.txt\""},{"name":"content-encoding","value":"gzip"},{"name":"server","value":"cafe"},{"name":"content-length","value":"120"},{"name":"x-xss-protection","value":"0"},{"name":"alt-svc","value":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"},{"name":"X-Firefox-Http3","value":"h3"}],"statusCode":200,"statusLine":"HTTP/3.0 200 ","proxyInfo":null,"ip":"172.217.16.162","frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
154
+ chrome.webRequest.onCompleted.dispatch({"requestId":"294","url":"https://googleads.g.doubleclick.net/pagead/id?slf_rd=1","originUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","documentUrl":"https://www.youtube.com/embed/sQpzRs4j1NQ?mute=1&widget_referrer=https%3A%2F%2Fwww.onet.pl%2F&enablejsapi=1&origin=https%3A%2F%2Fpulsembed.eu&widgetid=1","method":"GET","type":"xmlhttprequest","timeStamp":1729760358221,"tabId":tab.id,"frameId":17179869195,"parentFrameId":15032385542,"incognito":false,"thirdParty":true,"cookieStoreId":"firefox-default","fromCache":false,"responseHeaders":[{"name":"p3p","value":"policyref=\"https://googleads.g.doubleclick.net/pagead/gcn_p3p_.xml\", CP=\"CURa ADMa DEVa TAIo PSAo PSDo OUR IND UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR\""},{"name":"timing-allow-origin","value":"*"},{"name":"cross-origin-resource-policy","value":"cross-origin"},{"name":"access-control-allow-credentials","value":"true"},{"name":"access-control-allow-origin","value":"https://www.youtube.com"},{"name":"content-type","value":"application/json; charset=UTF-8"},{"name":"date","value":"Thu, 24 Oct 2024 08:59:18 GMT"},{"name":"pragma","value":"no-cache"},{"name":"expires","value":"Fri, 01 Jan 1990 00:00:00 GMT"},{"name":"cache-control","value":"no-cache, no-store, must-revalidate"},{"name":"x-content-type-options","value":"nosniff"},{"name":"content-disposition","value":"attachment; filename=\"f.txt\""},{"name":"content-encoding","value":"gzip"},{"name":"server","value":"cafe"},{"name":"content-length","value":"120"},{"name":"x-xss-protection","value":"0"},{"name":"alt-svc","value":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"},{"name":"X-Firefox-Http3","value":"h3"}],"statusCode":200,"statusLine":"HTTP/3.0 200 ","proxyInfo":null,"ip":"172.217.16.162","frameAncestors":[{"frameId":15032385542,"url":"https://pulsembed.eu/p2em/3VgyZUiWT/"},{"frameId":0,"url":"https://www.onet.pl/"}],"urlClassification":{"firstParty":[],"thirdParty":["tracking_ad","any_basic_tracking","any_strict_tracking"]},"requestSize":0,"responseSize":0});
155
+
156
+ // stages the page for sendout
157
+ chrome.tabs.onRemoved.dispatch(tab.id);
158
+ await clock.runToLast();
159
+
160
+ const [event] = await events;
161
+ expect(event).to.include({ action: 'wtm.attrack.tp_events' });
162
+ expect(
163
+ event.payload.data[0].tps['googleads.g.doubleclick.net'],
164
+ ).to.deep.equal({
165
+ c: 2,
166
+ type_11: 2,
167
+ scheme_https: 2,
168
+ resp_ob: 2,
169
+ content_length: 121,
170
+ status_302: 1,
171
+ has_qs: 1,
172
+ status_200: 1,
173
+ });
174
+ });
175
+ });
176
+
129
177
  context('0001-empty-page', function () {
130
178
  it('detects no 3rd parties', async function () {
131
179
  const { seenTabIds } = await playScenario(chrome, {
@@ -1,51 +0,0 @@
1
- /**
2
- * WhoTracks.Me
3
- * https://whotracks.me/
4
- *
5
- * Copyright 2017-present Ghostery GmbH. All rights reserved.
6
- *
7
- * This Source Code Form is subject to the terms of the Mozilla Public
8
- * License, v. 2.0. If a copy of the MPL was not distributed with this
9
- * file, You can obtain one at http://mozilla.org/MPL/2.0
10
- */
11
-
12
- import TempSet from '../utils/temp-set.js';
13
-
14
- const CACHE_TIMEOUT = 10 * 1000;
15
-
16
- /**
17
- * Caches 302 redirects so that we can ensure that the resulting request is properly
18
- * passed through the token logic.
19
- */
20
- export default class RedirectTagger {
21
- constructor() {
22
- this.redirectCache = new TempSet();
23
- }
24
-
25
- isFromRedirect(url) {
26
- return this.redirectCache.has(url);
27
- }
28
-
29
- checkRedirectStatus(state) {
30
- if (state.statusCode === 302) {
31
- const location = state.getResponseHeader('Location');
32
- if (!location) {
33
- // 302 without "Location" in header?
34
- console.log(state, '302 without "Location" in header?');
35
- return true;
36
- }
37
- if (location.startsWith('/')) {
38
- // relative redirect
39
- const redirectUrl = `${state.urlParts.protocol}://${state.urlParts.hostname}${location}`;
40
- this.redirectCache.add(redirectUrl, CACHE_TIMEOUT);
41
- } else if (
42
- location.startsWith('http://') ||
43
- location.startsWith('https://')
44
- ) {
45
- // absolute redirect
46
- this.redirectCache.add(location, CACHE_TIMEOUT);
47
- }
48
- }
49
- return true;
50
- }
51
- }