@whotracksme/reporting 5.1.24 → 5.1.26
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/.github/workflows/release.yml +2 -2
- package/.github/workflows/tests.yml +4 -5
- package/.tool-versions +1 -1
- package/CHANGELOG.md +32 -0
- package/package.json +3 -2
- package/reporting/karma.conf.cjs +2 -0
- package/reporting/package.json +4 -1
- package/reporting/src/bloom-filters.js +4 -4
- package/reporting/src/fixed-size-cache.js +1 -1
- package/reporting/src/logger.js +0 -1
- package/reporting/src/md5.js +1 -1
- package/reporting/src/network.js +1 -1
- package/reporting/src/pages.js +84 -21
- package/reporting/src/persisted-bitarray.js +2 -2
- package/reporting/src/request/config.js +2 -2
- package/reporting/src/request/hash.js +2 -2
- package/reporting/src/request/index.js +30 -29
- package/reporting/src/request/page-telemetry.js +2 -2
- package/reporting/src/request/qs-whitelist2.js +3 -3
- package/reporting/src/request/steps/cookie-context.js +6 -6
- package/reporting/src/request/steps/oauth-detector.js +3 -3
- package/reporting/src/request/steps/page-logger.js +5 -2
- package/reporting/src/request/steps/redirect-tagger.js +1 -1
- package/reporting/src/request/steps/token-checker/index.js +3 -3
- package/reporting/src/request/steps/token-checker/token-domain.js +3 -3
- package/reporting/src/request/steps/token-examiner.js +5 -5
- package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +3 -3
- package/reporting/src/request/steps/token-telemetry/index.js +4 -4
- package/reporting/src/request/steps/token-telemetry/key-pipeline.js +1 -1
- package/reporting/src/request/steps/token-telemetry/token-pipeline.js +1 -1
- package/reporting/src/request/utils/bloom-filter-packed.js +1 -1
- package/reporting/src/request/utils/chrome-storage-map.js +13 -1
- package/reporting/src/request/utils/subject.js +1 -1
- package/reporting/src/request/utils/temp-set.js +1 -1
- package/reporting/src/request-reporter.js +3 -3
- package/reporting/src/sanitizer.js +11 -3
- package/reporting/src/utils/pacemaker.js +1 -1
- package/reporting/src/utils/url.js +0 -29
- package/reporting/src/webrequest-pipeline/cname-uncloak.js +2 -2
- package/reporting/src/webrequest-pipeline/index.js +10 -11
- package/reporting/src/webrequest-pipeline/logger.js +1 -1
- package/reporting/src/webrequest-pipeline/page-store.js +23 -20
- package/reporting/src/webrequest-pipeline/page.js +81 -104
- package/reporting/src/webrequest-pipeline/pipeline.js +1 -1
- package/reporting/src/webrequest-pipeline/utils/webrequest.js +63 -57
- package/reporting/src/webrequest-pipeline/webrequest-context.js +6 -5
- package/reporting/test/helpers/fetch-mock.js +2 -2
- package/reporting/test/helpers/scenarios.js +85 -0
- package/reporting/test/pages.spec.js +52 -4
- package/reporting/test/request-reporter.test.js +251 -0
- package/reporting/test/sanitizer.spec.js +16 -0
- package/reporting/test/setup.unit.js +17 -0
- package/reporting/test/utils/url.spec.js +1 -26
- package/reporting/test/webrequest-pipeline/index.test.js +147 -0
- package/reporting/test/webrequest-pipeline/page-store.test.js +135 -0
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import CachedEntryPipeline from './cached-entry-pipeline';
|
|
12
|
+
import CachedEntryPipeline from './cached-entry-pipeline.js';
|
|
13
13
|
|
|
14
14
|
export function getSiteTokensMap(siteTokens, key) {
|
|
15
15
|
let siteTokensMap = siteTokens[key];
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import CachedEntryPipeline from './cached-entry-pipeline';
|
|
12
|
+
import CachedEntryPipeline from './cached-entry-pipeline.js';
|
|
13
13
|
|
|
14
14
|
export default class TokenPipeline extends CachedEntryPipeline {
|
|
15
15
|
constructor({ db, trustedClock, options, name }) {
|
|
@@ -88,6 +88,12 @@ export default class ChromeStorageMap {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
countNonExpiredKeys() {
|
|
92
|
+
this._warnIfOutOfSync();
|
|
93
|
+
this._expireOldEntries();
|
|
94
|
+
return this._inMemoryMap.size;
|
|
95
|
+
}
|
|
96
|
+
|
|
91
97
|
get(_key) {
|
|
92
98
|
this._warnIfOutOfSync();
|
|
93
99
|
const key = this.normalizeKey(_key);
|
|
@@ -103,10 +109,16 @@ export default class ChromeStorageMap {
|
|
|
103
109
|
return this._inMemoryMap.entries();
|
|
104
110
|
}
|
|
105
111
|
|
|
112
|
+
keys() {
|
|
113
|
+
this._warnIfOutOfSync();
|
|
114
|
+
this._expireOldEntries();
|
|
115
|
+
return this._inMemoryMap.keys();
|
|
116
|
+
}
|
|
117
|
+
|
|
106
118
|
values() {
|
|
107
119
|
this._warnIfOutOfSync();
|
|
108
120
|
this._expireOldEntries();
|
|
109
|
-
return
|
|
121
|
+
return this._inMemoryMap.values();
|
|
110
122
|
}
|
|
111
123
|
|
|
112
124
|
has(_key) {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/* eslint func-names: 'off' */
|
|
13
13
|
/* eslint prefer-arrow-callback: 'off' */
|
|
14
14
|
|
|
15
|
-
import pacemaker from '../../utils/pacemaker';
|
|
15
|
+
import pacemaker from '../../utils/pacemaker.js';
|
|
16
16
|
|
|
17
17
|
/** Set like class whose members are removed after a specific amount of time
|
|
18
18
|
*/
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import RequestMonitor from './request/index';
|
|
13
|
-
import Config from './request/config';
|
|
14
|
-
import Database from './request/database';
|
|
12
|
+
import RequestMonitor from './request/index.js';
|
|
13
|
+
import Config from './request/config.js';
|
|
14
|
+
import Database from './request/database.js';
|
|
15
15
|
|
|
16
16
|
export default class RequestReporter {
|
|
17
17
|
constructor(
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
import logger from './logger';
|
|
13
13
|
import { isHash } from './hash-detector';
|
|
14
|
-
//import { isHash } from './hash-detector-new';
|
|
15
14
|
|
|
16
15
|
function isCharNumber(char) {
|
|
17
16
|
const code = char.charCodeAt(0);
|
|
@@ -221,11 +220,17 @@ function tryParseUrl(url) {
|
|
|
221
220
|
}
|
|
222
221
|
}
|
|
223
222
|
|
|
224
|
-
function
|
|
223
|
+
function isPrivateHostname(hostname) {
|
|
225
224
|
// TODO: this could be extended to detect more cases
|
|
226
225
|
return hostname === 'localhost' || hostname === '127.0.0.1';
|
|
227
226
|
}
|
|
228
227
|
|
|
228
|
+
// Note: This is a conservative implementation that detects all valid IPv4 addresses.
|
|
229
|
+
// It may produce false-positives, so consider this if using for other purposes.
|
|
230
|
+
function looksLikeIPv4Address(hostname) {
|
|
231
|
+
return /^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}$/.test(hostname);
|
|
232
|
+
}
|
|
233
|
+
|
|
229
234
|
function looksLikeSafeUrlParameter(key, value) {
|
|
230
235
|
return value.length < 18 || /^[a-z-_]+$/.test(value);
|
|
231
236
|
}
|
|
@@ -346,9 +351,12 @@ export function sanitizeUrl(url, options = {}) {
|
|
|
346
351
|
if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
|
|
347
352
|
return drop('URL has uncommon protocol');
|
|
348
353
|
}
|
|
349
|
-
if (
|
|
354
|
+
if (isPrivateHostname(parsedUrl.hostname)) {
|
|
350
355
|
return drop('URL is not public');
|
|
351
356
|
}
|
|
357
|
+
if (looksLikeIPv4Address(parsedUrl.hostname)) {
|
|
358
|
+
return drop('hostname is an ipv4 address');
|
|
359
|
+
}
|
|
352
360
|
if (urlLeaksExtensionId(url)) {
|
|
353
361
|
return drop('URL leaks extension ID');
|
|
354
362
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { Logger } from '../logger';
|
|
12
|
+
import { Logger } from '../logger.js';
|
|
13
13
|
|
|
14
14
|
// Pacemaker is a service which allows to schedule tasks (either as intervals or
|
|
15
15
|
// timeouts) while doing its best to not wake-up the browser too often. To this
|
|
@@ -68,35 +68,6 @@ function tryDecode(fn) {
|
|
|
68
68
|
|
|
69
69
|
export const tryDecodeURIComponent = tryDecode(decodeURIComponent);
|
|
70
70
|
|
|
71
|
-
export function isPrivateIP(ip) {
|
|
72
|
-
// Need to check for ipv6.
|
|
73
|
-
if (ip.indexOf(':') !== -1) {
|
|
74
|
-
// ipv6
|
|
75
|
-
if (ip === '::1') {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
const ipParts = ip.split(':');
|
|
79
|
-
return (
|
|
80
|
-
ipParts[0].startsWith('fd') ||
|
|
81
|
-
ipParts.every((d, i) => {
|
|
82
|
-
if (i === ipParts.length - 1) {
|
|
83
|
-
// last group of address
|
|
84
|
-
return d === '1';
|
|
85
|
-
}
|
|
86
|
-
return d === '0' || !d;
|
|
87
|
-
})
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
const ipParts = ip.split('.').map((d) => parseInt(d, 10));
|
|
91
|
-
return (
|
|
92
|
-
ipParts[0] === 10 ||
|
|
93
|
-
(ipParts[0] === 192 && ipParts[1] === 168) ||
|
|
94
|
-
(ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] < 32) ||
|
|
95
|
-
ipParts[0] === 127 ||
|
|
96
|
-
ipParts[0] === 0
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
71
|
export function getName(url) {
|
|
101
72
|
if (url === null) {
|
|
102
73
|
return null;
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import logger from './logger';
|
|
13
|
-
import ChromeStorageMap from '../request/utils/chrome-storage-map';
|
|
12
|
+
import logger from './logger.js';
|
|
13
|
+
import ChromeStorageMap from '../request/utils/chrome-storage-map.js';
|
|
14
14
|
|
|
15
15
|
function checkUserAgent(pattern) {
|
|
16
16
|
return navigator.userAgent.indexOf(pattern) !== -1;
|
|
@@ -11,15 +11,14 @@
|
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
VALID_RESPONSE_PROPERTIES,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from './utils/webrequest';
|
|
14
|
+
default as WebRequestListenersManager,
|
|
15
|
+
} from './utils/webrequest.js';
|
|
17
16
|
|
|
18
|
-
import Pipeline from './pipeline';
|
|
19
|
-
import WebRequestContext from './webrequest-context';
|
|
20
|
-
import PageStore from './page-store';
|
|
21
|
-
import logger from './logger';
|
|
22
|
-
import CnameUncloaker, { isCnameUncloakSupported } from './cname-uncloak';
|
|
17
|
+
import Pipeline from './pipeline.js';
|
|
18
|
+
import WebRequestContext from './webrequest-context.js';
|
|
19
|
+
import PageStore from './page-store.js';
|
|
20
|
+
import logger from './logger.js';
|
|
21
|
+
import CnameUncloaker, { isCnameUncloakSupported } from './cname-uncloak.js';
|
|
23
22
|
|
|
24
23
|
function modifyHeaderByType(headers, name, value) {
|
|
25
24
|
const lowerCaseName = name.toLowerCase();
|
|
@@ -94,6 +93,7 @@ export default class WebRequestPipeline {
|
|
|
94
93
|
constructor() {
|
|
95
94
|
this.initialized = false;
|
|
96
95
|
this.onPageStagedListeners = new Set();
|
|
96
|
+
this.listenerManager = new WebRequestListenersManager();
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
enabled() {
|
|
@@ -158,7 +158,7 @@ export default class WebRequestPipeline {
|
|
|
158
158
|
if (this.pipelines.has(event)) {
|
|
159
159
|
const pipeline = this.pipelines.get(event);
|
|
160
160
|
this[event] = undefined;
|
|
161
|
-
removeListener(event, pipeline.listener);
|
|
161
|
+
this.listenerManager.removeListener(event, pipeline.listener);
|
|
162
162
|
pipeline.pipeline.unload();
|
|
163
163
|
this.pipelines.delete(event);
|
|
164
164
|
}
|
|
@@ -168,7 +168,6 @@ export default class WebRequestPipeline {
|
|
|
168
168
|
if (this.pipelines.has(event)) {
|
|
169
169
|
return this.pipelines.get(event).pipeline;
|
|
170
170
|
}
|
|
171
|
-
|
|
172
171
|
// Create pipeline step
|
|
173
172
|
const pipeline = new Pipeline(`webRequestPipeline.${event}`, [], false);
|
|
174
173
|
|
|
@@ -246,7 +245,7 @@ export default class WebRequestPipeline {
|
|
|
246
245
|
// can call it: `webRequestPipeline.background.onBeforeRequest(details)`.
|
|
247
246
|
this[event] = listener;
|
|
248
247
|
|
|
249
|
-
addListener(event, listener);
|
|
248
|
+
this.listenerManager.addListener(event, listener);
|
|
250
249
|
|
|
251
250
|
return pipeline;
|
|
252
251
|
}
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import logger from './logger';
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
import logger from './logger.js';
|
|
13
|
+
import {
|
|
14
|
+
setActive,
|
|
15
|
+
create as makeTabContext,
|
|
16
|
+
PAGE_LOADING_STATE,
|
|
17
|
+
} from './page.js';
|
|
18
|
+
import ChromeStorageMap from '../request/utils/chrome-storage-map.js';
|
|
19
19
|
|
|
20
20
|
const PAGE_TTL = 1000 * 60 * 60; // 1 hour
|
|
21
21
|
|
|
@@ -69,7 +69,10 @@ export default class PageStore {
|
|
|
69
69
|
if (this.staged.push(page) > 5) {
|
|
70
70
|
this.staged.shift();
|
|
71
71
|
}
|
|
72
|
-
page
|
|
72
|
+
setActive(page, false);
|
|
73
|
+
page.destroyed = Date.now();
|
|
74
|
+
// unset previous (to prevent history chain memory leak)
|
|
75
|
+
page.previous = undefined;
|
|
73
76
|
this.notifyPageStageListeners(page);
|
|
74
77
|
}
|
|
75
78
|
|
|
@@ -85,14 +88,14 @@ export default class PageStore {
|
|
|
85
88
|
*/
|
|
86
89
|
onTabUpdated = (tabId, info, tab) => {
|
|
87
90
|
let tabContext = this.tabs.get(tabId);
|
|
88
|
-
if (tabContext
|
|
91
|
+
if (!tabContext) {
|
|
89
92
|
tabContext = makeTabContext(tab);
|
|
90
93
|
this.tabs.set(tabId, tabContext);
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
// Update `isPrivate` and `url` if available
|
|
94
97
|
tabContext.isPrivate = tab.incognito;
|
|
95
|
-
|
|
98
|
+
setActive(tabContext, tab.active);
|
|
96
99
|
if (info.url !== undefined) {
|
|
97
100
|
tabContext.url = info.url;
|
|
98
101
|
}
|
|
@@ -114,13 +117,13 @@ export default class PageStore {
|
|
|
114
117
|
// otherwise, we only have to mark the previous tab as inactive
|
|
115
118
|
if (!previousTabId) {
|
|
116
119
|
for (const tab of this.tabs.values()) {
|
|
117
|
-
|
|
120
|
+
setActive(tab, false);
|
|
118
121
|
}
|
|
119
122
|
} else if (this.tabs.has(previousTabId)) {
|
|
120
|
-
this.tabs.get(previousTabId)
|
|
123
|
+
setActive(this.tabs.get(previousTabId), false);
|
|
121
124
|
}
|
|
122
125
|
if (this.tabs.has(tabId)) {
|
|
123
|
-
this.tabs.get(tabId)
|
|
126
|
+
setActive(this.tabs.get(tabId), true);
|
|
124
127
|
}
|
|
125
128
|
};
|
|
126
129
|
|
|
@@ -132,9 +135,9 @@ export default class PageStore {
|
|
|
132
135
|
return;
|
|
133
136
|
}
|
|
134
137
|
if (windowId === focusedWindow) {
|
|
135
|
-
|
|
138
|
+
setActive(tabContext, true);
|
|
136
139
|
} else {
|
|
137
|
-
|
|
140
|
+
setActive(tabContext, false);
|
|
138
141
|
}
|
|
139
142
|
});
|
|
140
143
|
});
|
|
@@ -169,7 +172,7 @@ export default class PageStore {
|
|
|
169
172
|
});
|
|
170
173
|
nextContext.previous = tabContext;
|
|
171
174
|
this.tabs.set(tabId, nextContext);
|
|
172
|
-
nextContext.
|
|
175
|
+
nextContext.state = PAGE_LOADING_STATE.NAVIGATING;
|
|
173
176
|
}
|
|
174
177
|
};
|
|
175
178
|
|
|
@@ -177,7 +180,7 @@ export default class PageStore {
|
|
|
177
180
|
const { frameId, tabId } = details;
|
|
178
181
|
const tabContext = this.tabs.get(tabId);
|
|
179
182
|
if (frameId === 0 && tabContext) {
|
|
180
|
-
tabContext.
|
|
183
|
+
tabContext.state = PAGE_LOADING_STATE.COMMITTED;
|
|
181
184
|
} else if (tabContext && !tabContext.frames[frameId]) {
|
|
182
185
|
// frame created without request
|
|
183
186
|
this.onSubFrame(details);
|
|
@@ -187,7 +190,7 @@ export default class PageStore {
|
|
|
187
190
|
onNavigationComplete = ({ frameId, tabId }) => {
|
|
188
191
|
const tabContext = this.tabs.get(tabId);
|
|
189
192
|
if (frameId === 0 && tabContext) {
|
|
190
|
-
tabContext.
|
|
193
|
+
tabContext.state = PAGE_LOADING_STATE.COMPLETE;
|
|
191
194
|
}
|
|
192
195
|
};
|
|
193
196
|
|
|
@@ -198,7 +201,7 @@ export default class PageStore {
|
|
|
198
201
|
}
|
|
199
202
|
// Update last request id from the tab
|
|
200
203
|
let tabContext = this.tabs.get(tabId);
|
|
201
|
-
if (tabContext
|
|
204
|
+
if (!tabContext) {
|
|
202
205
|
tabContext = makeTabContext({ url, incognito: false });
|
|
203
206
|
this.tabs.set(tabId, tabContext);
|
|
204
207
|
}
|
|
@@ -229,7 +232,7 @@ export default class PageStore {
|
|
|
229
232
|
onSubFrame = (details) => {
|
|
230
233
|
const { tabId, frameId, parentFrameId, url } = details;
|
|
231
234
|
const tab = this.tabs.get(tabId);
|
|
232
|
-
if (tab
|
|
235
|
+
if (!tab) {
|
|
233
236
|
logger.log('Could not find tab for sub_frame request', details);
|
|
234
237
|
return;
|
|
235
238
|
}
|
|
@@ -16,125 +16,102 @@ export const PAGE_LOADING_STATE = {
|
|
|
16
16
|
COMPLETE: 'complete',
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
}
|
|
19
|
+
export function create({ id, active, url, incognito, created }) {
|
|
20
|
+
const page = {};
|
|
21
|
+
page.id = id || 0;
|
|
22
|
+
page.url = url;
|
|
23
|
+
page.isRedirect = false;
|
|
24
|
+
page.isPrivate = incognito;
|
|
25
|
+
page.isPrivateServer = false;
|
|
26
|
+
page.created = created || Date.now();
|
|
27
|
+
page.destroyed = null;
|
|
28
|
+
page.lastRequestId = null;
|
|
29
|
+
page.frames = {
|
|
30
|
+
0: {
|
|
31
|
+
parentFrameId: -1,
|
|
32
|
+
url,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
page.state = PAGE_LOADING_STATE.CREATED;
|
|
36
|
+
|
|
37
|
+
page.activeTime = 0;
|
|
38
|
+
page.activeFrom = active ? Date.now() : 0;
|
|
39
|
+
|
|
40
|
+
page.requestStats = {};
|
|
41
|
+
page.annotations = {};
|
|
42
|
+
page.counter = 0;
|
|
43
|
+
|
|
44
|
+
page.tsv = '';
|
|
45
|
+
page.tsvId = undefined;
|
|
46
|
+
return page;
|
|
47
|
+
}
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
export function setActive(page, active) {
|
|
50
|
+
if (active && page.activeFrom === 0) {
|
|
51
|
+
page.activeFrom = Date.now();
|
|
52
|
+
} else if (!active && page.activeFrom > 0) {
|
|
53
|
+
page.activeTime += Date.now() - page.activeFrom;
|
|
54
|
+
page.activeFrom = 0;
|
|
59
55
|
}
|
|
56
|
+
}
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
export function getStatsForDomain(page, domain) {
|
|
59
|
+
let stats = page.requestStats[domain];
|
|
60
|
+
if (!stats) {
|
|
61
|
+
stats = {};
|
|
62
|
+
page.requestStats[domain] = stats;
|
|
66
63
|
}
|
|
64
|
+
return stats;
|
|
65
|
+
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!stats) {
|
|
71
|
-
stats = {};
|
|
72
|
-
this.requestStats[domain] = stats;
|
|
73
|
-
}
|
|
74
|
-
return stats;
|
|
75
|
-
}
|
|
67
|
+
export function getFrameAncestors(page, { parentFrameId }) {
|
|
68
|
+
const ancestors = [];
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
// Reconstruct frame ancestors
|
|
71
|
+
let currentFrameId = parentFrameId;
|
|
72
|
+
while (currentFrameId !== -1) {
|
|
73
|
+
const frame = page.frames[currentFrameId];
|
|
81
74
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// If `frame` if undefined, this means we do not have any information
|
|
91
|
-
// about the frame associated with `currentFrameId`. This can happen if
|
|
92
|
-
// the event for `main_frame` or `sub_frame` was not emitted from the
|
|
93
|
-
// webRequest API for this frame; this can happen when Service Workers
|
|
94
|
-
// are used. In this case, we consider that the parent frame is the main
|
|
95
|
-
// frame (which is very likely the case).
|
|
96
|
-
if (frame === undefined) {
|
|
97
|
-
ancestors.push({
|
|
98
|
-
frameId: 0,
|
|
99
|
-
url: this.url,
|
|
100
|
-
});
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Continue going up the ancestors chain
|
|
75
|
+
// If `frame` if undefined, this means we do not have any information
|
|
76
|
+
// about the frame associated with `currentFrameId`. This can happen if
|
|
77
|
+
// the event for `main_frame` or `sub_frame` was not emitted from the
|
|
78
|
+
// webRequest API for this frame; this can happen when Service Workers
|
|
79
|
+
// are used. In this case, we consider that the parent frame is the main
|
|
80
|
+
// frame (which is very likely the case).
|
|
81
|
+
if (frame === undefined) {
|
|
105
82
|
ancestors.push({
|
|
106
|
-
frameId:
|
|
107
|
-
url:
|
|
83
|
+
frameId: 0,
|
|
84
|
+
url: page.url,
|
|
108
85
|
});
|
|
109
|
-
|
|
86
|
+
break;
|
|
110
87
|
}
|
|
111
88
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
getTabUrl() {
|
|
119
|
-
return this.url;
|
|
89
|
+
// Continue going up the ancestors chain
|
|
90
|
+
ancestors.push({
|
|
91
|
+
frameId: currentFrameId,
|
|
92
|
+
url: frame.url,
|
|
93
|
+
});
|
|
94
|
+
currentFrameId = frame.parentFrameId;
|
|
120
95
|
}
|
|
121
96
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
*/
|
|
125
|
-
getFrameUrl(context) {
|
|
126
|
-
const { frameId } = context;
|
|
97
|
+
return ancestors;
|
|
98
|
+
}
|
|
127
99
|
|
|
128
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Return the URL of the frame.
|
|
102
|
+
*/
|
|
103
|
+
export function getFrameUrl(page, context) {
|
|
104
|
+
const { frameId } = context;
|
|
129
105
|
|
|
130
|
-
|
|
131
|
-
// if the iframe is specified in the HTML of the page directly). In this
|
|
132
|
-
// case we try to fall-back to something else: documentUrl, originUrl,
|
|
133
|
-
// initiator.
|
|
134
|
-
if (frame === undefined) {
|
|
135
|
-
return context.documentUrl || context.originUrl || context.initiator;
|
|
136
|
-
}
|
|
106
|
+
const frame = page.frames[frameId];
|
|
137
107
|
|
|
138
|
-
|
|
108
|
+
// In some cases, frame creation does not trigger a webRequest event (e.g.:
|
|
109
|
+
// if the iframe is specified in the HTML of the page directly). In this
|
|
110
|
+
// case we try to fall-back to something else: documentUrl, originUrl,
|
|
111
|
+
// initiator.
|
|
112
|
+
if (frame === undefined) {
|
|
113
|
+
return context.documentUrl || context.originUrl || context.initiator;
|
|
139
114
|
}
|
|
115
|
+
|
|
116
|
+
return frame.url;
|
|
140
117
|
}
|