@whotracksme/reporting 8.0.2 → 9.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 +19 -0
- package/package.json +1 -1
- package/reporting/scenarios/README.md +11 -15
- package/reporting/snapshots/0001/snapshot.json +48 -24
- package/reporting/snapshots/0003/snapshot.json +22 -22
- package/reporting/snapshots/0005/snapshot.json +140 -124
- package/reporting/src/popularity-vote-sanitizer.js +59 -1
- package/reporting/src/request/index.js +14 -0
- package/reporting/src/request/page-store.js +217 -209
- package/reporting/src/request/utils/webrequest.js +0 -5
- package/reporting/test/helpers/scenarios.js +11 -0
- package/reporting/test/popularity-vote-sanitizer.spec.js +54 -12
- package/reporting/test/request/index.spec.js +29 -5
- package/reporting/test/request/index.test.js +107 -116
- package/reporting/test/request/page-store.test.js +251 -83
- package/reporting/test/request/test-pages.js +116 -0
- package/reporting/snapshots/0002/events.log.br +0 -0
- package/reporting/snapshots/0002/snapshot.json +0 -2511
- package/reporting/snapshots/0004/events.log.br +0 -0
- package/reporting/snapshots/0004/snapshot.json +0 -759
- package/reporting/snapshots/0006/events.log.br +0 -0
- package/reporting/snapshots/0006/snapshot.json +0 -5489
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import chrome from 'sinon-chrome';
|
|
13
|
-
import { mock
|
|
13
|
+
import { mock } from 'sinon';
|
|
14
14
|
import { expect } from 'chai';
|
|
15
15
|
|
|
16
16
|
import PageStore from '../../src/request/page-store.js';
|
|
@@ -25,6 +25,7 @@ describe('PageStore', function () {
|
|
|
25
25
|
chrome.flush();
|
|
26
26
|
chrome.storage.session.get.yields({});
|
|
27
27
|
chrome.tabs.query.returns([]);
|
|
28
|
+
chrome.webNavigation.getAllFrames.resolves([]);
|
|
28
29
|
});
|
|
29
30
|
|
|
30
31
|
after(function () {
|
|
@@ -32,123 +33,290 @@ describe('PageStore', function () {
|
|
|
32
33
|
delete globalThis.chrome;
|
|
33
34
|
});
|
|
34
35
|
|
|
35
|
-
it('starts with empty
|
|
36
|
+
it('starts with empty store', async function () {
|
|
36
37
|
const store = new PageStore({});
|
|
37
38
|
await store.init();
|
|
38
39
|
expect(store.checkIfEmpty()).to.be.true;
|
|
39
40
|
});
|
|
40
41
|
|
|
41
|
-
context('
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
context('documentId attribution', function () {
|
|
43
|
+
async function commit(store, { tabId, documentId, url }) {
|
|
44
|
+
chrome.webNavigation.onCommitted.dispatch({
|
|
45
|
+
tabId,
|
|
46
|
+
frameId: 0,
|
|
47
|
+
documentId,
|
|
48
|
+
url,
|
|
49
|
+
});
|
|
50
|
+
chrome.webNavigation.onCompleted.dispatch({
|
|
51
|
+
tabId,
|
|
52
|
+
frameId: 0,
|
|
53
|
+
documentId,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
it('resolves a request to the page owning its documentId', async function () {
|
|
58
|
+
const store = new PageStore({ notifyPageStageListeners: () => {} });
|
|
44
59
|
await store.init();
|
|
45
|
-
const
|
|
46
|
-
|
|
60
|
+
const tabId = 1;
|
|
61
|
+
const documentId = 'DOC-1';
|
|
62
|
+
await commit(store, {
|
|
63
|
+
tabId,
|
|
64
|
+
documentId,
|
|
65
|
+
url: 'https://source.test/',
|
|
66
|
+
});
|
|
67
|
+
const page = store.getPageForRequest({
|
|
68
|
+
tabId,
|
|
69
|
+
frameId: 0,
|
|
70
|
+
documentId,
|
|
71
|
+
type: 'script',
|
|
72
|
+
url: 'https://tracker.test/a.js',
|
|
73
|
+
});
|
|
74
|
+
expect(page).to.include({ url: 'https://source.test/', documentId });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('keeps the document available so late beacons attribute to the source', async function () {
|
|
78
|
+
const listener = mock();
|
|
79
|
+
const store = new PageStore({ notifyPageStageListeners: listener });
|
|
80
|
+
await store.init();
|
|
81
|
+
const tabId = 1;
|
|
82
|
+
const sourceDoc = 'DOC_SOURCE';
|
|
83
|
+
const landingDoc = 'DOC_LANDING';
|
|
84
|
+
|
|
85
|
+
await commit(store, {
|
|
86
|
+
tabId,
|
|
87
|
+
documentId: sourceDoc,
|
|
88
|
+
url: 'https://source.test/',
|
|
89
|
+
});
|
|
90
|
+
// Navigate to landing — source is NOT emitted, just kept in
|
|
91
|
+
// storage alongside the new document.
|
|
92
|
+
await commit(store, {
|
|
93
|
+
tabId,
|
|
94
|
+
documentId: landingDoc,
|
|
95
|
+
url: 'https://landing.test/',
|
|
96
|
+
});
|
|
97
|
+
expect(listener).to.not.have.been.called;
|
|
47
98
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
99
|
+
// A late beacon carrying the source document's documentId
|
|
100
|
+
// resolves to the source page, not to landing.
|
|
101
|
+
const beaconPage = store.getPageForRequest({
|
|
102
|
+
tabId,
|
|
103
|
+
frameId: 0,
|
|
104
|
+
documentId: sourceDoc,
|
|
105
|
+
type: 'ping',
|
|
106
|
+
url: 'https://analytics.test/beacon',
|
|
52
107
|
});
|
|
108
|
+
expect(beaconPage).to.not.be.null;
|
|
109
|
+
expect(beaconPage.documentId).to.equal(sourceDoc);
|
|
110
|
+
expect(beaconPage.url).to.equal('https://source.test/');
|
|
53
111
|
});
|
|
54
|
-
});
|
|
55
112
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const store = new PageStore({});
|
|
113
|
+
it('bfcache re-commit does not create a second record for the same documentId', async function () {
|
|
114
|
+
const listener = mock();
|
|
115
|
+
const store = new PageStore({ notifyPageStageListeners: listener });
|
|
59
116
|
await store.init();
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
117
|
+
const tabId = 1;
|
|
118
|
+
const sourceDoc = 'DOC_SOURCE';
|
|
119
|
+
const landingDoc = 'DOC_LANDING';
|
|
120
|
+
|
|
121
|
+
await commit(store, {
|
|
122
|
+
tabId,
|
|
123
|
+
documentId: sourceDoc,
|
|
124
|
+
url: 'https://source.test/',
|
|
66
125
|
});
|
|
126
|
+
await commit(store, {
|
|
127
|
+
tabId,
|
|
128
|
+
documentId: landingDoc,
|
|
129
|
+
url: 'https://landing.test/',
|
|
130
|
+
});
|
|
131
|
+
// Back button — source's documentId re-commits.
|
|
132
|
+
await commit(store, {
|
|
133
|
+
tabId,
|
|
134
|
+
documentId: sourceDoc,
|
|
135
|
+
url: 'https://source.test/',
|
|
136
|
+
});
|
|
137
|
+
// The source page was never emitted on the way out, nothing
|
|
138
|
+
// has been reported yet.
|
|
139
|
+
expect(listener).to.not.have.been.called;
|
|
140
|
+
// The store has exactly one page per unique documentId, not
|
|
141
|
+
// a duplicated record from the re-commit.
|
|
142
|
+
const resolved = store.getPageForRequest({
|
|
143
|
+
tabId,
|
|
144
|
+
frameId: 0,
|
|
145
|
+
documentId: sourceDoc,
|
|
146
|
+
type: 'script',
|
|
147
|
+
url: 'https://t.test/a.js',
|
|
148
|
+
});
|
|
149
|
+
expect(resolved.documentId).to.equal(sourceDoc);
|
|
67
150
|
});
|
|
68
151
|
|
|
69
|
-
it('
|
|
70
|
-
const store = new PageStore({});
|
|
152
|
+
it('drops requests from a non-active document (prerender)', async function () {
|
|
153
|
+
const store = new PageStore({ notifyPageStageListeners: () => {} });
|
|
71
154
|
await store.init();
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
).to.have.property('url', undefined);
|
|
82
|
-
chrome.tabs.onUpdated.dispatch(tab.id, { url: 'about:blank' }, tab);
|
|
83
|
-
expect(
|
|
84
|
-
store.getPageForRequest({ tabId: tab.id, frameId: 0 }),
|
|
85
|
-
).to.have.property('url', 'about:blank');
|
|
155
|
+
const page = store.getPageForRequest({
|
|
156
|
+
tabId: 1,
|
|
157
|
+
frameId: 0,
|
|
158
|
+
documentId: 'DOC_PRERENDER',
|
|
159
|
+
documentLifecycle: 'prerender',
|
|
160
|
+
type: 'script',
|
|
161
|
+
url: 'https://tracker.test/a.js',
|
|
162
|
+
});
|
|
163
|
+
expect(page).to.be.null;
|
|
86
164
|
});
|
|
87
|
-
});
|
|
88
165
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const store = new PageStore({});
|
|
166
|
+
it('falls back to parentDocumentId for a sub-frame request whose commit has not fired yet', async function () {
|
|
167
|
+
const store = new PageStore({ notifyPageStageListeners: () => {} });
|
|
92
168
|
await store.init();
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
169
|
+
const tabId = 1;
|
|
170
|
+
const rootDoc = 'DOC_ROOT';
|
|
171
|
+
await commit(store, {
|
|
172
|
+
tabId,
|
|
173
|
+
documentId: rootDoc,
|
|
174
|
+
url: 'https://parent.test/',
|
|
175
|
+
});
|
|
176
|
+
// Sub-frame webRequest fires BEFORE its own onCommitted.
|
|
177
|
+
const page = store.getPageForRequest({
|
|
178
|
+
tabId,
|
|
179
|
+
frameId: 5,
|
|
180
|
+
documentId: 'DOC_SUB',
|
|
181
|
+
parentDocumentId: rootDoc,
|
|
182
|
+
type: 'sub_frame',
|
|
183
|
+
url: 'https://iframe.test/',
|
|
98
184
|
});
|
|
185
|
+
expect(page).to.not.be.null;
|
|
186
|
+
expect(page.documentId).to.equal(rootDoc);
|
|
99
187
|
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
context('flushing', function () {
|
|
191
|
+
async function commit(store, { tabId, documentId, url }) {
|
|
192
|
+
chrome.webNavigation.onCommitted.dispatch({
|
|
193
|
+
tabId,
|
|
194
|
+
frameId: 0,
|
|
195
|
+
documentId,
|
|
196
|
+
url,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
100
199
|
|
|
101
|
-
it('stages
|
|
200
|
+
it('stages a page when its tab is removed', async function () {
|
|
102
201
|
const listener = mock();
|
|
103
202
|
const store = new PageStore({ notifyPageStageListeners: listener });
|
|
104
203
|
await store.init();
|
|
105
|
-
|
|
204
|
+
await commit(store, {
|
|
106
205
|
tabId: 1,
|
|
107
|
-
|
|
108
|
-
url: '
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
expect(listener).to.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// sets PAGE_LOADING_STATE.COMPLETE;
|
|
116
|
-
chrome.webNavigation.onCompleted.dispatch(details);
|
|
117
|
-
|
|
118
|
-
chrome.webNavigation.onBeforeNavigate.dispatch({
|
|
119
|
-
...details,
|
|
120
|
-
timeStamp: details.timeStamp + 300,
|
|
121
|
-
});
|
|
122
|
-
expect(listener).to.have.been.calledWith(
|
|
123
|
-
match({
|
|
124
|
-
id: page.id,
|
|
125
|
-
url: details.url,
|
|
126
|
-
created: details.timeStamp,
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
206
|
+
documentId: 'DOC_A',
|
|
207
|
+
url: 'https://example.test/',
|
|
208
|
+
});
|
|
209
|
+
chrome.tabs.onRemoved.dispatch(1);
|
|
210
|
+
await store.flush();
|
|
211
|
+
expect(listener).to.have.been.calledOnce;
|
|
212
|
+
expect(listener.firstCall.args[0].documentId).to.equal('DOC_A');
|
|
129
213
|
});
|
|
130
214
|
|
|
131
|
-
it('
|
|
215
|
+
it('stages a page when its tab is memory-discarded', async function () {
|
|
132
216
|
const listener = mock();
|
|
133
217
|
const store = new PageStore({ notifyPageStageListeners: listener });
|
|
134
218
|
await store.init();
|
|
135
|
-
|
|
219
|
+
await commit(store, {
|
|
136
220
|
tabId: 1,
|
|
137
|
-
|
|
138
|
-
url: '
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
|
|
221
|
+
documentId: 'DOC_A',
|
|
222
|
+
url: 'https://example.test/',
|
|
223
|
+
});
|
|
224
|
+
chrome.tabs.onUpdated.dispatch(1, { discarded: true }, { id: 1 });
|
|
225
|
+
await store.flush();
|
|
226
|
+
expect(listener).to.have.been.calledOnce;
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('keeps a page across navigations until the bfcache TTL elapses', async function () {
|
|
230
|
+
const listener = mock();
|
|
231
|
+
const store = new PageStore({ notifyPageStageListeners: listener });
|
|
232
|
+
await store.init();
|
|
233
|
+
const tabId = 1;
|
|
234
|
+
await commit(store, {
|
|
235
|
+
tabId,
|
|
236
|
+
documentId: 'DOC_A',
|
|
237
|
+
url: 'https://a.test/',
|
|
238
|
+
});
|
|
239
|
+
// User navigates to B; A may still come back via bfcache.
|
|
240
|
+
await commit(store, {
|
|
241
|
+
tabId,
|
|
242
|
+
documentId: 'DOC_B',
|
|
243
|
+
url: 'https://b.test/',
|
|
244
|
+
});
|
|
245
|
+
// Browser only reports B as live now.
|
|
246
|
+
chrome.webNavigation.getAllFrames.resolves([{ documentId: 'DOC_B' }]);
|
|
247
|
+
chrome.tabs.query.returns([{ id: tabId }]);
|
|
248
|
+
|
|
249
|
+
// First sweep marks A as cached but doesn't stage it.
|
|
250
|
+
await store.flush();
|
|
251
|
+
expect(listener).to.not.have.been.called;
|
|
252
|
+
|
|
253
|
+
// Second sweep within TTL — still alive.
|
|
254
|
+
await store.flush();
|
|
142
255
|
expect(listener).to.not.have.been.called;
|
|
256
|
+
});
|
|
143
257
|
|
|
144
|
-
|
|
145
|
-
|
|
258
|
+
it('clears stageAfter on bfcache restore', async function () {
|
|
259
|
+
const listener = mock();
|
|
260
|
+
const store = new PageStore({ notifyPageStageListeners: listener });
|
|
261
|
+
await store.init();
|
|
262
|
+
const tabId = 1;
|
|
263
|
+
await commit(store, {
|
|
264
|
+
tabId,
|
|
265
|
+
documentId: 'DOC_A',
|
|
266
|
+
url: 'https://a.test/',
|
|
267
|
+
});
|
|
268
|
+
await commit(store, {
|
|
269
|
+
tabId,
|
|
270
|
+
documentId: 'DOC_B',
|
|
271
|
+
url: 'https://b.test/',
|
|
272
|
+
});
|
|
273
|
+
chrome.webNavigation.getAllFrames.resolves([{ documentId: 'DOC_B' }]);
|
|
274
|
+
chrome.tabs.query.returns([{ id: tabId }]);
|
|
275
|
+
// A enters cached state.
|
|
276
|
+
await store.flush();
|
|
277
|
+
expect(store.findPageForTab(tabId).documentId).to.equal('DOC_A');
|
|
278
|
+
// Bfcache restore re-commits A; marker must clear so a stale
|
|
279
|
+
// sweep can't stage it.
|
|
280
|
+
await commit(store, {
|
|
281
|
+
tabId,
|
|
282
|
+
documentId: 'DOC_A',
|
|
283
|
+
url: 'https://a.test/',
|
|
284
|
+
});
|
|
285
|
+
const restored = store.getPageForRequest({
|
|
286
|
+
tabId,
|
|
287
|
+
frameId: 0,
|
|
288
|
+
documentId: 'DOC_A',
|
|
289
|
+
type: 'script',
|
|
290
|
+
url: 'https://t.test/a.js',
|
|
291
|
+
});
|
|
292
|
+
expect(restored.stageAfter).to.equal(null);
|
|
293
|
+
});
|
|
146
294
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
295
|
+
it('preserves COMPLETE state across bfcache re-commit', async function () {
|
|
296
|
+
const store = new PageStore({ notifyPageStageListeners: () => {} });
|
|
297
|
+
await store.init();
|
|
298
|
+
const tabId = 1;
|
|
299
|
+
// First load fully completes.
|
|
300
|
+
chrome.webNavigation.onCommitted.dispatch({
|
|
301
|
+
tabId,
|
|
302
|
+
frameId: 0,
|
|
303
|
+
documentId: 'DOC_A',
|
|
304
|
+
url: 'https://a.test/',
|
|
150
305
|
});
|
|
151
|
-
|
|
306
|
+
chrome.webNavigation.onCompleted.dispatch({
|
|
307
|
+
tabId,
|
|
308
|
+
frameId: 0,
|
|
309
|
+
documentId: 'DOC_A',
|
|
310
|
+
});
|
|
311
|
+
// Bfcache restore re-commits A without a fresh onCompleted.
|
|
312
|
+
chrome.webNavigation.onCommitted.dispatch({
|
|
313
|
+
tabId,
|
|
314
|
+
frameId: 0,
|
|
315
|
+
documentId: 'DOC_A',
|
|
316
|
+
url: 'https://a.test/',
|
|
317
|
+
});
|
|
318
|
+
// State must stay COMPLETE so the page still emits at staging.
|
|
319
|
+
expect(store.findPageForTab(tabId).state).to.equal('complete');
|
|
152
320
|
});
|
|
153
321
|
});
|
|
154
322
|
});
|