@whotracksme/reporting 5.1.26 → 5.1.28
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 +30 -0
- package/package.json +1 -1
- package/reporting/example/index.js +14 -3
- package/reporting/example/manifests/chromium.json +1 -2
- package/reporting/src/request/index.js +4 -43
- package/reporting/src/request/page-telemetry.js +2 -2
- package/reporting/src/request/steps/page-logger.js +1 -6
- package/reporting/src/request/steps/redirect-tagger.js +0 -24
- package/reporting/src/webrequest-pipeline/page-store.js +220 -150
- package/reporting/src/webrequest-pipeline/webrequest-context.js +1 -33
- package/reporting/test/helpers/scenarios.js +19 -0
- package/reporting/test/request/index.spec.js +2 -9
- package/reporting/test/request-reporter.test.js +18 -14
- package/reporting/test/webrequest-pipeline/index.test.js +28 -15
- package/reporting/test/webrequest-pipeline/page-store.test.js +36 -17
- package/reporting/src/request/dnt.js +0 -24
- package/reporting/src/webrequest-pipeline/page.js +0 -117
|
@@ -9,277 +9,347 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import logger from './logger.js';
|
|
13
|
-
import {
|
|
14
|
-
setActive,
|
|
15
|
-
create as makeTabContext,
|
|
16
|
-
PAGE_LOADING_STATE,
|
|
17
|
-
} from './page.js';
|
|
18
12
|
import ChromeStorageMap from '../request/utils/chrome-storage-map.js';
|
|
19
13
|
|
|
20
14
|
const PAGE_TTL = 1000 * 60 * 60; // 1 hour
|
|
21
15
|
|
|
16
|
+
const PAGE_LOADING_STATE = {
|
|
17
|
+
CREATED: 'created',
|
|
18
|
+
NAVIGATING: 'navigating',
|
|
19
|
+
COMMITTED: 'committed',
|
|
20
|
+
COMPLETE: 'complete',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
class Page {
|
|
24
|
+
constructor(page) {
|
|
25
|
+
this.id = page.id;
|
|
26
|
+
this.url = page.url;
|
|
27
|
+
this.isPrivate = page.incognito || false;
|
|
28
|
+
this.isPrivateServer = page.isPrivateServer || false;
|
|
29
|
+
this.created = page.created || Date.now();
|
|
30
|
+
this.destroyed = page.destroyed || null;
|
|
31
|
+
this.frames = page.frames || {
|
|
32
|
+
0: {
|
|
33
|
+
parentFrameId: -1,
|
|
34
|
+
url: page.url,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
this.state = page.state || PAGE_LOADING_STATE.CREATED;
|
|
38
|
+
|
|
39
|
+
this.activeTime = page.activeTime || 0;
|
|
40
|
+
this.activeFrom = page.active ? Date.now() : 0;
|
|
41
|
+
|
|
42
|
+
this.requestStats = page.requestStats || {};
|
|
43
|
+
this.annotations = page.annotations || {};
|
|
44
|
+
this.counter = page.counter || 0;
|
|
45
|
+
this.previous = page.previous;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
setActive(active) {
|
|
49
|
+
if (active && this.activeFrom === 0) {
|
|
50
|
+
this.activeFrom = Date.now();
|
|
51
|
+
} else if (!active && this.activeFrom > 0) {
|
|
52
|
+
this.activeTime += Date.now() - this.activeFrom;
|
|
53
|
+
this.activeFrom = 0;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getStatsForDomain(domain) {
|
|
58
|
+
return (this.requestStats[domain] ||= {});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
22
62
|
export default class PageStore {
|
|
63
|
+
#notifyPageStageListeners;
|
|
64
|
+
#pages;
|
|
65
|
+
|
|
23
66
|
constructor({ notifyPageStageListeners }) {
|
|
24
|
-
this
|
|
67
|
+
this.#pages = new ChromeStorageMap({
|
|
25
68
|
storageKey: 'wtm-url-reporting:page-store:tabs',
|
|
26
69
|
ttlInMs: PAGE_TTL,
|
|
27
70
|
});
|
|
28
|
-
this
|
|
29
|
-
this.notifyPageStageListeners = notifyPageStageListeners;
|
|
71
|
+
this.#notifyPageStageListeners = notifyPageStageListeners;
|
|
30
72
|
}
|
|
31
73
|
|
|
32
74
|
async init() {
|
|
33
|
-
await this.
|
|
34
|
-
chrome.tabs.onCreated.addListener(this
|
|
35
|
-
chrome.tabs.onUpdated.addListener(this
|
|
36
|
-
chrome.tabs.onRemoved.addListener(this
|
|
37
|
-
chrome.tabs.onActivated.addListener(this
|
|
38
|
-
chrome.webNavigation.onBeforeNavigate.addListener(this
|
|
39
|
-
chrome.webNavigation.onCommitted.addListener(this
|
|
40
|
-
chrome.webNavigation.onCompleted.addListener(this
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
75
|
+
await this.#pages.isReady;
|
|
76
|
+
chrome.tabs.onCreated.addListener(this.#onTabCreated);
|
|
77
|
+
chrome.tabs.onUpdated.addListener(this.#onTabUpdated);
|
|
78
|
+
chrome.tabs.onRemoved.addListener(this.#onTabRemoved);
|
|
79
|
+
chrome.tabs.onActivated.addListener(this.#onTabActivated);
|
|
80
|
+
chrome.webNavigation.onBeforeNavigate.addListener(this.#onBeforeNavigate);
|
|
81
|
+
chrome.webNavigation.onCommitted.addListener(this.#onNavigationCommitted);
|
|
82
|
+
chrome.webNavigation.onCompleted.addListener(this.#onNavigationCompleted);
|
|
83
|
+
chrome.windows.onFocusChanged?.addListener(this.#onWindowFocusChanged);
|
|
84
|
+
|
|
44
85
|
// popupate initially open tabs
|
|
45
|
-
chrome.tabs.query({}
|
|
46
|
-
openTabs.forEach((tab) => {
|
|
47
|
-
this.onTabCreated(tab);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
86
|
+
(await chrome.tabs.query({})).forEach((tab) => this.#onTabCreated(tab));
|
|
50
87
|
}
|
|
51
88
|
|
|
52
89
|
unload() {
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
chrome.tabs.
|
|
60
|
-
chrome.
|
|
61
|
-
chrome.
|
|
62
|
-
chrome.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
90
|
+
this.#pages.forEach((serializedPage) => {
|
|
91
|
+
const page = new Page(serializedPage);
|
|
92
|
+
this.#stagePage(page);
|
|
93
|
+
});
|
|
94
|
+
this.#pages.clear();
|
|
95
|
+
|
|
96
|
+
chrome.tabs.onCreated.removeListener(this.#onTabCreated);
|
|
97
|
+
chrome.tabs.onUpdated.removeListener(this.#onTabUpdated);
|
|
98
|
+
chrome.tabs.onRemoved.removeListener(this.#onTabRemoved);
|
|
99
|
+
chrome.tabs.onActivated.removeListener(this.#onTabActivated);
|
|
100
|
+
chrome.webNavigation.onBeforeNavigate.removeListener(
|
|
101
|
+
this.#onBeforeNavigate,
|
|
102
|
+
);
|
|
103
|
+
chrome.webNavigation.onCommitted.removeListener(
|
|
104
|
+
this.#onNavigationCommitted,
|
|
105
|
+
);
|
|
106
|
+
chrome.webNavigation.onCompleted.removeListener(
|
|
107
|
+
this.#onNavigationCompleted,
|
|
108
|
+
);
|
|
109
|
+
chrome.windows.onFocusChanged?.removeListener(this.#onWindowFocusChanged);
|
|
66
110
|
}
|
|
67
111
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
112
|
+
checkIfEmpty() {
|
|
113
|
+
// this operations can potentially be expensive
|
|
114
|
+
return this.#pages.countNonExpiredKeys() === 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#stagePage(page) {
|
|
118
|
+
page.setActive(false);
|
|
73
119
|
page.destroyed = Date.now();
|
|
74
120
|
// unset previous (to prevent history chain memory leak)
|
|
75
121
|
page.previous = undefined;
|
|
76
|
-
this.
|
|
122
|
+
this.#pages.set(page.id, page);
|
|
123
|
+
this.#notifyPageStageListeners(page);
|
|
77
124
|
}
|
|
78
125
|
|
|
79
126
|
/**
|
|
80
127
|
* Create a new `tabContext` for the new tab
|
|
81
128
|
*/
|
|
82
|
-
onTabCreated = (tab) => {
|
|
83
|
-
this.
|
|
129
|
+
#onTabCreated = (tab) => {
|
|
130
|
+
this.#pages.set(tab.id, new Page(tab));
|
|
84
131
|
};
|
|
85
132
|
|
|
86
133
|
/**
|
|
87
134
|
* Update an existing tab or create it if we do not have a context yet.
|
|
88
135
|
*/
|
|
89
|
-
onTabUpdated = (tabId, info, tab) => {
|
|
90
|
-
|
|
91
|
-
if (!tabContext) {
|
|
92
|
-
tabContext = makeTabContext(tab);
|
|
93
|
-
this.tabs.set(tabId, tabContext);
|
|
94
|
-
}
|
|
136
|
+
#onTabUpdated = (tabId, info, tab) => {
|
|
137
|
+
const page = new Page(this.#pages.get(tabId) || tab);
|
|
95
138
|
|
|
96
139
|
// Update `isPrivate` and `url` if available
|
|
97
|
-
|
|
98
|
-
setActive(
|
|
140
|
+
page.isPrivate = tab.incognito;
|
|
141
|
+
page.setActive(tab.active);
|
|
99
142
|
if (info.url !== undefined) {
|
|
100
|
-
|
|
143
|
+
page.url = info.url;
|
|
101
144
|
}
|
|
145
|
+
|
|
146
|
+
this.#pages.set(tabId, page);
|
|
102
147
|
};
|
|
103
148
|
|
|
104
149
|
/**
|
|
105
150
|
* Remove tab context for `tabId`.
|
|
106
151
|
*/
|
|
107
|
-
onTabRemoved = (tabId) => {
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
|
|
152
|
+
#onTabRemoved = (tabId) => {
|
|
153
|
+
const serializedPage = this.#pages.get(tabId);
|
|
154
|
+
if (!serializedPage) {
|
|
155
|
+
return;
|
|
111
156
|
}
|
|
112
|
-
|
|
157
|
+
const page = new Page(serializedPage);
|
|
158
|
+
if (page.state === PAGE_LOADING_STATE.COMPLETE) {
|
|
159
|
+
this.#stagePage(page);
|
|
160
|
+
}
|
|
161
|
+
this.#pages.delete(tabId);
|
|
113
162
|
};
|
|
114
163
|
|
|
115
|
-
onTabActivated = (
|
|
164
|
+
#onTabActivated = (details) => {
|
|
165
|
+
const { previousTabId, tabId } = details;
|
|
116
166
|
// if previousTabId is not set (e.g. on chrome), set all tabs to inactive
|
|
117
167
|
// otherwise, we only have to mark the previous tab as inactive
|
|
118
168
|
if (!previousTabId) {
|
|
119
|
-
for (const
|
|
120
|
-
|
|
169
|
+
for (const serializedPage of this.#pages.values()) {
|
|
170
|
+
const page = new Page(serializedPage);
|
|
171
|
+
page.setActive(false);
|
|
172
|
+
this.#pages.set(page.id, page);
|
|
121
173
|
}
|
|
122
|
-
} else if (this.
|
|
123
|
-
|
|
174
|
+
} else if (this.#pages.has(previousTabId)) {
|
|
175
|
+
const previousPage = this.#pages.get(previousTabId);
|
|
176
|
+
const page = new Page(previousPage);
|
|
177
|
+
page.setActive(false);
|
|
178
|
+
this.#pages.set(page.id, page);
|
|
124
179
|
}
|
|
125
|
-
|
|
126
|
-
|
|
180
|
+
|
|
181
|
+
if (this.#pages.has(tabId)) {
|
|
182
|
+
const page = new Page(this.#pages.get(tabId));
|
|
183
|
+
page.setActive(true);
|
|
184
|
+
this.#pages.set(page.id, page);
|
|
127
185
|
}
|
|
128
186
|
};
|
|
129
187
|
|
|
130
|
-
onWindowFocusChanged = (
|
|
131
|
-
chrome.tabs.query({ active: true }
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
});
|
|
188
|
+
#onWindowFocusChanged = async (focusedWindowId) => {
|
|
189
|
+
const activeTabs = await chrome.tabs.query({ active: true });
|
|
190
|
+
for (const { id, windowId } of activeTabs) {
|
|
191
|
+
const serializedPage = this.#pages.get(id);
|
|
192
|
+
if (!serializedPage) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const page = new Page(serializedPage);
|
|
196
|
+
page.setActive(windowId === focusedWindowId);
|
|
197
|
+
this.#pages.set(id, page);
|
|
198
|
+
}
|
|
144
199
|
};
|
|
145
200
|
|
|
146
|
-
onBeforeNavigate = (details) => {
|
|
201
|
+
#onBeforeNavigate = (details) => {
|
|
147
202
|
const { frameId, tabId, url, timeStamp } = details;
|
|
148
|
-
|
|
149
|
-
if (frameId
|
|
150
|
-
|
|
203
|
+
|
|
204
|
+
if (frameId !== 0) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const page = this.#pages.has(tabId)
|
|
209
|
+
? new Page(this.#pages.get(tabId))
|
|
210
|
+
: null;
|
|
211
|
+
|
|
212
|
+
if (page) {
|
|
213
|
+
// ignore duplicated #onBeforeNavigate https://bugzilla.mozilla.org/show_bug.cgi?id=1732564
|
|
151
214
|
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
tabContext.created + 200 > timeStamp
|
|
215
|
+
page.id === tabId &&
|
|
216
|
+
page.url === url &&
|
|
217
|
+
page.created + 200 > timeStamp
|
|
156
218
|
) {
|
|
157
219
|
return;
|
|
158
220
|
}
|
|
159
221
|
// We are starting a navigation to a new page - if the previous page is complete (i.e. fully
|
|
160
222
|
// loaded), stage it before we create the new page info.
|
|
161
|
-
if (
|
|
162
|
-
this
|
|
223
|
+
if (page.state === PAGE_LOADING_STATE.COMPLETE) {
|
|
224
|
+
this.#stagePage(page);
|
|
163
225
|
}
|
|
164
|
-
// create a new page for the navigation
|
|
165
|
-
this.tabs.delete(tabId);
|
|
166
|
-
const nextContext = makeTabContext({
|
|
167
|
-
id: tabId,
|
|
168
|
-
active: false,
|
|
169
|
-
url,
|
|
170
|
-
incognito: tabContext ? tabContext.isPrivate : false,
|
|
171
|
-
created: timeStamp,
|
|
172
|
-
});
|
|
173
|
-
nextContext.previous = tabContext;
|
|
174
|
-
this.tabs.set(tabId, nextContext);
|
|
175
|
-
nextContext.state = PAGE_LOADING_STATE.NAVIGATING;
|
|
176
226
|
}
|
|
227
|
+
|
|
228
|
+
// create a new page for the navigation
|
|
229
|
+
this.#pages.delete(tabId);
|
|
230
|
+
|
|
231
|
+
const nextPage = new Page({
|
|
232
|
+
id: tabId,
|
|
233
|
+
active: false,
|
|
234
|
+
url,
|
|
235
|
+
incognito: page ? page.isPrivate : false,
|
|
236
|
+
created: timeStamp,
|
|
237
|
+
});
|
|
238
|
+
nextPage.previous = page;
|
|
239
|
+
nextPage.state = PAGE_LOADING_STATE.NAVIGATING;
|
|
240
|
+
this.#pages.set(tabId, nextPage);
|
|
177
241
|
};
|
|
178
242
|
|
|
179
|
-
onNavigationCommitted = (details) => {
|
|
243
|
+
#onNavigationCommitted = (details) => {
|
|
180
244
|
const { frameId, tabId } = details;
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
245
|
+
const serializedPage = this.#pages.get(tabId);
|
|
246
|
+
|
|
247
|
+
if (!serializedPage) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const page = new Page(serializedPage);
|
|
252
|
+
|
|
253
|
+
if (frameId === 0) {
|
|
254
|
+
page.state = PAGE_LOADING_STATE.COMMITTED;
|
|
255
|
+
this.#pages.set(tabId, page);
|
|
256
|
+
} else if (!page.frames[frameId]) {
|
|
185
257
|
// frame created without request
|
|
186
258
|
this.onSubFrame(details);
|
|
187
259
|
}
|
|
188
260
|
};
|
|
189
261
|
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
262
|
+
#onNavigationCompleted = (details) => {
|
|
263
|
+
const { frameId, tabId } = details;
|
|
264
|
+
const serializedPage = this.#pages.get(tabId);
|
|
265
|
+
if (!serializedPage) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const page = new Page(serializedPage);
|
|
269
|
+
if (frameId === 0) {
|
|
270
|
+
page.state = PAGE_LOADING_STATE.COMPLETE;
|
|
194
271
|
}
|
|
272
|
+
this.#pages.set(tabId, page);
|
|
195
273
|
};
|
|
196
274
|
|
|
197
|
-
onMainFrame = (
|
|
275
|
+
onMainFrame = (details, event) => {
|
|
276
|
+
const { tabId, url } = details;
|
|
198
277
|
// main frame from tabId -1 is from service worker and should not be saved
|
|
199
278
|
if (tabId === -1) {
|
|
200
279
|
return;
|
|
201
280
|
}
|
|
281
|
+
|
|
202
282
|
// Update last request id from the tab
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
this.tabs.set(tabId, tabContext);
|
|
207
|
-
}
|
|
283
|
+
const page = new Page(
|
|
284
|
+
this.#pages.get(tabId) || { url, incognito: false, id: tabId },
|
|
285
|
+
);
|
|
208
286
|
|
|
209
287
|
if (event === 'onBeforeRequest') {
|
|
210
|
-
|
|
211
|
-
// Detect redirect: if the last request on this tab had the same id and
|
|
212
|
-
// this was from the same `onBeforeRequest` hook, we can assume this is a
|
|
213
|
-
// redirection.
|
|
214
|
-
if (tabContext.lastRequestId === requestId) {
|
|
215
|
-
tabContext.isRedirect = true;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Only keep track of `lastRequestId` with `onBeforeRequest` listener
|
|
219
|
-
// since we need this information for redirect detection only and this can
|
|
220
|
-
// be detected with this hook.
|
|
221
|
-
tabContext.lastRequestId = requestId;
|
|
288
|
+
page.frames = {};
|
|
222
289
|
}
|
|
223
290
|
|
|
224
291
|
// Update context of tab with `url` and main frame information
|
|
225
|
-
|
|
226
|
-
|
|
292
|
+
page.url = url;
|
|
293
|
+
page.frames[0] = {
|
|
227
294
|
parentFrameId: -1,
|
|
228
295
|
url,
|
|
229
296
|
};
|
|
297
|
+
|
|
298
|
+
this.#pages.set(tabId, page);
|
|
230
299
|
};
|
|
231
300
|
|
|
232
301
|
onSubFrame = (details) => {
|
|
233
302
|
const { tabId, frameId, parentFrameId, url } = details;
|
|
234
|
-
const
|
|
235
|
-
if (!
|
|
236
|
-
logger.log('Could not find tab for sub_frame request', details);
|
|
303
|
+
const serializedPage = this.#pages.get(tabId);
|
|
304
|
+
if (!serializedPage) {
|
|
237
305
|
return;
|
|
238
306
|
}
|
|
239
|
-
|
|
307
|
+
const page = new Page(serializedPage);
|
|
240
308
|
// Keep track of frameUrl as well as parent frame
|
|
241
|
-
|
|
309
|
+
page.frames[frameId] = {
|
|
242
310
|
parentFrameId,
|
|
243
311
|
url,
|
|
244
312
|
};
|
|
313
|
+
this.#pages.set(tabId, page);
|
|
245
314
|
};
|
|
246
315
|
|
|
247
316
|
getPageForRequest(context) {
|
|
248
317
|
const { tabId, frameId, originUrl, type, initiator } = context;
|
|
249
|
-
const
|
|
250
|
-
if (!
|
|
318
|
+
const serializedPage = this.#pages.get(tabId);
|
|
319
|
+
if (!serializedPage) {
|
|
251
320
|
return null;
|
|
252
321
|
}
|
|
322
|
+
const page = new Page(serializedPage);
|
|
253
323
|
// check if the current page has the given frame id, otherwise check if it belongs to the
|
|
254
324
|
// previous page
|
|
255
|
-
if (!
|
|
256
|
-
if (
|
|
257
|
-
return
|
|
325
|
+
if (!page.frames[frameId]) {
|
|
326
|
+
if (page.previous && page.previous.frames[frameId]) {
|
|
327
|
+
return page.previous;
|
|
258
328
|
}
|
|
259
329
|
return null;
|
|
260
330
|
}
|
|
261
331
|
|
|
262
332
|
const couldBePreviousPage =
|
|
263
|
-
frameId === 0 && type !== 'main_frame' &&
|
|
333
|
+
frameId === 0 && type !== 'main_frame' && page.previous;
|
|
264
334
|
|
|
265
335
|
// for main frame requests: check if the origin url is from the previous page (Firefox)
|
|
266
336
|
if (
|
|
267
337
|
couldBePreviousPage &&
|
|
268
|
-
|
|
269
|
-
|
|
338
|
+
page.url !== originUrl &&
|
|
339
|
+
page.previous.url === originUrl
|
|
270
340
|
) {
|
|
271
|
-
return
|
|
341
|
+
return page.previous;
|
|
272
342
|
}
|
|
273
343
|
// on Chrome we have `initiator` which only contains the origin. In this case, check for a
|
|
274
344
|
// different origin
|
|
275
345
|
if (
|
|
276
346
|
couldBePreviousPage &&
|
|
277
347
|
initiator &&
|
|
278
|
-
!
|
|
279
|
-
|
|
348
|
+
!page.url.startsWith(initiator) &&
|
|
349
|
+
page.previous.url.startsWith(initiator)
|
|
280
350
|
) {
|
|
281
|
-
return
|
|
351
|
+
return page.previous;
|
|
282
352
|
}
|
|
283
|
-
return
|
|
353
|
+
return page;
|
|
284
354
|
}
|
|
285
355
|
}
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
import { parse } from '../utils/url.js';
|
|
13
13
|
import logger from './logger.js';
|
|
14
|
-
import { getFrameUrl, getFrameAncestors } from './page.js';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Transform an array of headers (i.e.: `{ name, value }`) into a `Map`.
|
|
@@ -59,38 +58,17 @@ export default class WebRequestContext {
|
|
|
59
58
|
// Get context on this page
|
|
60
59
|
const page = pageStore.getPageForRequest(context);
|
|
61
60
|
|
|
62
|
-
//
|
|
63
|
-
// frameAncestors
|
|
64
|
-
if (context.frameAncestors === undefined) {
|
|
65
|
-
context.frameAncestors = page ? getFrameAncestors(page, context) : [];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Cliqz-specific extensions to webRequest details
|
|
61
|
+
// Ghostery-specific extensions to webRequest details
|
|
69
62
|
context.page = page;
|
|
70
63
|
context.tabUrl = context.tabUrl || (page && page.url);
|
|
71
|
-
context.frameUrl = context.frameUrl || (page && getFrameUrl(page, context));
|
|
72
64
|
context.isPrivate = page ? page.isPrivate : null;
|
|
73
65
|
context.isMainFrame = context.type === 'main_frame';
|
|
74
|
-
context.isRedirect = page && context.isMainFrame && page.isRedirect;
|
|
75
66
|
|
|
76
67
|
if (!context.tabUrl) {
|
|
77
68
|
context.tabUrl =
|
|
78
69
|
context.originUrl || context.initiator || context.documentUrl;
|
|
79
70
|
}
|
|
80
71
|
|
|
81
|
-
if (!context.frameUrl) {
|
|
82
|
-
context.frameUrl =
|
|
83
|
-
context.documentUrl || context.originUrl || context.initiator;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (!context.originUrl) {
|
|
87
|
-
context.originUrl =
|
|
88
|
-
context.initiator ||
|
|
89
|
-
context.documentUrl ||
|
|
90
|
-
context.frameUrl ||
|
|
91
|
-
context.tabUrl;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
72
|
return new WebRequestContext(context);
|
|
95
73
|
}
|
|
96
74
|
|
|
@@ -98,15 +76,11 @@ export default class WebRequestContext {
|
|
|
98
76
|
Object.assign(this, details);
|
|
99
77
|
|
|
100
78
|
// Lazy attributes
|
|
101
|
-
this._frameUrlParts = null;
|
|
102
|
-
|
|
103
79
|
this._requestHeadersMap = null;
|
|
104
80
|
this._responseHeadersMap = null;
|
|
105
81
|
|
|
106
82
|
this.urlParts = parse(this.url);
|
|
107
|
-
this.frameUrlParts = parse(this.frameUrl);
|
|
108
83
|
this.tabUrlParts = parse(this.tabUrl);
|
|
109
|
-
this.originUrlParts = parse(this.originUrl);
|
|
110
84
|
}
|
|
111
85
|
|
|
112
86
|
/**
|
|
@@ -145,10 +119,4 @@ export default class WebRequestContext {
|
|
|
145
119
|
getReferrer() {
|
|
146
120
|
return this.getRequestHeader('Referer');
|
|
147
121
|
}
|
|
148
|
-
|
|
149
|
-
isBackgroundRequest() {
|
|
150
|
-
return (
|
|
151
|
-
this.tabId === -1 && this.originUrlParts?.protocol.endsWith('extension:')
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
122
|
}
|
|
@@ -72,14 +72,33 @@ export async function playScenario(
|
|
|
72
72
|
throw new Error('specify scenario release');
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
const seenTabIds = new Set();
|
|
75
76
|
const scenarioPath = await download(scenarioRelease, scenarioName, browser);
|
|
76
77
|
const events = loadScenario(scenarioPath);
|
|
77
78
|
for (const event of events) {
|
|
78
79
|
try {
|
|
79
80
|
const args = event.args.map(rewriteIp);
|
|
81
|
+
|
|
82
|
+
if (events.api === 'tabs' && event.event === 'onCreated') {
|
|
83
|
+
seenTabIds.add(args[0].id);
|
|
84
|
+
} else {
|
|
85
|
+
if (Object.prototype.hasOwnProperty.call(args[0], 'tabId')) {
|
|
86
|
+
seenTabIds.add(args[0].tabId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (
|
|
90
|
+
Object.prototype.hasOwnProperty.call(args[0], 'successorTabId') &&
|
|
91
|
+
args[0].successorTabId !== -1
|
|
92
|
+
) {
|
|
93
|
+
seenTabIds.add(args[0].successorTabId);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
80
97
|
chrome[event.api][event.event].dispatch(...args);
|
|
81
98
|
} catch (e) {
|
|
82
99
|
console.error(`Could not dispatch event`, event, e);
|
|
83
100
|
}
|
|
84
101
|
}
|
|
102
|
+
|
|
103
|
+
return { seenTabIds };
|
|
85
104
|
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import * as chai from 'chai';
|
|
13
13
|
import sinon from 'sinon';
|
|
14
|
+
|
|
14
15
|
// import FakeSessionApi from '../helpers/fake-session-storage.js'; // TODO: see comments below
|
|
15
16
|
|
|
16
17
|
import testPages from './test-pages.js';
|
|
@@ -82,7 +83,6 @@ describe('request/index', function () {
|
|
|
82
83
|
afterEach(() => {
|
|
83
84
|
pipeline?.unload();
|
|
84
85
|
pipeline = null;
|
|
85
|
-
|
|
86
86
|
if (monkeyPatchedChromeStorage) {
|
|
87
87
|
chrome.storage.session = oldChromeStorageSession;
|
|
88
88
|
chrome.storage = oldChromeStorage;
|
|
@@ -139,9 +139,7 @@ describe('request/index', function () {
|
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
function simulatePageLoad(pageSpec) {
|
|
142
|
-
|
|
143
|
-
...pageSpec.tab,
|
|
144
|
-
});
|
|
142
|
+
chrome.tabs.onCreated.dispatch(pageSpec.tab);
|
|
145
143
|
return {
|
|
146
144
|
onBeforeRequest: pageSpec.onBeforeRequest.map(function (reqData) {
|
|
147
145
|
const response = pipeline.onBeforeRequest(reqData);
|
|
@@ -296,7 +294,6 @@ describe('request/index', function () {
|
|
|
296
294
|
type: 'main_frame',
|
|
297
295
|
url: 'http://cliqztest.com/',
|
|
298
296
|
requestHeaders: mockRequestHeaders,
|
|
299
|
-
frameAncestors: [],
|
|
300
297
|
});
|
|
301
298
|
chai.expect(mainDoc).to.not.have.property('cancel');
|
|
302
299
|
chai.expect(mainDoc).to.not.have.property('redirectUrl');
|
|
@@ -313,7 +310,6 @@ describe('request/index', function () {
|
|
|
313
310
|
requestHeaders: mockRequestHeaders,
|
|
314
311
|
initiator: 'http://cliqztest.com',
|
|
315
312
|
isPrivate: false,
|
|
316
|
-
frameAncestors: [],
|
|
317
313
|
});
|
|
318
314
|
chai.expect(response).to.have.property('redirectUrl');
|
|
319
315
|
chai.expect(response.redirectUrl).to.not.contain(uid);
|
|
@@ -331,7 +327,6 @@ describe('request/index', function () {
|
|
|
331
327
|
requestHeaders: mockRequestHeaders,
|
|
332
328
|
originUrl: '',
|
|
333
329
|
tabUrl: '',
|
|
334
|
-
frameAncestors: [],
|
|
335
330
|
});
|
|
336
331
|
chai.expect(mainDoc).to.not.have.property('cancel');
|
|
337
332
|
chai.expect(mainDoc).to.not.have.property('redirectUrl');
|
|
@@ -349,7 +344,6 @@ describe('request/index', function () {
|
|
|
349
344
|
originUrl: 'http://cliqztest.com',
|
|
350
345
|
tabUrl: 'http://cliqztest.com',
|
|
351
346
|
isPrivate: false,
|
|
352
|
-
frameAncestors: [],
|
|
353
347
|
});
|
|
354
348
|
chai.expect(response).to.have.property('redirectUrl');
|
|
355
349
|
chai.expect(response.redirectUrl).to.not.contain(uid);
|
|
@@ -368,7 +362,6 @@ describe('request/index', function () {
|
|
|
368
362
|
originUrl: 'http://cliqztest.com',
|
|
369
363
|
tabUrl: 'http://cliqztest.com',
|
|
370
364
|
isPrivate: false,
|
|
371
|
-
frameAncestors: [],
|
|
372
365
|
});
|
|
373
366
|
chai.expect(response).to.have.property('redirectUrl');
|
|
374
367
|
chai.expect(response.redirectUrl).to.not.contain(uid);
|