@whotracksme/reporting 8.0.2 → 9.0.1

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.
@@ -542,28 +542,70 @@ describe('#sanitizePathSegment', function () {
542
542
  }
543
543
  });
544
544
 
545
+ describe('should not crash on arbitrary URL path segments', function () {
546
+ for (const segment of [
547
+ '%F0%90%80%80%F0%90%80%82%F0%90%A0%81IbFe',
548
+ 'b---344%F0%9F%90%80%F0%9F%90%818880-88e',
549
+ '01-%F0%9F%90%80-687%F0%9F%90%80ca%F0%9F%90%80-%F0%9F%90%80b-0245',
550
+ ]) {
551
+ it(`- <<${segment}>>`, function () {
552
+ sanitizePathSegment(segment); // should not throw
553
+ });
554
+ }
555
+ });
556
+
557
+ describe('should safely truncate long strings', function () {
558
+ // %F0%9F%90%80 decodes to U+1F400, which JavaScript stores as the
559
+ // surrogate pair '🐀' (two UTF-16 code units). By growing
560
+ // the prefix one char at a time, we eventually reach a length at
561
+ // which the internal truncation at MAX_TEXT_LENGTH - MASKED.length
562
+ // lands between the high and low surrogate of that pair. The
563
+ // truncated text then carries a lone surrogate, which
564
+ // `encodeURIComponent` rejects with "URI malformed" once the
565
+ // backport step runs.
566
+ it('should not throw when a surrogate pair straddles the truncation boundary', function () {
567
+ for (let i = 0; i < 300; i++) {
568
+ sanitizePathSegment('a'.repeat(i) + '%F0%9F%90%80aaa');
569
+ }
570
+ });
571
+ });
572
+
545
573
  describe('[property based testing]', function () {
574
+ function checkSanitizedPathSegment(pathSegment) {
575
+ const sanitized = sanitizePathSegment(pathSegment);
576
+ if (!sanitized.includes('#??#')) {
577
+ return sanitized === pathSegment;
578
+ }
579
+ if (sanitized.length > pathSegment.length) {
580
+ return false;
581
+ }
582
+ const nonMasked = sanitized.replaceAll('#??#', '');
583
+ return textCanBeDerivedByRemovingChars({
584
+ fullText: pathSegment,
585
+ reducedTo: nonMasked,
586
+ });
587
+ }
588
+
546
589
  it('should only remove, but never add characters', function () {
547
590
  fc.assert(
548
591
  fc.property(fc.webUrl(), (url) => {
549
592
  const { pathname } = new URL(url);
550
593
  for (const pathSegment of pathname.split('/').filter((x) => x)) {
551
- const sanitized = sanitizePathSegment(pathSegment);
552
- if (!sanitized.includes('#??#')) {
553
- return sanitized === pathSegment;
554
- }
555
- if (sanitized.length > pathSegment.length) {
556
- return false;
557
- }
558
- const nonMasked = sanitized.replaceAll('#??#', '');
559
- return textCanBeDerivedByRemovingChars({
560
- fullText: pathSegment,
561
- reducedTo: nonMasked,
562
- });
594
+ return checkSanitizedPathSegment(pathSegment);
563
595
  }
564
596
  }),
565
597
  );
566
598
  });
599
+
600
+ it('should handle arbitrary, long strings', function () {
601
+ fc.assert(
602
+ fc.property(
603
+ fc.string({ unit: 'binary', minLength: 1, maxLength: 2000 }),
604
+ checkSanitizedPathSegment,
605
+ ),
606
+ { numRuns: 5 },
607
+ );
608
+ });
567
609
  });
568
610
  });
569
611
 
