@whotracksme/reporting 5.2.1 โ 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/communication/src/errors.js +17 -6
- package/communication/src/server-public-key-accessor.js +27 -15
- package/package.json +1 -1
- package/reporting/example/index.js +12 -2
- package/reporting/src/communication-proxy/attrack-message-handler.js +85 -0
- package/reporting/src/doublefetch-page-handler.js +31 -0
- package/reporting/src/job-scheduler.js +1 -1
- package/reporting/src/reporting.js +13 -0
- package/reporting/src/request/index.js +3 -9
- package/reporting/test/doublefetch-page-handler.spec.js +42 -0
- package/reporting/test/request/index.spec.js +1 -0
- package/reporting/test/request/index.test.js +13 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
# v6.0.0 (Wed Jan 15 2025)
|
|
2
|
+
|
|
3
|
+
#### ๐ฅ Breaking Change
|
|
4
|
+
|
|
5
|
+
- Randomly delay sending of request reporter messages [#149](https://github.com/whotracksme/webextension-packages/pull/149) ([@philipp-classen](https://github.com/philipp-classen))
|
|
6
|
+
|
|
7
|
+
#### ๐ Enhancement
|
|
8
|
+
|
|
9
|
+
- Improve title matching [#150](https://github.com/whotracksme/webextension-packages/pull/150) ([@philipp-classen](https://github.com/philipp-classen) [@chrmod](https://github.com/chrmod))
|
|
10
|
+
|
|
11
|
+
#### Authors: 2
|
|
12
|
+
|
|
13
|
+
- Krzysztof Modras ([@chrmod](https://github.com/chrmod))
|
|
14
|
+
- Philipp Claรen ([@philipp-classen](https://github.com/philipp-classen))
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# v5.2.2 (Wed Jan 15 2025)
|
|
19
|
+
|
|
20
|
+
#### ๐ Bug Fix
|
|
21
|
+
|
|
22
|
+
- Better error handling if fetching public keys fails [#146](https://github.com/whotracksme/webextension-packages/pull/146) ([@philipp-classen](https://github.com/philipp-classen))
|
|
23
|
+
|
|
24
|
+
#### Authors: 1
|
|
25
|
+
|
|
26
|
+
- Philipp Claรen ([@philipp-classen](https://github.com/philipp-classen))
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
1
30
|
# v5.2.1 (Tue Dec 10 2024)
|
|
2
31
|
|
|
3
32
|
#### ๐ Bug Fix
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
* in the code (e.g. configuration errors, incorrect use of the API).
|
|
21
21
|
*/
|
|
22
22
|
class ExtendableError extends Error {
|
|
23
|
-
constructor(message) {
|
|
24
|
-
super(message);
|
|
23
|
+
constructor(message, options) {
|
|
24
|
+
super(message, options);
|
|
25
25
|
this.name = this.constructor.name;
|
|
26
26
|
if (typeof Error.captureStackTrace === 'function') {
|
|
27
27
|
Error.captureStackTrace(this, this.constructor);
|
|
@@ -55,8 +55,8 @@ class ExtendableError extends Error {
|
|
|
55
55
|
* retried at a later point, or replaced by updated messages.
|
|
56
56
|
*/
|
|
57
57
|
class RecoverableError extends ExtendableError {
|
|
58
|
-
constructor(message) {
|
|
59
|
-
super(message);
|
|
58
|
+
constructor(message, options) {
|
|
59
|
+
super(message, options);
|
|
60
60
|
this.isRecoverableError = true;
|
|
61
61
|
this.isPermanentError = false;
|
|
62
62
|
}
|
|
@@ -70,15 +70,26 @@ class RecoverableError extends ExtendableError {
|
|
|
70
70
|
* trying to send it again will again trigger the identical error.
|
|
71
71
|
*/
|
|
72
72
|
class PermanentError extends ExtendableError {
|
|
73
|
-
constructor(message) {
|
|
74
|
-
super(message);
|
|
73
|
+
constructor(message, options) {
|
|
74
|
+
super(message, options);
|
|
75
75
|
this.isRecoverableError = false;
|
|
76
76
|
this.isPermanentError = true;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* The message size exceeded the limit of 32K.
|
|
82
|
+
*/
|
|
80
83
|
export class TooBigMsgError extends PermanentError {}
|
|
84
|
+
|
|
81
85
|
export class TransportError extends RecoverableError {}
|
|
82
86
|
export class ProtocolError extends PermanentError {}
|
|
83
87
|
export class InvalidMessageError extends PermanentError {}
|
|
84
88
|
export class ClockOutOfSync extends RecoverableError {}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Thrown when the client failed to fetch public keys. Without
|
|
92
|
+
* current keys, it cannot setup the end-to-end encryption
|
|
93
|
+
* needed to communicate with the server.
|
|
94
|
+
*/
|
|
95
|
+
export class FailedToFetchPublicKeys extends RecoverableError {}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import logger from './logger.js';
|
|
13
13
|
import { getTimeAsYYYYMMDD } from './timestamps.js';
|
|
14
14
|
import { fromBase64 } from './encoding.js';
|
|
15
|
+
import { FailedToFetchPublicKeys } from './errors.js';
|
|
15
16
|
|
|
16
17
|
function isYYYYMMDD(date) {
|
|
17
18
|
return typeof date === 'string' && /^[0-9]{8}$/.test(date);
|
|
@@ -72,21 +73,7 @@ export default class ServerPublicKeyAccessor {
|
|
|
72
73
|
|
|
73
74
|
// not found on disk or outdated -> fetch from server
|
|
74
75
|
if (!knownKeys) {
|
|
75
|
-
const
|
|
76
|
-
logger.info('Fetching new server public keys from', url);
|
|
77
|
-
const response = await fetch(url, {
|
|
78
|
-
method: 'GET',
|
|
79
|
-
credentials: 'omit',
|
|
80
|
-
redirect: 'manual',
|
|
81
|
-
});
|
|
82
|
-
if (!response.ok) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
`Failed to get config (${response.statusText}) from url=${url}`,
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
const { pubKeys } = await response.json();
|
|
88
|
-
logger.info('Fetched server public keys:', pubKeys);
|
|
89
|
-
|
|
76
|
+
const pubKeys = await this._fetchPublicKeys();
|
|
90
77
|
const allKeys = Object.keys(pubKeys)
|
|
91
78
|
.filter(isYYYYMMDD)
|
|
92
79
|
.map((date) => [date, fromBase64(pubKeys[date])]);
|
|
@@ -104,6 +91,31 @@ export default class ServerPublicKeyAccessor {
|
|
|
104
91
|
this._knownKeys = knownKeys;
|
|
105
92
|
}
|
|
106
93
|
|
|
94
|
+
async _fetchPublicKeys() {
|
|
95
|
+
const url = `${this.collectorUrl}/config?fields=pubKeys`;
|
|
96
|
+
logger.info('Fetching new server public keys from', url);
|
|
97
|
+
try {
|
|
98
|
+
const response = await fetch(url, {
|
|
99
|
+
method: 'GET',
|
|
100
|
+
credentials: 'omit',
|
|
101
|
+
redirect: 'manual',
|
|
102
|
+
});
|
|
103
|
+
if (!response.ok) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Failed to get config (${response.statusText}) from '${url}'`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
const { pubKeys } = await response.json();
|
|
109
|
+
logger.info('Fetched server public keys:', pubKeys);
|
|
110
|
+
return pubKeys;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
throw new FailedToFetchPublicKeys(
|
|
113
|
+
`Failed to fetch public keys from '${url}'`,
|
|
114
|
+
{ cause: e },
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
107
119
|
async importAndVerifyPubKeys(allKeys) {
|
|
108
120
|
return new Map(
|
|
109
121
|
await Promise.all(
|
package/package.json
CHANGED
|
@@ -47,7 +47,11 @@ function createStorage() {
|
|
|
47
47
|
|
|
48
48
|
const communication = {
|
|
49
49
|
send(msg) {
|
|
50
|
-
console.
|
|
50
|
+
console.log(
|
|
51
|
+
'%c[DRY-RUN] send message:',
|
|
52
|
+
'color: blue; font-size: 30px;',
|
|
53
|
+
msg,
|
|
54
|
+
);
|
|
51
55
|
},
|
|
52
56
|
// TODO: use actuall anonymous-communication to access quorum
|
|
53
57
|
sendInstant(msg) {
|
|
@@ -90,7 +94,13 @@ const urlReporter = new UrlReporter({
|
|
|
90
94
|
|
|
91
95
|
const requestReporter = new RequestReporter(config.request, {
|
|
92
96
|
dryRunMode: true,
|
|
93
|
-
|
|
97
|
+
onMessageReady: (msg) => {
|
|
98
|
+
console.log(
|
|
99
|
+
'%c[DRY-RUN] request-reporter message ready:',
|
|
100
|
+
'color: green; font-size: 30px;',
|
|
101
|
+
msg,
|
|
102
|
+
);
|
|
103
|
+
},
|
|
94
104
|
countryProvider: urlReporter.countryProvider,
|
|
95
105
|
trustedClock: communication.trustedClock,
|
|
96
106
|
getBrowserInfo: () => ({ name: 'xx' }),
|
|
@@ -0,0 +1,85 @@
|
|
|
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 logger from '../logger';
|
|
13
|
+
import { requireParam, requireString } from '../utils';
|
|
14
|
+
|
|
15
|
+
const SECOND = 1000;
|
|
16
|
+
const MINUTE = 60 * SECOND;
|
|
17
|
+
const HOUR = 60 * MINUTE;
|
|
18
|
+
const DAY = 24 * HOUR;
|
|
19
|
+
|
|
20
|
+
const ATTRACK_JOB_TYPE = 'attrack:send-message:v1';
|
|
21
|
+
|
|
22
|
+
export default class AttrackMessageHandler {
|
|
23
|
+
constructor({ communication, jobScheduler }) {
|
|
24
|
+
this.communication = requireParam(communication);
|
|
25
|
+
this.jobScheduler = requireParam(jobScheduler);
|
|
26
|
+
|
|
27
|
+
this._configOverride = {
|
|
28
|
+
'wtm.attrack.tokensv2': {
|
|
29
|
+
readyIn: { min: 2 * SECOND, max: 4 * HOUR },
|
|
30
|
+
},
|
|
31
|
+
'wtm.attrack.keysv2': {
|
|
32
|
+
readyIn: { min: 2 * SECOND, max: 4 * HOUR },
|
|
33
|
+
},
|
|
34
|
+
'wtm.attrack.tp_events': {
|
|
35
|
+
readyIn: { min: 2 * SECOND, max: 30 * MINUTE },
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.jobScheduler.registerHandler(
|
|
40
|
+
ATTRACK_JOB_TYPE,
|
|
41
|
+
async (job) => {
|
|
42
|
+
const { message } = job.args;
|
|
43
|
+
requireParam(message);
|
|
44
|
+
requireString(message.action);
|
|
45
|
+
|
|
46
|
+
await this.communication.send(message);
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
priority: -1000,
|
|
50
|
+
cooldownInMs: 1 * SECOND,
|
|
51
|
+
maxJobsTotal: 500,
|
|
52
|
+
maxTTL: 14 * DAY,
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sendInBackground(message) {
|
|
58
|
+
requireParam(message);
|
|
59
|
+
requireString(message.action);
|
|
60
|
+
|
|
61
|
+
if (this.jobScheduler.active) {
|
|
62
|
+
const job = {
|
|
63
|
+
type: ATTRACK_JOB_TYPE,
|
|
64
|
+
args: { message },
|
|
65
|
+
config: this._configOverride[message.action] || {},
|
|
66
|
+
};
|
|
67
|
+
this.jobScheduler.registerJob(job).catch((e) => {
|
|
68
|
+
logger.warn('Failed to register job', job, e);
|
|
69
|
+
this._sendNowInBackground(message);
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
// Sending directly has the advantage that the request reporter
|
|
73
|
+
// can be used even if the URL reporter is not available.
|
|
74
|
+
// It should happen rarely enough.
|
|
75
|
+
logger.info('jobScheduler not available. Send immediately...');
|
|
76
|
+
this._sendNowInBackground(message);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_sendNowInBackground(message) {
|
|
81
|
+
this.communication.send(message).catch((e) => {
|
|
82
|
+
logger.error('Failed to send message', e);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -27,6 +27,25 @@ const ALLOW_HTML_AND_TEXT = [
|
|
|
27
27
|
'application/xhtml+xml', // legacy format
|
|
28
28
|
];
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Checks if one string (subsequence) can be derived from another string (sequence)
|
|
32
|
+
* by only removing characters. This means that the subsequence appears in the
|
|
33
|
+
* sequence in the same relative order but not necessarily consecutively.
|
|
34
|
+
*
|
|
35
|
+
* Example: "anana" is a subsequence of "banana", but "ab" is not.
|
|
36
|
+
*/
|
|
37
|
+
function isSubSequence({ sequence, subsequence }) {
|
|
38
|
+
let i = 0;
|
|
39
|
+
let j = 0;
|
|
40
|
+
while (i < subsequence.length && j < sequence.length) {
|
|
41
|
+
if (subsequence[i] === sequence[j]) {
|
|
42
|
+
i++;
|
|
43
|
+
}
|
|
44
|
+
j++;
|
|
45
|
+
}
|
|
46
|
+
return i === subsequence.length;
|
|
47
|
+
}
|
|
48
|
+
|
|
30
49
|
/**
|
|
31
50
|
* This checks if the extracted title of a website is safe to share.
|
|
32
51
|
* To decide, it compares it with the title on the doublefetch HTML.
|
|
@@ -100,6 +119,18 @@ export function titlesMatchAfterDoublefetch({
|
|
|
100
119
|
}
|
|
101
120
|
}
|
|
102
121
|
|
|
122
|
+
// Removing small parts of text should be generally safe. Note that
|
|
123
|
+
// this is still quite strict; edits like swapping characters or
|
|
124
|
+
// adding a single char will make this heuristic fail.
|
|
125
|
+
if (
|
|
126
|
+
before.length > after.length &&
|
|
127
|
+
after.length > 12 &&
|
|
128
|
+
after.length > 0.75 * before.length &&
|
|
129
|
+
isSubSequence({ sequence: before, subsequence: after })
|
|
130
|
+
) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
|
|
103
134
|
return false;
|
|
104
135
|
}
|
|
105
136
|
|
|
@@ -304,7 +304,7 @@ export default class JobScheduler {
|
|
|
304
304
|
// "min" value and an optional "max" value (if you want randomness).
|
|
305
305
|
//
|
|
306
306
|
// Examples:
|
|
307
|
-
// - { min: 2000} will delay by (at least) 2 seconds
|
|
307
|
+
// - { min: 2000 } will delay by (at least) 2 seconds
|
|
308
308
|
// - { min: 2000, max: 3000 } will delay by (at least) 2-3 seconds
|
|
309
309
|
//
|
|
310
310
|
// Note: the real delay can be higher, since there is no guarantee
|
|
@@ -29,6 +29,7 @@ import PersistedHashes from './persisted-hashes';
|
|
|
29
29
|
import AliveCheck from './alive-check';
|
|
30
30
|
import AliveMessageGenerator from './alive-message-generator';
|
|
31
31
|
import SessionStorageWrapper from './session-storage';
|
|
32
|
+
import AttrackMessageHandler from './communication-proxy/attrack-message-handler';
|
|
32
33
|
import logger from './logger';
|
|
33
34
|
import SelfCheck from './self-check';
|
|
34
35
|
import { BloomFilter } from './bloom-filters';
|
|
@@ -152,6 +153,11 @@ export default class Reporting {
|
|
|
152
153
|
storage,
|
|
153
154
|
storageKey: 'alive_check',
|
|
154
155
|
});
|
|
156
|
+
|
|
157
|
+
this.attrackMessageHandler = new AttrackMessageHandler({
|
|
158
|
+
communication,
|
|
159
|
+
jobScheduler: this.jobScheduler,
|
|
160
|
+
});
|
|
155
161
|
}
|
|
156
162
|
|
|
157
163
|
async init() {
|
|
@@ -270,6 +276,13 @@ export default class Reporting {
|
|
|
270
276
|
await this.patternsUpdater.update();
|
|
271
277
|
}
|
|
272
278
|
|
|
279
|
+
// Drop-in replacement for "communication.send". To be used by the
|
|
280
|
+
// request reporter. It is a synchronous fire-and-forget API. The
|
|
281
|
+
// message delivery will be best-effort. Also, it may be delayed.
|
|
282
|
+
forwardRequestReporterMessage(msg) {
|
|
283
|
+
this.attrackMessageHandler.sendInBackground(msg);
|
|
284
|
+
}
|
|
285
|
+
|
|
273
286
|
async selfChecks(check = new SelfCheck()) {
|
|
274
287
|
if (!this.isActive) {
|
|
275
288
|
check.warn('reporting is not enabled');
|
|
@@ -47,7 +47,7 @@ export default class RequestReporter {
|
|
|
47
47
|
{
|
|
48
48
|
trustedClock,
|
|
49
49
|
countryProvider,
|
|
50
|
-
|
|
50
|
+
onMessageReady,
|
|
51
51
|
getBrowserInfo,
|
|
52
52
|
onTrackerInteraction = (event, state) => {
|
|
53
53
|
logger.info('Tracker', event, 'with url:', state.url);
|
|
@@ -57,7 +57,7 @@ export default class RequestReporter {
|
|
|
57
57
|
},
|
|
58
58
|
) {
|
|
59
59
|
this.settings = settings;
|
|
60
|
-
this.
|
|
60
|
+
this.onMessageReady = onMessageReady;
|
|
61
61
|
this.trustedClock = trustedClock;
|
|
62
62
|
this.countryProvider = countryProvider;
|
|
63
63
|
this.onTrackerInteraction = onTrackerInteraction;
|
|
@@ -150,11 +150,6 @@ export default class RequestReporter {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
telemetry(message) {
|
|
153
|
-
if (!this.communication) {
|
|
154
|
-
logger.error('No provider provider loaded');
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
153
|
message.type = 'wtm.request';
|
|
159
154
|
message.userAgent = this.userAgent;
|
|
160
155
|
message.ts = this.trustedClock.getTimeAsYYYYMMDD();
|
|
@@ -168,8 +163,7 @@ export default class RequestReporter {
|
|
|
168
163
|
message.payload.ctry = this.countryProvider.getSafeCountryCode();
|
|
169
164
|
|
|
170
165
|
logger.debug('report', message);
|
|
171
|
-
|
|
172
|
-
this.communication.send(message);
|
|
166
|
+
this.onMessageReady(message);
|
|
173
167
|
}
|
|
174
168
|
|
|
175
169
|
/** Global module initialisation.
|
|
@@ -717,6 +717,48 @@ describe('#titlesMatchAfterDoublefetch', function () {
|
|
|
717
717
|
}
|
|
718
718
|
});
|
|
719
719
|
});
|
|
720
|
+
|
|
721
|
+
describe('should tolerate removing a limited amount of chars in a longer title', function () {
|
|
722
|
+
describe('if most of the text is still preserved', function () {
|
|
723
|
+
for (const { before, after } of [
|
|
724
|
+
{
|
|
725
|
+
before:
|
|
726
|
+
'Darts-WM 2025: Alle Spiele heute live in TV und Stream schauen - COMPUTER BILD',
|
|
727
|
+
after:
|
|
728
|
+
'Darts-WM 2025: Alle Spiele live in TV und Stream schauen - COMPUTER BILD',
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
before:
|
|
732
|
+
'Darts-WM 2025: Alle Spiele heute live in TV und Stream schauen - COMPUTER BILD',
|
|
733
|
+
after:
|
|
734
|
+
'Darts-WM: Alle Spiele heute live in TV und Stream schauen - COMPUTER BILD',
|
|
735
|
+
},
|
|
736
|
+
]) {
|
|
737
|
+
it(`- ${before} --> ${after}`, function () {
|
|
738
|
+
shouldMatch(before, after);
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
describe('but reject if too much is removed', function () {
|
|
744
|
+
for (const { before, after } of [
|
|
745
|
+
{
|
|
746
|
+
before:
|
|
747
|
+
'Darts-WM 2025: Alle Spiele heute live in TV und Stream schauen - COMPUTER BILD',
|
|
748
|
+
after: 'Darts-WM 2025',
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
before:
|
|
752
|
+
'Darts-WM 2025: Alle Spiele heute live in TV und Stream schauen - COMPUTER BILD',
|
|
753
|
+
after: 'COMPUTER BILD',
|
|
754
|
+
},
|
|
755
|
+
]) {
|
|
756
|
+
it(`- ${before} --> ${after}`, function () {
|
|
757
|
+
shouldNotMatch(before, after);
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
});
|
|
720
762
|
});
|
|
721
763
|
|
|
722
764
|
describe('#sanitizeActivity', function () {
|
|
@@ -87,7 +87,7 @@ describe('RequestReporter', function () {
|
|
|
87
87
|
context('with pre-recorded events', function () {
|
|
88
88
|
let reporter;
|
|
89
89
|
let clock;
|
|
90
|
-
const
|
|
90
|
+
const communicationEmitter = new EventEmitter();
|
|
91
91
|
|
|
92
92
|
beforeEach(async function () {
|
|
93
93
|
globalThis.indexedDB = new IDBFactory();
|
|
@@ -100,18 +100,11 @@ describe('RequestReporter', function () {
|
|
|
100
100
|
return '';
|
|
101
101
|
},
|
|
102
102
|
};
|
|
103
|
-
|
|
104
|
-
const communication = {
|
|
105
|
-
send(msg) {
|
|
106
|
-
communicationEmiter.emit('send', msg);
|
|
107
|
-
},
|
|
108
|
-
sendInstant(msg) {
|
|
109
|
-
communicationEmiter.emit('sendInstant', msg);
|
|
110
|
-
},
|
|
111
|
-
trustedClock,
|
|
112
|
-
};
|
|
103
|
+
communicationEmitter.removeAllListeners();
|
|
113
104
|
reporter = new RequestReporter(config, {
|
|
114
|
-
|
|
105
|
+
onMessageReady: (msg) => {
|
|
106
|
+
communicationEmitter.emit('send', msg);
|
|
107
|
+
},
|
|
115
108
|
trustedClock,
|
|
116
109
|
getBrowserInfo: () => ({ name: 'xx' }),
|
|
117
110
|
countryProvider: { getSafeCountryCode: () => 'en' },
|
|
@@ -129,11 +122,11 @@ describe('RequestReporter', function () {
|
|
|
129
122
|
|
|
130
123
|
context('synthetic events', function () {
|
|
131
124
|
it('records stats from redirects', async function () {
|
|
132
|
-
const events = once(
|
|
125
|
+
const events = once(communicationEmitter, 'send');
|
|
133
126
|
|
|
134
127
|
const tab = { id: 1, url: 'https://www.onet.pl/' };
|
|
135
128
|
// creates a page
|
|
136
|
-
chrome.tabs.onCreated.dispatch(tab)
|
|
129
|
+
chrome.tabs.onCreated.dispatch(tab);
|
|
137
130
|
// changes state to 'completed'
|
|
138
131
|
chrome.webNavigation.onCompleted.dispatch({ tabId: tab.id, frameId: 0, });
|
|
139
132
|
|
|
@@ -221,7 +214,7 @@ describe('RequestReporter', function () {
|
|
|
221
214
|
});
|
|
222
215
|
await clock.runToLast();
|
|
223
216
|
const eventPromise = new Promise((resolve) =>
|
|
224
|
-
|
|
217
|
+
communicationEmitter.once('send', resolve),
|
|
225
218
|
);
|
|
226
219
|
// force stage all pages
|
|
227
220
|
seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
|
|
@@ -237,7 +230,7 @@ describe('RequestReporter', function () {
|
|
|
237
230
|
context('0004-ping', function () {
|
|
238
231
|
it('reports pings', async function () {
|
|
239
232
|
const eventPromise = new Promise((resolve) =>
|
|
240
|
-
|
|
233
|
+
communicationEmitter.once('send', resolve),
|
|
241
234
|
);
|
|
242
235
|
await playScenario(chrome, {
|
|
243
236
|
scenarioName: this.test.parent.title,
|
|
@@ -261,7 +254,7 @@ describe('RequestReporter', function () {
|
|
|
261
254
|
});
|
|
262
255
|
await clock.runToLast();
|
|
263
256
|
const eventPromise = new Promise((resolve) =>
|
|
264
|
-
|
|
257
|
+
communicationEmitter.once('send', resolve),
|
|
265
258
|
);
|
|
266
259
|
// force stage all pages
|
|
267
260
|
seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
|
|
@@ -277,7 +270,7 @@ describe('RequestReporter', function () {
|
|
|
277
270
|
context('0008-navigation', function () {
|
|
278
271
|
it('reports 3rd parties', async function () {
|
|
279
272
|
const eventPromise1 = new Promise((resolve) =>
|
|
280
|
-
|
|
273
|
+
communicationEmitter.once('send', resolve),
|
|
281
274
|
);
|
|
282
275
|
const { seenTabIds } = await playScenario(chrome, {
|
|
283
276
|
scenarioName: this.test.parent.title,
|
|
@@ -290,7 +283,7 @@ describe('RequestReporter', function () {
|
|
|
290
283
|
});
|
|
291
284
|
expect(event1.payload.data[0].tps).to.have.keys(['script1.localhost']);
|
|
292
285
|
const eventPromise2 = new Promise((resolve) =>
|
|
293
|
-
|
|
286
|
+
communicationEmitter.once('send', resolve),
|
|
294
287
|
);
|
|
295
288
|
// force stage all pages
|
|
296
289
|
seenTabIds.forEach((tabId) => chrome.tabs.onRemoved.dispatch(tabId));
|
|
@@ -329,7 +322,7 @@ describe('RequestReporter', function () {
|
|
|
329
322
|
for (const snapshotName of ['0001', '0002', '0003', '0004', '0005', '0006']) {
|
|
330
323
|
it(snapshotName, async function () {
|
|
331
324
|
const messages = [];
|
|
332
|
-
|
|
325
|
+
communicationEmitter.addListener('send', (message) =>
|
|
333
326
|
messages.push(cleanupMessage(message)),
|
|
334
327
|
);
|
|
335
328
|
playSnapshotScenario(chrome, snapshotName);
|