@whotracksme/reporting 5.1.31 → 5.1.33

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.
@@ -23,21 +23,20 @@ import * as datetime from './utils/time.js';
23
23
  import QSWhitelist2 from './qs-whitelist2.js';
24
24
  import TempSet from './utils/temp-set.js';
25
25
  import { HashProb, shouldCheckToken } from './hash/index.js';
26
- import { VERSION, COOKIE_MODE } from './config.js';
26
+ import { COOKIE_MODE, VERSION } from './config.js';
27
27
  import { shuffle } from './utils/utils.js';
28
28
  import random from '../random.js';
29
29
 
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';
37
36
  import OAuthDetector from './steps/oauth-detector.js';
38
37
  import {
39
- checkValidContext,
40
38
  checkSameGeneralDomain,
39
+ checkValidContext,
41
40
  } from './steps/check-context.js';
42
41
  import PageStore from './page-store.js';
43
42
 
@@ -74,8 +73,38 @@ export default class RequestReporter {
74
73
  notifyPageStageListeners: this.onPageStaged.bind(this),
75
74
  });
76
75
 
77
- // Web request pipelines
78
- this.pipelines = {};
76
+ this.ready = false;
77
+ const urls = ['http://*/*', 'https://*/*'];
78
+ // TODO: find a way to detect if blocking webRequest is available on Brave and Opera
79
+ const blockingWebRequest = chrome.runtime
80
+ .getManifest()
81
+ .permissions.includes('webRequestBlocking');
82
+
83
+ chrome.webRequest.onBeforeRequest.addListener(
84
+ this.onBeforeRequest,
85
+ { urls },
86
+ blockingWebRequest
87
+ ? Object.values(chrome.webRequest.OnBeforeRequestOptions)
88
+ : undefined,
89
+ );
90
+ chrome.webRequest.onBeforeSendHeaders.addListener(
91
+ this.onBeforeSendHeaders,
92
+ { urls },
93
+ blockingWebRequest
94
+ ? Object.values(chrome.webRequest.OnBeforeSendHeadersOptions)
95
+ : undefined,
96
+ );
97
+ chrome.webRequest.onHeadersReceived.addListener(
98
+ this.onHeadersReceived,
99
+ { urls },
100
+ blockingWebRequest
101
+ ? Object.values(chrome.webRequest.OnHeadersReceivedOptions)
102
+ : undefined,
103
+ );
104
+ chrome.webRequest.onCompleted.addListener(this.onCompleted, { urls });
105
+ chrome.webRequest.onErrorOccurred.addListener(this.onErrorOccurred, {
106
+ urls,
107
+ });
79
108
  }
80
109
 
81
110
  #reportTrackerInteraction(kind, state) {
@@ -211,9 +240,8 @@ export default class RequestReporter {
211
240
 
212
241
  this.userAgent = (await this.getBrowserInfo()).name;
213
242
 
214
- this.pageLogger = new PageLogger(this.config);
243
+ this.pageLogger = new PageLogger(this.config.placeHolder);
215
244
  this.blockRules = new BlockRules(this.config);
216
- this.redirectTagger = new RedirectTagger();
217
245
  this.cookieContext = new CookieContext(this.config, this.qs_whitelist);
218
246
  await this.cookieContext.init();
219
247
 
@@ -247,44 +275,23 @@ export default class RequestReporter {
247
275
  );
248
276
  await this.tokenChecker.init();
249
277
 
250
- const urls = ['http://*/*', 'https://*/*'];
251
- const blockingWebRequest = await chrome.permissions.contains({
252
- permissions: ['webRequestBlocking'],
253
- });
254
-
255
- chrome.webRequest.onBeforeRequest.addListener(
256
- this.onBeforeRequest,
257
- { urls },
258
- blockingWebRequest
259
- ? Object.values(chrome.webRequest.OnBeforeRequestOptions)
260
- : undefined,
261
- );
262
- chrome.webRequest.onBeforeSendHeaders.addListener(
263
- this.onBeforeSendHeaders,
264
- { urls },
265
- blockingWebRequest
266
- ? Object.values(chrome.webRequest.OnBeforeSendHeadersOptions)
267
- : undefined,
268
- );
269
- chrome.webRequest.onHeadersReceived.addListener(
270
- this.onHeadersReceived,
271
- { urls },
272
- blockingWebRequest
273
- ? Object.values(chrome.webRequest.OnHeadersReceivedOptions)
274
- : undefined,
275
- );
276
- chrome.webRequest.onCompleted.addListener(this.onCompleted, { urls });
277
- chrome.webRequest.onErrorOccurred.addListener(this.onErrorOccurred, {
278
- urls,
279
- });
278
+ this.ready = true;
280
279
  }