@@ -120,6 +120,20 @@ describe('request/index', function () {
120
120
 
121
121
  function simulatePageLoad(pageSpec) {
122
122
  chrome.tabs.onCreated.dispatch(pageSpec.tab);
123
+
124
+ const seen = new Set();
125
+ for (const req of pageSpec.onBeforeRequest) {
126
+ if (seen.has(req.documentId)) continue;
127
+ seen.add(req.documentId);
128
+ chrome.webNavigation.onCommitted.dispatch({
129
+ tabId: req.tabId,
130
+ frameId: req.frameId,
131
+ documentId: req.documentId,
132
+ parentDocumentId: req.parentDocumentId,
133
+ url: req.url,
134
+ });
135
+ }
136
+
123
137
  return {
124
138
  onBeforeRequest: pageSpec.onBeforeRequest.map(function (reqData) {
125
139
  const response = attrack.onBeforeRequest(reqData);
@@ -264,15 +278,26 @@ describe('request/index', function () {
264
278
  attrack.config.tokenDomainCountThreshold = 0; // block first time
265
279
  });
266
280
 
267
- it('removes all occurances of uid in the request', function () {
281
+ function commitTab() {
268
282
  chrome.tabs.onCreated.dispatch({
269
283
  id: 34,
270
284
  url: 'http://cliqztest.com/',
271
285
  });
286
+ chrome.webNavigation.onCommitted.dispatch({
287
+ tabId: 34,
288
+ frameId: 0,
289
+ documentId: 'doc-34-0',
290
+ url: 'http://cliqztest.com/',
291
+ });
292
+ }
293
+
294
+ it('removes all occurances of uid in the request', function () {
295
+ commitTab();
272
296
  const response = attrack.onBeforeRequest({
273
297
  tabId: 34,
274
298
  frameId: 0,
275
299
  parentFrameId: -1,
300
+ documentId: 'doc-34-0',
276
301
  method: 'GET',
277
302
  type: 'xmlhttprequest',
278
303
  url: `http://tracker.com/track;uid=${uid}?uid2=${uid}&encuid=${encodeURIComponent(
@@ -288,14 +313,12 @@ describe('request/index', function () {
288
313
  });
289
314
 
290
315
  it('removes also after subsequent redirect with same uid', function () {
291
- chrome.tabs.onCreated.dispatch({
292
- id: 34,
293
- url: 'http://cliqztest.com/',
294
- });
316
+ commitTab();
295
317
  let response = attrack.onBeforeRequest({
296
318
  tabId: 34,
297
319
  frameId: 0,
298
320
  parentFrameId: -1,
321
+ documentId: 'doc-34-0',
299
322
  method: 'GET',
300
323
  type: 'xmlhttprequest',
301
324
  url: `http://tracker.com/track;uid=${uid}?uid2=${uid}&encuid=${encodeURIComponent(
@@ -314,6 +337,7 @@ describe('request/index', function () {
314
337
  tabId: 34,
315
338
  frameId: 0,
316
339
  parentFrameId: -1,
340
+ documentId: 'doc-34-0',
317
341
  method: 'GET',
318
342
  type: 'xmlhttprequest',
319
343
  url: `http://tracker.com/track;uid=cliqz.com/tracking&uid2=cliqz.com/tracking&uid=${uid}?uid2=${uid}&encuid=${encodeURIComponent(
@@ -1,4 +1,3 @@
1
- /* eslint-disable prettier/prettier */
2
1
  /**
3
2
  * WhoTracks.Me
4
3
  * https://ghostery.com/whotracksme
@@ -13,7 +12,7 @@
13
12
  import chrome from 'sinon-chrome';
14
13
  import sinon from 'sinon';
15
14
  import { expect } from 'chai';
16
- import EventEmitter, { once } from 'node:events';
15
+ import EventEmitter from 'node:events';
17
16
  import { IDBFactory } from 'fake-indexeddb';
18
17
 
19
18
  import {
@@ -25,6 +24,7 @@ import {
25
24
  import { base64ToArrayBuffer } from '../helpers/fetch-mock.js';
26
25
 
27
26
  import { setLogLevel } from '../../src/logger.js';
27
+ import { truncatedHash } from '../../src/md5.js';
28
28
  import RequestReporter from '../../src/request/index.js';
29
29
 
30
30
  const config = {
@@ -119,54 +119,6 @@ describe('RequestReporter', function () {
119
119
  delete globalThis.indexedDB;
120
120
  });
121
121
 
122
- context('synthetic events', function () {
123
- it('records stats from redirects', async function () {
124
- const events = once(communicationEmitter, 'send');
125
-
126
- const tab = { id: 1, url: 'https://www.onet.pl/' };
127
- // creates a page
128
- chrome.tabs.onCreated.dispatch(tab);
129
- // changes state to 'completed'
130
- chrome.webNavigation.onCompleted.dispatch({ tabId: tab.id, frameId: 0, });
131
-
132
- // prepare iframe
133
- chrome.webNavigation.onCommitted.dispatch({ tabId: tab.id, parentFrameId: 0, frameId:15032385542, url: "https://pulsembed.eu/p2em/3VgyZUiWT/"});
134
- 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"});
135
-
136
- // Fragment of 0002 snapshot
137
- 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});
138
- 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});
139
- 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});
140
- 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});
141
- 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});
142
- 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});
143
- 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});
144
- 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});
145
- 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});
146
- 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});
147
- 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});
148
-
149
- // stages the page for sendout
150
- chrome.tabs.onRemoved.dispatch(tab.id);
151
- await clock.runToLast();
152
-
153
- const [event] = await events;
154
- expect(event).to.include({ action: 'wtm.attrack.tp_events' });
155
- expect(
156
- event.payload.data[0].tps['googleads.g.doubleclick.net'],
157
- ).to.deep.equal({
158
- c: 2,
159
- type_11: 2,
160
- scheme_https: 2,
161
- resp_ob: 2,
162
- content_length: 121,
163
- status_302: 1,
164
- has_qs: 1,
165
- status_200: 1,
166
- });
167
- });
168
- });
169
-
170
122
  context('0001-empty-page', function () {
171
123
  it('detects no 3rd parties', async function () {
172
124
  const { seenTabIds } = await playScenario(chrome, {
@@ -174,15 +126,10 @@ describe('RequestReporter', function () {
174
126
  scenarioRelease: '2026-04-23',
175
127
  });
176
128
  await clock.runToLast();
177
- expect(
178
- reporter.pageStore.checkIfEmpty(),
179
- ).to.be.false;
129
+ expect(reporter.pageStore.checkIfEmpty()).to.be.false;
180
130
  expect(seenTabIds).to.have.property('size', 1);
181
131
  const tabId = seenTabIds.values().next().value;
182
- const tab = reporter.pageStore.getPageForRequest({
183
- tabId,
184
- frameId: 0,
185
- });
132
+ const tab = reporter.pageStore.findPageForTab(tabId);
186
133
  expect(tab.requestStats).to.be.empty;
187
134
  });
188
135
  });
@@ -194,15 +141,10 @@ describe('RequestReporter', function () {
194
141
  scenarioRelease: '2026-04-23',
195
142
  });
196
143
  await clock.runToLast();
197
- expect(
198
- reporter.pageStore.checkIfEmpty(),
199
- ).to.be.false;
144
+ expect(reporter.pageStore.checkIfEmpty()).to.be.false;
200
145
  expect(seenTabIds).to.have.property('size', 1);
201
146
  const tabId = seenTabIds.values().next().value;
202
- const tab = reporter.pageStore.getPageForRequest({
203
- tabId,
204
- frameId: 0,
205
- });
147
+ const tab = reporter.pageStore.findPageForTab(tabId);
206
148
  expect(tab.requestStats).to.have.keys(['script.localhost']);
207
149
  });
208
150
 
@@ -217,6 +159,7 @@ describe('RequestReporter', function () {
217
159
  );
218
160
  // force stage all pages
219
161
  seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
162
+ await reporter.pageStore.flush();
220
163
  await clock.runToLast();
221
164
  const event = await eventPromise;
222
165
  expect(event).to.deep.include({
@@ -238,6 +181,7 @@ describe('RequestReporter', function () {
238
181
  );
239
182
  // force stage all pages
240
183
  seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
184
+ await reporter.pageStore.flush();
241
185
  await clock.runToLast();
242
186
  const event = await eventPromise;
243
187
  expect(event).to.deep.include({
@@ -249,22 +193,48 @@ describe('RequestReporter', function () {
249
193
 
250
194
  context('0004-ping', function () {
251
195
  it('reports pings', async function () {
196
+ // The ping fires from the first document (path "/") during
197
+ // navigation to the second (path "/result"), so correct
198
+ // documentId attribution puts ping.localhost on the source
199
+ // page's tp_events. The `next` page, if it emits at all,
200
+ // must not carry the ping. We collect tp_events across the
201
+ // whole run because the source page is held at nav time and
202
+ // its timer fires inside the first runToLast — earlier than
203
+ // a `.once('send')` listener set up after it would catch.
204
+ const events = [];
205
+ communicationEmitter.on('send', (msg) => {
206
+ if (msg.action === 'wtm.attrack.tp_events') {
207
+ events.push(msg);
208
+ }
209
+ });
252
210
  const { seenTabIds } = await playScenario(chrome, {
253
211
  scenarioName: this.test.parent.title,
254
212
  scenarioRelease: '2026-04-23',
255
213
  });
256
214
  await clock.runToLast();
257
- const eventPromise = new Promise((resolve) =>
258
- communicationEmitter.once('send', resolve),
259
- );
260
215
  // force stage all pages
261
216
  seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
217
+ await reporter.pageStore.flush();
262
218
  await clock.runToLast();
263
- const event = await eventPromise;
264
- expect(event).to.deep.include({
265
- action: 'wtm.attrack.tp_events',
266
- });
267
- expect(event.payload.data[0].tps).to.have.keys(['ping.localhost']);
219
+ const sourcePathHash = truncatedHash('/');
220
+ const successorPathHash = truncatedHash('/result');
221
+ const sourceEvent = events.find(
222
+ (e) => e.payload.data[0].path === sourcePathHash,
223
+ );
224
+ const successorEvent = events.find(
225
+ (e) => e.payload.data[0].path === successorPathHash,
226
+ );
227
+ expect(sourceEvent, 'source page tp_events must fire').to.exist;
228
+ expect(Object.keys(sourceEvent.payload.data[0].tps)).to.include(
229
+ 'ping.localhost',
230
+ );
231
+ // The /result page has no third parties of its own; if it
232
+ // emits at all, it must not carry the source's ping.
233
+ if (successorEvent) {
234
+ expect(
235
+ Object.keys(successorEvent.payload.data[0].tps),
236
+ ).to.not.include('ping.localhost');
237
+ }
268
238
  });
269
239
  });
270
240
 
@@ -280,6 +250,7 @@ describe('RequestReporter', function () {
280
250
  );
281
251
  // force stage all pages
282
252
  seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
253
+ await reporter.pageStore.flush();
283
254
  await clock.runToLast();
284
255
  const event = await eventPromise;
285
256
  expect(event).to.deep.include({
@@ -299,7 +270,7 @@ describe('RequestReporter', function () {
299
270
  expect(reporter.pageStore.checkIfEmpty()).to.be.false;
300
271
  expect(seenTabIds).to.have.property('size', 1);
301
272
  const tabId = seenTabIds.values().next().value;
302
- const tab = reporter.pageStore.getPageForRequest({ tabId, frameId: 0 });
273
+ const tab = reporter.pageStore.findPageForTab(tabId);
303
274
  // preconnect opens a socket but fires no webRequest, so no
304
275
  // third-party counters should accumulate.
305
276
  expect(tab.requestStats).to.be.empty;
@@ -318,58 +289,58 @@ describe('RequestReporter', function () {
318
289
  // prerendered document lives on a separate tab and is not
319
290
  // counted against the one the user is looking at.
320
291
  const visibleTabId = seenTabIds.values().next().value;
321
- const tab = reporter.pageStore.getPageForRequest({
322
- tabId: visibleTabId,
323
- frameId: 0,
324
- });
292
+ const tab = reporter.pageStore.findPageForTab(visibleTabId);
325
293
  expect(tab.requestStats).to.be.empty;
326
294
  });
327
295
  });
328
296
 
329
297
  context('0008-navigation', function () {
330
298
  it('reports 3rd parties', async function () {
331
- const eventPromise1 = new Promise((resolve) =>
332
- communicationEmitter.once('send', resolve),
333
- );
299
+ // Two main-frame navigations on the same tab; each page's
300
+ // trackers should attribute to its own document. With
301
+ // event-driven emission (flush on SW startup / tab close),
302
+ // both pages are emitted together once we flush; we then
303
+ // look them up by their own hostname.
304
+ const events = [];
305
+ communicationEmitter.on('send', (msg) => {
306
+ if (msg.action === 'wtm.attrack.tp_events') {
307
+ events.push(msg);
308
+ }
309
+ });
334
310
  const { seenTabIds } = await playScenario(chrome, {
335
311
  scenarioName: this.test.parent.title,
336
312
  scenarioRelease: '2026-04-23',
337
313
  });
338
314
  await clock.runToLast();
339
- const event1 = await eventPromise1;
340
- expect(event1).to.deep.include({
341
- action: 'wtm.attrack.tp_events',
342
- });
343
- expect(event1.payload.data[0].tps).to.have.keys(['script1.localhost']);
344
- const eventPromise2 = new Promise((resolve) =>
345
- communicationEmitter.once('send', resolve),
346
- );
347
315
  // force stage all pages
348
316
  seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
317
+ await reporter.pageStore.flush();
349
318
  await clock.runToLast();
350
- const event2 = await eventPromise2;
351
- expect(event2).to.deep.include({
352
- action: 'wtm.attrack.tp_events',
353
- });
354
- expect(event2.payload.data[0].tps).to.have.keys(['script2.localhost']);
319
+ const page1Event = events.find((e) =>
320
+ Object.keys(e.payload.data[0].tps).includes('script1.localhost'),
321
+ );
322
+ const page2Event = events.find((e) =>
323
+ Object.keys(e.payload.data[0].tps).includes('script2.localhost'),
324
+ );
325
+ expect(page1Event, 'page1 tp_events must fire').to.exist;
326
+ expect(page2Event, 'page2 tp_events must fire').to.exist;
355
327
  // reports should belong to different pages
356
- expect(event1.payload.data[0].hostname).to.not.be.equal(
357
- event2.payload.data[0].hostname,
328
+ expect(page1Event.payload.data[0].hostname).to.not.be.equal(
329
+ page2Event.payload.data[0].hostname,
358
330
  );
359
331
  });
360
332
  });
361
333
 
362
334
  context('0009-beacon', function () {
363
- // SKIP: passes only on the documentId-centric attribution
364
- // branch. User searches on search.localhost, clicks through to
365
- // landing.localhost, and the search document fires two beacons
366
- // to beacon.localhost (click handler + pagehide). Each beacon
367
- // webRequest carries the search document's documentId, so
368
- // correct attribution keeps beacon.localhost on search's
369
- // tp_events. Main's tabId+previous-chain logic misattributes
370
- // the beacons to a staged-and-dead page, silently dropping
371
- // them.
372
- it.skip('attributes late beacon to the source document', async function () {
335
+ // Passes only with document-centric attribution. User searches
336
+ // on search.localhost, clicks through to landing.localhost, and
337
+ // the search document fires two beacons to beacon.localhost
338
+ // (click handler + pagehide). Each beacon webRequest carries
339
+ // the search document's documentId, so correct attribution
340
+ // keeps beacon.localhost on search's tp_events. On main the
341
+ // tabId+previous-chain logic misattributes the beacons to a
342
+ // staged-and-dead page and silently drops them.
343
+ it('attributes late beacon to the source document', async function () {
373
344
  const events = [];
374
345
  communicationEmitter.on('send', (msg) => {
375
346
  if (msg.action === 'wtm.attrack.tp_events') {
@@ -383,12 +354,27 @@ describe('RequestReporter', function () {
383
354
  await clock.runToLast();
384
355
  // Force-stage remaining pages so any held documents flush.
385
356
  seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
357
+ await reporter.pageStore.flush();
386
358
  await clock.runToLast();
387
- const emittedBeacon = events.some((e) =>
388
- Object.keys(e.payload.data[0].tps).includes('beacon.localhost'),
359
+ const searchHostnameHash = truncatedHash('search.localhost');
360
+ const landingHostnameHash = truncatedHash('landing.localhost');
361
+ const searchEvent = events.find(
362
+ (e) => e.payload.data[0].hostname === searchHostnameHash,
363
+ );
364
+ const landingEvent = events.find(
365
+ (e) => e.payload.data[0].hostname === landingHostnameHash,
366
+ );
367
+ // The beacon originates in the search document; it must land
368
+ // on that document's tp_events, not on the successor.
369
+ expect(searchEvent, 'search page tp_events must fire').to.exist;
370
+ expect(Object.keys(searchEvent.payload.data[0].tps)).to.include(
371
+ 'beacon.localhost',
389
372
  );
390
- expect(emittedBeacon, 'beacon.localhost must land in some tp_events')
391
- .to.be.true;
373
+ if (landingEvent) {
374
+ expect(Object.keys(landingEvent.payload.data[0].tps)).to.not.include(
375
+ 'beacon.localhost',
376
+ );
377
+ }
392
378
  });
393
379
  });
394
380
 
@@ -411,7 +397,7 @@ describe('RequestReporter', function () {
411
397
  }
412
398
  }
413
399
 
414
- for (const snapshotName of ['0001', '0002', '0003', '0004', '0005', '0006']) {
400
+ for (const snapshotName of ['0001', '0003', '0005']) {
415
401
  it(snapshotName, async function () {
416
402
  const messages = [];
417
403
  communicationEmitter.addListener('send', (message) =>
@@ -419,14 +405,19 @@ describe('RequestReporter', function () {
419
405
  );
420
406
  playSnapshotScenario(chrome, snapshotName);
421
407
 
422
- // run twice to allow token telemetry to trigger
408
+ // run twice to allow token telemetry to trigger. The
409
+ // documentIdPrefix makes the replay look like a fresh
410
+ // session so that documentId-keyed tp_events dedupe
411
+ // doesn't suppress its reports.
423
412
  playSnapshotScenario(chrome, snapshotName, {
424
- rewriteUrls: { 'onet.pl': 'wp.pl', 'soundcloud.com': 'google.com', 'nike.com': 'adidas.com' },
413
+ rewriteUrls: {
414
+ 'onet.pl': 'wp.pl',
415
+ 'soundcloud.com': 'google.com',
416
+ 'nike.com': 'adidas.com',
417
+ },
418
+ documentIdPrefix: 'replay2-',
425
419
  });
426
- await processRunloopUntil(
427
- reporter.tokenTelemetry
428
- .NEW_ENTRY_MIN_AGE,
429
- );
420
+ await processRunloopUntil(reporter.tokenTelemetry.NEW_ENTRY_MIN_AGE);
430
421
 
431
422
  /* eslint-disable no-undef */
432
423
  if (