281
280
 
282
281
  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();
282
+ this.ready = false;
283
+ if (this.qs_whitelist) {
284
+ this.qs_whitelist.destroy();
285
+ }
286
+ if (this.cookieContext) {
287
+ this.cookieContext.unload();
288
+ }
289
+ if (this.tokenExaminer) {
290
+ this.tokenExaminer.unload();
291
+ }
292
+ if (this.tokenChecker) {
293
+ this.tokenChecker.unload();
294
+ }
288
295
 
289
296
  chrome.webRequest.onBeforeRequest.removeListener(this.onBeforeRequest);
290
297
  chrome.webRequest.onBeforeSendHeaders.removeListener(
@@ -294,12 +301,15 @@ export default class RequestReporter {
294
301
  chrome.webRequest.onCompleted.removeListener(this.onCompleted);
295
302
  chrome.webRequest.onErrorOccurred.removeListener(this.onErrorOccurred);
296
303
 
297
- this.db.unload();
304
+ if (this.db) {
305
+ this.db.unload();
306
+ }
298
307
  clearInterval(this.dayChangedInterval);
299
308
  this.dayChangedInterval = null;
300
309
  }
301
310
 
302
311
  onBeforeRequest = (details) => {
312
+ if (!this.ready) return;
303
313
  const state = WebRequestContext.fromDetails(details, this.pageStore);
304
314
  const response = new BlockingResponse(details, 'onBeforeRequest');
305
315
  // checkState
@@ -322,10 +332,9 @@ export default class RequestReporter {
322
332
  if (this.cancelRecentlyModified(state, response) === false) {
323
333
  return response.toWebRequestResponse();
324
334
  }
325
- // pageLogger.onBeforeRequest
326
- if (this.pageLogger.onBeforeRequest(state) === false) {
327
- return response.toWebRequestResponse();
328
- }
335
+
336
+ this.pageLogger.onBeforeRequest(state);
337
+
329
338
  // logIsTracker
330
339
  if (
331
340
  this.qs_whitelist.isTrackerDomain(
@@ -387,6 +396,7 @@ export default class RequestReporter {
387
396
  };
388
397
 
389
398
  onBeforeSendHeaders = (details) => {
399
+ if (!this.ready) return;
390
400
  const state = WebRequestContext.fromDetails(details, this.pageStore);
391
401
  const response = new BlockingResponse(details, 'onBeforeSendHeaders');
392
402
  // checkState
@@ -404,18 +414,9 @@ export default class RequestReporter {
404
414
  if (checkSameGeneralDomain(state) === false) {
405
415
  return response.toWebRequestResponse();
406
416
  }
407
- // pageLogger.onBeforeSendHeaders
408
- if (this.pageLogger.onBeforeSendHeaders(state) === false) {
409
- return response.toWebRequestResponse();
410
- }
411
- // catchMissedOpenListener
412
- if (
413
- (state.reqLog && state.reqLog.c === 0) ||
414
- this.redirectTagger.isFromRedirect(state.url)
415
- ) {
416
- // take output from 'open' pipeline and copy into our response object
417
- this.onBeforeRequest(state, response);
418
- }
417
+
418
+ this.pageLogger.onBeforeSendHeaders(state);
419
+
419
420
  // overrideUserAgent
420
421
  if (this.config.overrideUserAgent === true) {
421
422
  const domainHash = truncatedHash(state.urlParts.generalDomain);
@@ -481,6 +482,7 @@ export default class RequestReporter {
481
482
  };
482
483
 
483
484
  onHeadersReceived = (details) => {
485
+ if (!this.ready) return;
484
486
  const state = WebRequestContext.fromDetails(details, this.pageStore);
485
487
  const response = new BlockingResponse(details, 'onHeadersReceived');
486
488
  // checkState
@@ -495,14 +497,10 @@ export default class RequestReporter {
495
497
  if (checkSameGeneralDomain(state) === false) {
496
498
  return response.toWebRequestResponse();
497
499
  }
498
- // redirectTagger.checkRedirectStatus
499
- if (this.redirectTagger.checkRedirectStatus(state) === false) {
500
- return response.toWebRequestResponse();
501
- }
500
+
502
501
  // pageLogger.onHeadersReceived
503
- if (this.pageLogger.onHeadersReceived(state) === false) {
504
- return response.toWebRequestResponse();
505
- }
502
+ this.pageLogger.onHeadersReceived(state);
503
+
506
504
  // checkSetCookie
507
505
  if ((state.hasSetCookie === true) === false) {
508
506
  return response.toWebRequestResponse();
@@ -548,6 +546,8 @@ export default class RequestReporter {
548
546
  };
549
547
 
550
548
  onCompleted = (details) => {
549
+ if (!this.ready) return;
550
+ this.whitelistedRequestCache.delete(details.requestId);
551
551
  const state = WebRequestContext.fromDetails(details, this.pageStore);
552
552
  // checkState
553
553
  if (checkValidContext(state) === false) {
@@ -558,32 +558,12 @@ export default class RequestReporter {
558
558
  if (isLocalIP(state.ip)) {
559
559
  state.page.isPrivateServer = true;
560
560
  }
561
- return false;
562
- }
563
- // pageLogger.reattachStatCounter
564
- if (this.pageLogger.reattachStatCounter(state) === false) {
565
- return false;
566
561
  }
567
- // logIsCached
568
- this.whitelistedRequestCache.delete(state.requestId);
569
- state.incrementStat(state.fromCache ? 'cached' : 'not_cached');
570
562
  };
571
563
 
572
564
  onErrorOccurred = (details) => {
573
- const state = WebRequestContext.fromDetails(details, this.pageStore);
574
- // checkState
575
- if (checkValidContext(state) === false) {
576
- return false;
577
- }
578
- // pageLogger.reattachStatCounte
579
- if (this.pageLogger.reattachStatCounter(state) === false) {
580
- return false;
581
- }
582
- // logError
583
- this.whitelistedRequestCache.delete(state.requestId);
584
- if (state.error && state.error.indexOf('ABORT')) {
585
- state.incrementStat('error_abort');
586
- }
565
+ if (!this.ready) return;
566
+ this.whitelistedRequestCache.delete(details.requestId);
587
567
  };
588
568
 
589
569
  async dayChanged() {
@@ -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'],
@@ -156,6 +157,12 @@ export class WebRequestContext {
156
157
 
157
158
  this.urlParts = parse(this.url);
158
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);
159
166
  }
160
167
 
161
168
  /**
@@ -65,6 +65,7 @@ describe('request/index', function () {
65
65
  // Thus, leaving the old way to monkey patch, even though it may
66
66
  // indicate that there are bugs in the implementation or in the tests.
67
67
  chrome.storage.session = chrome.storage.local;
68
+ chrome.runtime.getManifest.returns({ permissions: [] });
68
69
  chrome.storage.session.get.yields({});
69
70
  chrome.tabs.query.returns([]);
70
71
 
@@ -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 {
@@ -73,6 +73,7 @@ describe('RequestReporter', function () {
73
73
  beforeEach(function () {
74
74
  chrome.flush();
75
75
  chrome.storage.session.get.yields({});
76
+ chrome.runtime.getManifest.returns({ permissions: [] });
76
77
  chrome.tabs.query.returns([]);
77
78
  });
78
79
 
@@ -126,6 +127,54 @@ describe('RequestReporter', function () {
126
127
  delete globalThis.indexedDB;
127
128
  });
128
129
 
130
+ context('synthetic events', function () {
131
+ it('records stats from redirects', async function () {
132
+ const events = once(communicationEmiter, 'send');
133
+
134
+ const tab = { id: 1, url: 'https://www.onet.pl/' };
135
+ // creates a page
136
+ chrome.tabs.onCreated.dispatch(tab)
137
+ // changes state to 'completed'
138
+ chrome.webNavigation.onCompleted.dispatch({ tabId: tab.id, frameId: 0, });
139
+
140
+ // prepare iframe
141
+ chrome.webNavigation.onCommitted.dispatch({ tabId: tab.id, parentFrameId: 0, frameId:15032385542, url: "https://pulsembed.eu/p2em/3VgyZUiWT/"});
142
+ 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"});
143
+
144
+ // Fragment of 0002 snapshot
145
+ 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});
146
+ 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});
147
+ 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});
148
+ 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});
149
+ 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});
150
+ 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});
151
+ 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});
152
+ 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});
153
+ 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});
154
+ 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});
155
+ 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});
156
+
157
+ // stages the page for sendout
158
+ chrome.tabs.onRemoved.dispatch(tab.id);
159
+ await clock.runToLast();
160
+
161
+ const [event] = await events;
162
+ expect(event).to.include({ action: 'wtm.attrack.tp_events' });
163
+ expect(
164
+ event.payload.data[0].tps['googleads.g.doubleclick.net'],
165
+ ).to.deep.equal({
166
+ c: 2,
167
+ type_11: 2,
168
+ scheme_https: 2,
169
+ resp_ob: 2,
170
+ content_length: 121,
171
+ status_302: 1,
172
+ has_qs: 1,
173
+ status_200: 1,
174
+ });
175
+ });
176
+ });
177
+
129
178
  context('0001-empty-page', function () {
130
179
  it('detects no 3rd parties', async function () {
131
180
  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
- }