@cloudcare/browser-rum 3.3.14 → 3.3.15
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/README.md +48 -0
- package/README.zh.md +35 -0
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/perStartRum.js +3 -0
- package/cjs/boot/perStartRum.js.map +1 -1
- package/cjs/boot/recorderApi.js +72 -56
- package/cjs/boot/recorderApi.js.map +1 -1
- package/cjs/boot/rumPublicApi.js +35 -3
- package/cjs/boot/rumPublicApi.js.map +1 -1
- package/cjs/domain/assembly.js +7 -1
- package/cjs/domain/assembly.js.map +1 -1
- package/cjs/domain/configuration.js +62 -0
- package/cjs/domain/configuration.js.map +1 -1
- package/cjs/domain/deflate/deflateWorker.js +1 -1
- package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/cjs/domain/requestCollection.js +3 -1
- package/cjs/domain/requestCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/cjs/domain/tracing/tracer.js +5 -1
- package/cjs/domain/tracing/tracer.js.map +1 -1
- package/cjs/domain/visitorId/index.js +379 -0
- package/cjs/domain/visitorId/index.js.map +1 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/perStartRum.js +3 -0
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +72 -56
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/rumPublicApi.js +36 -4
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/domain/assembly.js +7 -1
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/configuration.js +62 -1
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +1 -1
- package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/esm/domain/requestCollection.js +4 -2
- package/esm/domain/requestCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/tracing/tracer.js +6 -2
- package/esm/domain/tracing/tracer.js.map +1 -1
- package/esm/domain/visitorId/index.js +368 -0
- package/esm/domain/visitorId/index.js.map +1 -0
- package/package.json +4 -4
- package/src/boot/perStartRum.js +4 -0
- package/src/boot/recorderApi.js +73 -59
- package/src/boot/rumPublicApi.js +38 -4
- package/src/domain/assembly.js +13 -1
- package/src/domain/configuration.js +154 -0
- package/src/domain/requestCollection.js +4 -1
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +3 -0
- package/src/domain/tracing/tracer.js +15 -2
- package/src/domain/visitorId/index.js +522 -0
- package/types/index.d.ts +2 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
import { DOM_EVENT, ONE_HOUR, UUID, WeakSet, addEventListener, display, getOrigin, initFetchObservable, initXhrObservable, isRequest, noop, normalizeUrl, shallowClone, timeStampNow } from '@cloudcare/browser-core';
|
|
3
|
+
import { isAllowedRequestUrl } from '../rumEventsCollection/resource/resourceUtils';
|
|
4
|
+
import { createRandomHexIdentifier } from '../tracing/traceIdentifier';
|
|
5
|
+
export var VISITOR_ID_CONTEXT_KEY = 'visitor_id';
|
|
6
|
+
export var VISITOR_ID_STORAGE_KEY = '_gc_visitor_id';
|
|
7
|
+
export var DEFAULT_VISITOR_ID_TTL_HOURS = 24;
|
|
8
|
+
var PERSISTENT_ID_PREFIX = 'p';
|
|
9
|
+
var SESSION_ID_PREFIX = 's';
|
|
10
|
+
var VISITOR_ID_PATTERN = /^[ps][0-9a-f]{32}$/;
|
|
11
|
+
var FETCH_INIT_FIELDS = ['method', 'headers', 'body', 'referrer', 'referrerPolicy', 'mode', 'credentials', 'cache', 'redirect', 'integrity', 'keepalive', 'signal', 'window', 'duplex', 'priority', 'attributionReporting', 'browsingTopics'];
|
|
12
|
+
export function startVisitorId(configuration) {
|
|
13
|
+
if (!configuration.visitorId.enabled) {
|
|
14
|
+
return createVisitorIdStub();
|
|
15
|
+
}
|
|
16
|
+
var manager = createVisitorIdManager(configuration.visitorId);
|
|
17
|
+
var requestCollection = startVisitorIdRequestCollection(configuration, manager);
|
|
18
|
+
return {
|
|
19
|
+
getId: manager.getId,
|
|
20
|
+
reset: manager.reset,
|
|
21
|
+
stop: function stop() {
|
|
22
|
+
requestCollection.stop();
|
|
23
|
+
manager.stop();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function createVisitorIdManager(visitorIdConfiguration, options) {
|
|
28
|
+
if (options === undefined) {
|
|
29
|
+
options = {};
|
|
30
|
+
}
|
|
31
|
+
var getNow = options.getNow || timeStampNow;
|
|
32
|
+
var createIdentifier = options.createIdentifier || createIdentifierValue;
|
|
33
|
+
var localStorage = getStorage(options, 'localStorage');
|
|
34
|
+
var sessionStorage = getStorage(options, 'sessionStorage');
|
|
35
|
+
var ttl = visitorIdConfiguration.ttlHours * ONE_HOUR;
|
|
36
|
+
var currentRecord = loadOrCreateRecord();
|
|
37
|
+
var storageListener = localStorage ? addEventListener(window, DOM_EVENT.STORAGE, function (event) {
|
|
38
|
+
if (event.key !== VISITOR_ID_STORAGE_KEY) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (event.storageArea && event.storageArea !== localStorage) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Storage events may be queued before a later reset in this or another tab.
|
|
45
|
+
// Read the current value instead of replaying the event's stale snapshot.
|
|
46
|
+
var nextRecord = readRecord(localStorage, PERSISTENT_ID_PREFIX, getNow(), ttl);
|
|
47
|
+
if (nextRecord && currentRecord && compareRecords(nextRecord, currentRecord) < 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
currentRecord = nextRecord;
|
|
51
|
+
}) : {
|
|
52
|
+
stop: noop
|
|
53
|
+
};
|
|
54
|
+
function loadOrCreateRecord() {
|
|
55
|
+
var now = getNow();
|
|
56
|
+
var persistentRecord = readRecord(localStorage, PERSISTENT_ID_PREFIX, now, ttl);
|
|
57
|
+
var sessionRecord = readRecord(sessionStorage, SESSION_ID_PREFIX, now, ttl);
|
|
58
|
+
if (sessionRecord && persistentRecord) {
|
|
59
|
+
var order = compareRecords(sessionRecord, persistentRecord);
|
|
60
|
+
return order > 0 || order === 0 && sessionRecord.revision === undefined && persistentRecord.revision === undefined ? sessionRecord : persistentRecord;
|
|
61
|
+
}
|
|
62
|
+
if (sessionRecord || persistentRecord) {
|
|
63
|
+
return sessionRecord || persistentRecord;
|
|
64
|
+
}
|
|
65
|
+
return createAndPersistRecord(now);
|
|
66
|
+
}
|
|
67
|
+
function createAndPersistRecord(now) {
|
|
68
|
+
var identifier = createIdentifier();
|
|
69
|
+
// Date.now() can return the same value for several resets. Keep their order
|
|
70
|
+
// independently from the TTL timestamp, including when session cleanup fails.
|
|
71
|
+
var revision = 0;
|
|
72
|
+
[currentRecord, readRecord(localStorage, PERSISTENT_ID_PREFIX, now, ttl), readRecord(sessionStorage, SESSION_ID_PREFIX, now, ttl)].forEach(function (record) {
|
|
73
|
+
if (record && record.createdAt === now) {
|
|
74
|
+
revision = Math.max(revision, (record.revision || 0) + 1);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var persistentRecord = {
|
|
78
|
+
id: PERSISTENT_ID_PREFIX + identifier,
|
|
79
|
+
createdAt: now,
|
|
80
|
+
revision: revision
|
|
81
|
+
};
|
|
82
|
+
var storedPersistentRecord = writeRecord(localStorage, persistentRecord, PERSISTENT_ID_PREFIX, now, ttl);
|
|
83
|
+
if (storedPersistentRecord) {
|
|
84
|
+
try {
|
|
85
|
+
sessionStorage && sessionStorage.removeItem(VISITOR_ID_STORAGE_KEY);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
// Ordering metadata still supersedes the stale session record.
|
|
88
|
+
}
|
|
89
|
+
return storedPersistentRecord;
|
|
90
|
+
}
|
|
91
|
+
var sessionRecord = {
|
|
92
|
+
id: SESSION_ID_PREFIX + identifier,
|
|
93
|
+
createdAt: now,
|
|
94
|
+
revision: revision
|
|
95
|
+
};
|
|
96
|
+
return writeRecord(sessionStorage, sessionRecord, SESSION_ID_PREFIX, now, ttl) || sessionRecord;
|
|
97
|
+
}
|
|
98
|
+
function ensureCurrentRecord() {
|
|
99
|
+
var now = getNow();
|
|
100
|
+
if (!isValidRecord(currentRecord, undefined, now, ttl)) {
|
|
101
|
+
currentRecord = loadOrCreateRecord();
|
|
102
|
+
}
|
|
103
|
+
return currentRecord;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
getId: function getId() {
|
|
107
|
+
return ensureCurrentRecord().id;
|
|
108
|
+
},
|
|
109
|
+
reset: function reset() {
|
|
110
|
+
currentRecord = createAndPersistRecord(getNow());
|
|
111
|
+
},
|
|
112
|
+
stop: storageListener.stop
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export function startVisitorIdRequestCollection(configuration, manager) {
|
|
116
|
+
var xhrHeaderReservation;
|
|
117
|
+
var xhrSubscription = initXhrObservable().subscribe(function (context) {
|
|
118
|
+
if (context.state === 'start') {
|
|
119
|
+
context.visitorId = xhrHeaderReservation.apply(context);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
xhrHeaderReservation = startVisitorIdXhrHeaderReservation(configuration, manager);
|
|
123
|
+
var fetchSubscription = initFetchObservable().subscribe(function (context) {
|
|
124
|
+
if (context.state === 'start' && shouldInjectVisitorId(configuration, context.url)) {
|
|
125
|
+
var visitorId = manager.getId();
|
|
126
|
+
if (injectVisitorIdIntoFetch(context, configuration.visitorId.header, visitorId)) {
|
|
127
|
+
context.visitorId = visitorId;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
stop: function stop() {
|
|
133
|
+
xhrHeaderReservation.stop();
|
|
134
|
+
xhrSubscription.unsubscribe();
|
|
135
|
+
fetchSubscription.unsubscribe();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export function shouldInjectVisitorId(configuration, url) {
|
|
140
|
+
return isAllowedRequestUrl(configuration, url) && matchesVisitorIdUrl(configuration.visitorId.match, url);
|
|
141
|
+
}
|
|
142
|
+
export function matchesVisitorIdUrl(matchOptions, url) {
|
|
143
|
+
for (var index = 0; index < matchOptions.length; index += 1) {
|
|
144
|
+
var matchOption = matchOptions[index];
|
|
145
|
+
try {
|
|
146
|
+
if (typeof matchOption === 'function' && matchOption(url)) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
if (matchOption instanceof RegExp) {
|
|
150
|
+
var matched;
|
|
151
|
+
try {
|
|
152
|
+
matchOption.lastIndex = 0;
|
|
153
|
+
matched = matchOption.test(url);
|
|
154
|
+
} finally {
|
|
155
|
+
matchOption.lastIndex = 0;
|
|
156
|
+
}
|
|
157
|
+
if (matched) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (typeof matchOption === 'string' && url.indexOf(matchOption) === 0 && getOrigin(matchOption) === getOrigin(url)) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
display.error('Visitor ID URL matcher threw an error:', error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
function injectVisitorIdIntoFetch(context, header, visitorId) {
|
|
171
|
+
try {
|
|
172
|
+
var originalInit = context.init;
|
|
173
|
+
if (originalInit != null && _typeof(originalInit) !== 'object' && typeof originalInit !== 'function') {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
var init = shallowClone(originalInit);
|
|
177
|
+
// RequestInit is a WebIDL dictionary: inherited and non-enumerable fields
|
|
178
|
+
// count too. Materialize them so later tracing instrumentation preserves them.
|
|
179
|
+
FETCH_INIT_FIELDS.forEach(function (field) {
|
|
180
|
+
if (originalInit && field in originalInit && !Object.prototype.hasOwnProperty.call(init, field)) {
|
|
181
|
+
init[field] = originalInit[field];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
var headers = new Headers(init.headers === undefined && isRequest(context.input) ? context.input.headers : init.headers);
|
|
185
|
+
if (headers.has(header)) {
|
|
186
|
+
displayVisitorIdHeaderOverrideWarning('fetch');
|
|
187
|
+
}
|
|
188
|
+
headers.set(header, visitorId);
|
|
189
|
+
init.headers = headers;
|
|
190
|
+
// Avoid constructing a Request here: that can consume the caller's body even
|
|
191
|
+
// if a later header operation fails. Native fetch handles the body once.
|
|
192
|
+
context.init = init;
|
|
193
|
+
return true;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
display.error('Unable to inject the Visitor ID header into fetch:', error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function startVisitorIdXhrHeaderReservation(configuration, manager) {
|
|
199
|
+
var header = configuration.visitorId.header;
|
|
200
|
+
var matchedXhrs = new WeakSet();
|
|
201
|
+
var callerHeaderXhrs = new WeakSet();
|
|
202
|
+
var sentXhrs = new WeakSet();
|
|
203
|
+
var injectedIds = new WeakMap();
|
|
204
|
+
var originalOpen = XMLHttpRequest.prototype.open;
|
|
205
|
+
var stopped = false;
|
|
206
|
+
var openInstrumentation = function openInstrumentation() {
|
|
207
|
+
if (stopped) {
|
|
208
|
+
return originalOpen.apply(this, arguments);
|
|
209
|
+
}
|
|
210
|
+
var xhr = this;
|
|
211
|
+
matchedXhrs["delete"](xhr);
|
|
212
|
+
callerHeaderXhrs["delete"](xhr);
|
|
213
|
+
sentXhrs["delete"](xhr);
|
|
214
|
+
injectedIds["delete"](xhr);
|
|
215
|
+
try {
|
|
216
|
+
if (shouldInjectVisitorId(configuration, normalizeUrl(String(arguments[1])))) {
|
|
217
|
+
matchedXhrs.add(xhr);
|
|
218
|
+
}
|
|
219
|
+
} catch (error) {
|
|
220
|
+
// Let native open() validate the URL and preserve its original exception.
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
// open() synchronously dispatches OPENED; handlers may set headers/send.
|
|
224
|
+
return originalOpen.apply(xhr, arguments);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
matchedXhrs["delete"](xhr);
|
|
227
|
+
callerHeaderXhrs["delete"](xhr);
|
|
228
|
+
sentXhrs["delete"](xhr);
|
|
229
|
+
injectedIds["delete"](xhr);
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
XMLHttpRequest.prototype.open = openInstrumentation;
|
|
234
|
+
var originalSend = XMLHttpRequest.prototype.send;
|
|
235
|
+
var sendInstrumentation = function sendInstrumentation() {
|
|
236
|
+
if (stopped || !matchedXhrs.has(this)) {
|
|
237
|
+
return originalSend.apply(this, arguments);
|
|
238
|
+
}
|
|
239
|
+
var xhr = this;
|
|
240
|
+
var wasSent = sentXhrs.has(xhr);
|
|
241
|
+
sentXhrs.add(xhr);
|
|
242
|
+
try {
|
|
243
|
+
return originalSend.apply(xhr, arguments);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
// A failed first send leaves the native XHR open for header edits/retry.
|
|
246
|
+
// A failed duplicate send must not reopen an already-sent reservation.
|
|
247
|
+
if (!wasSent) {
|
|
248
|
+
sentXhrs["delete"](xhr);
|
|
249
|
+
}
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
XMLHttpRequest.prototype.send = sendInstrumentation;
|
|
254
|
+
var originalSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
|
|
255
|
+
var setRequestHeaderInstrumentation = function setRequestHeaderInstrumentation(name, value) {
|
|
256
|
+
if (!stopped && typeof name === 'string' && name.toLowerCase() === header && matchedXhrs.has(this) && !sentXhrs.has(this)) {
|
|
257
|
+
callerHeaderXhrs.add(this);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
return originalSetRequestHeader.apply(this, arguments);
|
|
261
|
+
};
|
|
262
|
+
XMLHttpRequest.prototype.setRequestHeader = setRequestHeaderInstrumentation;
|
|
263
|
+
return {
|
|
264
|
+
apply: function apply(context) {
|
|
265
|
+
var xhr = context.xhr;
|
|
266
|
+
if (!matchedXhrs.has(xhr)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (callerHeaderXhrs["delete"](xhr)) {
|
|
270
|
+
displayVisitorIdHeaderOverrideWarning('XHR');
|
|
271
|
+
}
|
|
272
|
+
if (injectedIds.has(xhr)) {
|
|
273
|
+
// Native send() may throw before sending and leave the XHR reusable.
|
|
274
|
+
// Headers cannot be replaced once set, so retain the first injected ID
|
|
275
|
+
// even if resetVisitorId() was called before the retry.
|
|
276
|
+
return injectedIds.get(xhr);
|
|
277
|
+
}
|
|
278
|
+
var visitorId = manager.getId();
|
|
279
|
+
try {
|
|
280
|
+
originalSetRequestHeader.call(xhr, header, visitorId);
|
|
281
|
+
injectedIds.set(xhr, visitorId);
|
|
282
|
+
return visitorId;
|
|
283
|
+
} catch (error) {
|
|
284
|
+
display.error('Unable to inject the Visitor ID header into XHR:', error);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
stop: function stop() {
|
|
289
|
+
stopped = true;
|
|
290
|
+
if (XMLHttpRequest.prototype.open === openInstrumentation) {
|
|
291
|
+
XMLHttpRequest.prototype.open = originalOpen;
|
|
292
|
+
}
|
|
293
|
+
if (XMLHttpRequest.prototype.send === sendInstrumentation) {
|
|
294
|
+
XMLHttpRequest.prototype.send = originalSend;
|
|
295
|
+
}
|
|
296
|
+
if (XMLHttpRequest.prototype.setRequestHeader === setRequestHeaderInstrumentation) {
|
|
297
|
+
XMLHttpRequest.prototype.setRequestHeader = originalSetRequestHeader;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function displayVisitorIdHeaderOverrideWarning(requestType) {
|
|
303
|
+
display.warn('Visitor ID header is already set on this ' + requestType + ' request. It was replaced with the SDK-managed value.');
|
|
304
|
+
}
|
|
305
|
+
function getStorage(options, storageName) {
|
|
306
|
+
if (Object.prototype.hasOwnProperty.call(options, storageName)) {
|
|
307
|
+
return options[storageName];
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
return window[storageName];
|
|
311
|
+
} catch (error) {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function readRecord(storage, expectedPrefix, now, ttl) {
|
|
316
|
+
if (!storage) {
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
return parseRecord(storage.getItem(VISITOR_ID_STORAGE_KEY), expectedPrefix, now, ttl);
|
|
321
|
+
} catch (error) {
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function writeRecord(storage, record, expectedPrefix, now, ttl) {
|
|
326
|
+
if (!storage) {
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
storage.setItem(VISITOR_ID_STORAGE_KEY, JSON.stringify(record));
|
|
331
|
+
} catch (error) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
var storedRecord = readRecord(storage, expectedPrefix, now, ttl);
|
|
335
|
+
return storedRecord && storedRecord.id === record.id && compareRecords(storedRecord, record) === 0 ? storedRecord : undefined;
|
|
336
|
+
}
|
|
337
|
+
function parseRecord(rawRecord, expectedPrefix, now, ttl) {
|
|
338
|
+
if (!rawRecord) {
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
var record = JSON.parse(rawRecord);
|
|
343
|
+
return isValidRecord(record, expectedPrefix, now, ttl) ? record : undefined;
|
|
344
|
+
} catch (error) {
|
|
345
|
+
return undefined;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function isValidRecord(record, expectedPrefix, now, ttl) {
|
|
349
|
+
return !!record && VISITOR_ID_PATTERN.test(record.id) && (!expectedPrefix || record.id.charAt(0) === expectedPrefix) && typeof record.createdAt === 'number' && (record.revision === undefined || typeof record.revision === 'number' && isFinite(record.revision) && record.revision >= 0 && Math.floor(record.revision) === record.revision) && record.createdAt <= now && record.createdAt + ttl > now;
|
|
350
|
+
}
|
|
351
|
+
function compareRecords(first, second) {
|
|
352
|
+
return first.createdAt - second.createdAt || (first.revision || 0) - (second.revision || 0);
|
|
353
|
+
}
|
|
354
|
+
function createIdentifierValue() {
|
|
355
|
+
try {
|
|
356
|
+
return createRandomHexIdentifier(16);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
return UUID().replace(/-/g, '');
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function createVisitorIdStub() {
|
|
362
|
+
return {
|
|
363
|
+
getId: noop,
|
|
364
|
+
reset: noop,
|
|
365
|
+
stop: noop
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["DOM_EVENT","ONE_HOUR","UUID","WeakSet","addEventListener","display","getOrigin","initFetchObservable","initXhrObservable","isRequest","noop","normalizeUrl","shallowClone","timeStampNow","isAllowedRequestUrl","createRandomHexIdentifier","VISITOR_ID_CONTEXT_KEY","VISITOR_ID_STORAGE_KEY","DEFAULT_VISITOR_ID_TTL_HOURS","PERSISTENT_ID_PREFIX","SESSION_ID_PREFIX","VISITOR_ID_PATTERN","FETCH_INIT_FIELDS","startVisitorId","configuration","visitorId","enabled","createVisitorIdStub","manager","createVisitorIdManager","requestCollection","startVisitorIdRequestCollection","getId","reset","stop","visitorIdConfiguration","options","undefined","getNow","createIdentifier","createIdentifierValue","localStorage","getStorage","sessionStorage","ttl","ttlHours","currentRecord","loadOrCreateRecord","storageListener","window","STORAGE","event","key","storageArea","nextRecord","readRecord","compareRecords","now","persistentRecord","sessionRecord","order","revision","createAndPersistRecord","identifier","forEach","record","createdAt","Math","max","id","storedPersistentRecord","writeRecord","removeItem","error","ensureCurrentRecord","isValidRecord","xhrHeaderReservation","xhrSubscription","subscribe","context","state","apply","startVisitorIdXhrHeaderReservation","fetchSubscription","shouldInjectVisitorId","url","injectVisitorIdIntoFetch","header","unsubscribe","matchesVisitorIdUrl","match","matchOptions","index","length","matchOption","RegExp","matched","lastIndex","test","indexOf","originalInit","init","_typeof","field","Object","prototype","hasOwnProperty","call","headers","Headers","input","has","displayVisitorIdHeaderOverrideWarning","set","matchedXhrs","callerHeaderXhrs","sentXhrs","injectedIds","WeakMap","originalOpen","XMLHttpRequest","open","stopped","openInstrumentation","arguments","xhr","String","add","originalSend","send","sendInstrumentation","wasSent","originalSetRequestHeader","setRequestHeader","setRequestHeaderInstrumentation","name","value","toLowerCase","get","requestType","warn","storageName","storage","expectedPrefix","parseRecord","getItem","setItem","JSON","stringify","storedRecord","rawRecord","parse","charAt","isFinite","floor","first","second","replace"],"sources":["../../../src/domain/visitorId/index.js"],"mappings":";AAAA,SACEA,SAAS,EACTC,QAAQ,EACRC,IAAI,EACJC,OAAO,EACPC,gBAAgB,EAChBC,OAAO,EACPC,SAAS,EACTC,mBAAmB,EACnBC,iBAAiB,EACjBC,SAAS,EACTC,IAAI,EACJC,YAAY,EACZC,YAAY,EACZC,YAAY,QACP,yBAAyB;AAChC,SAASC,mBAAmB,QAAQ,+CAA+C;AACnF,SAASC,yBAAyB,QAAQ,4BAA4B;AAEtE,OAAO,IAAIC,sBAAsB,GAAG,YAAY;AAChD,OAAO,IAAIC,sBAAsB,GAAG,gBAAgB;AACpD,OAAO,IAAIC,4BAA4B,GAAG,EAAE;AAE5C,IAAIC,oBAAoB,GAAG,GAAG;AAC9B,IAAIC,iBAAiB,GAAG,GAAG;AAC3B,IAAIC,kBAAkB,GA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BI,MAAM,CAACJ,QAAQ,IAAI,CAAC,IACpBM,IAAI,CAACuF,KAAK,CAACzF,MAAM,CAACJ,QAAQ,CAAC,KAAKI,MAAM,CAACJ,QAAS,CAAC,IACrDI,MAAM,CAACC,SAAS,IAAIT,GAAG,IACvBQ,MAAM,CAACC,SAAS,GAAGtB,GAAG,GAAGa,GAAG;AAEhC;AAEA,SAASD,cAAcA,CAACmG,KAAK,EAAEC,MAAM,EAAE;EACrC,OAAOD,KAAK,CAACzF,SAAS,GAAG0F,MAAM,CAAC1F,SAAS,IACvC,CAACyF,KAAK,CAAC9F,QAAQ,IAAI,CAAC,KAAK+F,MAAM,CAAC/F,QAAQ,IAAI,CAAC,CAAC;AAClD;AAEA,SAASrB,qBAAqBA,CAAA,EAAG;EAC/B,IAAI;IACF,OAAOzB,yBAAyB,CAAC,EAAE,CAAC;EACtC,CAAC,CAAC,OAAO0D,KAAK,EAAE;IACd,OAAOvE,IAAI,CAAC,CAAC,CAAC2J,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;EACjC;AACF;AAEA,SAASlI,mBAAmBA,CAAA,EAAG;EAC7B,OAAO;IACLK,KAAK,EAAEtB,IAAI;IACXuB,KAAK,EAAEvB,IAAI;IACXwB,IAAI,EAAExB;EACR,CAAC;AACH","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-rum",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.15",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@cloudcare/browser-core": "3.3.
|
|
9
|
-
"@cloudcare/browser-worker": "3.3.
|
|
8
|
+
"@cloudcare/browser-core": "3.3.15",
|
|
9
|
+
"@cloudcare/browser-worker": "3.3.15"
|
|
10
10
|
},
|
|
11
11
|
"description": "Guance Browser SDK RUM Package",
|
|
12
12
|
"browserSdkCapabilities": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"author": "dataflux",
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"homepage": "https://github.com/GuanceCloud/datakit-js/README.md",
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "a3f93aed4f6b30826605292d0086fc68a061a217"
|
|
45
45
|
}
|
package/src/boot/perStartRum.js
CHANGED
|
@@ -101,6 +101,10 @@ export function createPreStartStrategy(
|
|
|
101
101
|
return
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
if (rumPublicApiOptions.onConfigurationReady) {
|
|
105
|
+
rumPublicApiOptions.onConfigurationReady(configuration)
|
|
106
|
+
}
|
|
107
|
+
|
|
104
108
|
if (!eventBridgeAvailable && !configuration.sessionStoreStrategyType) {
|
|
105
109
|
display.warn(
|
|
106
110
|
'No storage available for session. We will not send any data.'
|
package/src/boot/recorderApi.js
CHANGED
|
@@ -59,6 +59,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
59
59
|
var state = {
|
|
60
60
|
$rStatus: RecorderStatus.Stopped
|
|
61
61
|
}
|
|
62
|
+
var retryOnView = false
|
|
62
63
|
var nextRecordingToken = 0
|
|
63
64
|
var unloadRecoveryGeneration = 0
|
|
64
65
|
var replayDeflateWorkerController = createDeflateWorkerController()
|
|
@@ -66,22 +67,38 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
66
67
|
return replayDeflateWorkerController.getStatus()
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
function isRecordingInProgress() {
|
|
71
|
+
return state.$rStatus >= RecorderStatus.Starting
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function keepRecordingIntent(options, shouldRetryOnView) {
|
|
75
|
+
retryOnView = shouldRetryOnView
|
|
76
|
+
state = {
|
|
77
|
+
$rStatus: RecorderStatus.IntentToStart,
|
|
78
|
+
$rOptions: options
|
|
79
|
+
}
|
|
80
|
+
notifyRecordingState(false)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function keepRecordingIntentAfterFailure(options) {
|
|
84
|
+
// `force` has already updated the current session before recorder startup.
|
|
85
|
+
// Reusing it while recovering would force the session again for every
|
|
86
|
+
// failed View instead of only retrying the recorder.
|
|
87
|
+
keepRecordingIntent(options && options.force ? undefined : options, true)
|
|
88
|
+
}
|
|
89
|
+
|
|
69
90
|
function reconcileStoppedRecordingState() {
|
|
70
91
|
if (
|
|
71
92
|
state.$rStatus === RecorderStatus.Started &&
|
|
72
93
|
state.$rIsStopped &&
|
|
73
94
|
state.$rIsStopped()
|
|
74
95
|
) {
|
|
75
|
-
state
|
|
76
|
-
notifyRecordingState(false)
|
|
96
|
+
keepRecordingIntentAfterFailure(state.$rOptions)
|
|
77
97
|
}
|
|
78
98
|
}
|
|
79
99
|
|
|
80
100
|
var startStrategy = function (options) {
|
|
81
|
-
|
|
82
|
-
$rStatus: RecorderStatus.IntentToStart,
|
|
83
|
-
$rOptions: options
|
|
84
|
-
}
|
|
101
|
+
keepRecordingIntent(options)
|
|
85
102
|
}
|
|
86
103
|
var stopStrategy = function () {
|
|
87
104
|
unloadRecoveryGeneration += 1
|
|
@@ -105,26 +122,17 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
105
122
|
compressionWorker
|
|
106
123
|
) {
|
|
107
124
|
lifeCycle.subscribe(LifeCycleEventType.SESSION_EXPIRED, function () {
|
|
108
|
-
if (
|
|
109
|
-
state.$rStatus === RecorderStatus.Starting ||
|
|
110
|
-
state.$rStatus === RecorderStatus.Started
|
|
111
|
-
) {
|
|
125
|
+
if (isRecordingInProgress()) {
|
|
112
126
|
var options = state.$rOptions
|
|
113
127
|
stopStrategy()
|
|
114
|
-
|
|
115
|
-
$rStatus: RecorderStatus.IntentToStart,
|
|
116
|
-
$rOptions: options
|
|
117
|
-
}
|
|
128
|
+
keepRecordingIntent(options)
|
|
118
129
|
}
|
|
119
130
|
})
|
|
120
131
|
lifeCycle.subscribe(
|
|
121
132
|
LifeCycleEventType.PAGE_EXITED,
|
|
122
133
|
function (pageExitEvent) {
|
|
123
134
|
if (pageExitEvent.reason === PageExitReason.UNLOADING) {
|
|
124
|
-
var shouldRecoverCanceledUnload =
|
|
125
|
-
state.$rStatus === RecorderStatus.IntentToStart ||
|
|
126
|
-
state.$rStatus === RecorderStatus.Starting ||
|
|
127
|
-
state.$rStatus === RecorderStatus.Started
|
|
135
|
+
var shouldRecoverCanceledUnload = state.$rStatus
|
|
128
136
|
var recoveryOptions =
|
|
129
137
|
state.$rOptions && state.$rOptions.force
|
|
130
138
|
? undefined
|
|
@@ -152,6 +160,12 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
152
160
|
startStrategy(state.$rOptions)
|
|
153
161
|
}
|
|
154
162
|
})
|
|
163
|
+
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
|
|
164
|
+
reconcileStoppedRecordingState()
|
|
165
|
+
if (state.$rStatus === RecorderStatus.IntentToStart && retryOnView) {
|
|
166
|
+
startStrategy(state.$rOptions)
|
|
167
|
+
}
|
|
168
|
+
})
|
|
155
169
|
if (sessionManager.sessionStateUpdateObservable) {
|
|
156
170
|
sessionManager.sessionStateUpdateObservable.subscribe(function ({
|
|
157
171
|
previousState,
|
|
@@ -169,28 +183,41 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
169
183
|
var cachedDeflateEncoder
|
|
170
184
|
var replayWorker = compressionWorker
|
|
171
185
|
var replayWorkerOwnership = compressionWorker ? 'shared' : 'none'
|
|
172
|
-
|
|
173
|
-
var failedDeflateEncoder = cachedDeflateEncoder
|
|
174
|
-
cachedDeflateEncoder = undefined
|
|
175
|
-
stopStrategy()
|
|
176
|
-
if (failedDeflateEncoder) {
|
|
177
|
-
failedDeflateEncoder.stop()
|
|
178
|
-
}
|
|
179
|
-
if (replayWorkerOwnership === 'owned') {
|
|
180
|
-
replayWorker = undefined
|
|
181
|
-
replayWorkerOwnership = 'none'
|
|
182
|
-
replayDeflateWorkerController.reset()
|
|
183
|
-
} else if (replayWorkerOwnership === 'shared') {
|
|
184
|
-
// The compression worker belongs to the RUM transport. A replay
|
|
185
|
-
// stream failure must not terminate or reset that shared worker.
|
|
186
|
-
// Detach replay from it so an explicit restart can fall back to an
|
|
187
|
-
// isolated worker instead of remaining disabled for the whole page.
|
|
188
|
-
replayWorker = undefined
|
|
189
|
-
replayWorkerOwnership = 'none'
|
|
190
|
-
}
|
|
191
|
-
}
|
|
186
|
+
var activeDeflateFailure
|
|
192
187
|
function getOrCreateDeflateEncoder() {
|
|
193
188
|
if (!cachedDeflateEncoder) {
|
|
189
|
+
var handleDeflateWorkerFailure = function () {
|
|
190
|
+
if (activeDeflateFailure !== handleDeflateWorkerFailure) {
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
activeDeflateFailure = undefined
|
|
194
|
+
var shouldRetry = isRecordingInProgress()
|
|
195
|
+
var recoveryOptions = state.$rOptions
|
|
196
|
+
var failedDeflateEncoder = cachedDeflateEncoder
|
|
197
|
+
cachedDeflateEncoder = undefined
|
|
198
|
+
if (shouldRetry) {
|
|
199
|
+
stopStrategy()
|
|
200
|
+
}
|
|
201
|
+
if (failedDeflateEncoder) {
|
|
202
|
+
failedDeflateEncoder.stop()
|
|
203
|
+
}
|
|
204
|
+
if (replayWorkerOwnership === 'owned') {
|
|
205
|
+
replayWorker = undefined
|
|
206
|
+
replayWorkerOwnership = 'none'
|
|
207
|
+
replayDeflateWorkerController.reset()
|
|
208
|
+
} else if (replayWorkerOwnership === 'shared') {
|
|
209
|
+
// The compression worker belongs to the RUM transport. A replay
|
|
210
|
+
// stream failure must not terminate or reset that shared worker.
|
|
211
|
+
// Detach replay from it so a retry can fall back to an isolated
|
|
212
|
+
// worker instead of remaining disabled for the whole page.
|
|
213
|
+
replayWorker = undefined
|
|
214
|
+
replayWorkerOwnership = 'none'
|
|
215
|
+
}
|
|
216
|
+
if (shouldRetry) {
|
|
217
|
+
keepRecordingIntentAfterFailure(recoveryOptions)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
activeDeflateFailure = handleDeflateWorkerFailure
|
|
194
221
|
if (!replayWorker) {
|
|
195
222
|
// Mark ownership before start(): worker creation can fail
|
|
196
223
|
// synchronously and invoke the failure callback before start()
|
|
@@ -221,10 +248,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
221
248
|
}
|
|
222
249
|
startStrategy = function (options) {
|
|
223
250
|
reconcileStoppedRecordingState()
|
|
224
|
-
if (
|
|
225
|
-
state.$rStatus === RecorderStatus.Starting ||
|
|
226
|
-
state.$rStatus === RecorderStatus.Started
|
|
227
|
-
) {
|
|
251
|
+
if (isRecordingInProgress()) {
|
|
228
252
|
if (options && options.force) {
|
|
229
253
|
sessionManager.setForcedSession()
|
|
230
254
|
}
|
|
@@ -239,10 +263,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
239
263
|
}
|
|
240
264
|
var session = sessionManager.findTrackedSession()
|
|
241
265
|
if (!session || !session.sessionReplayAllowed) {
|
|
242
|
-
|
|
243
|
-
$rStatus: RecorderStatus.IntentToStart,
|
|
244
|
-
$rOptions: options
|
|
245
|
-
}
|
|
266
|
+
keepRecordingIntent(options)
|
|
246
267
|
return
|
|
247
268
|
}
|
|
248
269
|
|
|
@@ -262,9 +283,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
262
283
|
}
|
|
263
284
|
var deflateEncoder = getOrCreateDeflateEncoder()
|
|
264
285
|
if (!deflateEncoder) {
|
|
265
|
-
|
|
266
|
-
$rStatus: RecorderStatus.Stopped
|
|
267
|
-
}
|
|
286
|
+
keepRecordingIntentAfterFailure(options)
|
|
268
287
|
return
|
|
269
288
|
}
|
|
270
289
|
try {
|
|
@@ -277,12 +296,10 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
277
296
|
undefined,
|
|
278
297
|
function () {
|
|
279
298
|
if (
|
|
280
|
-
(
|
|
281
|
-
state.$rStatus === RecorderStatus.Started) &&
|
|
299
|
+
isRecordingInProgress() &&
|
|
282
300
|
state.$rToken === recordingToken
|
|
283
301
|
) {
|
|
284
|
-
|
|
285
|
-
notifyRecordingState(false)
|
|
302
|
+
keepRecordingIntentAfterFailure(options)
|
|
286
303
|
}
|
|
287
304
|
}
|
|
288
305
|
)
|
|
@@ -294,9 +311,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
294
311
|
return
|
|
295
312
|
}
|
|
296
313
|
if (recordingImpl.isStopped && recordingImpl.isStopped()) {
|
|
297
|
-
|
|
298
|
-
$rStatus: RecorderStatus.Stopped
|
|
299
|
-
}
|
|
314
|
+
keepRecordingIntentAfterFailure(options)
|
|
300
315
|
return
|
|
301
316
|
}
|
|
302
317
|
state = {
|
|
@@ -336,13 +351,12 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
|
336
351
|
state.$rStatus === RecorderStatus.Starting &&
|
|
337
352
|
state.$rToken === recordingToken
|
|
338
353
|
) {
|
|
339
|
-
|
|
354
|
+
keepRecordingIntentAfterFailure(options)
|
|
340
355
|
}
|
|
341
356
|
if (
|
|
342
357
|
cachedDeflateEncoder === deflateEncoder &&
|
|
343
358
|
!(
|
|
344
|
-
(
|
|
345
|
-
state.$rStatus === RecorderStatus.Started) &&
|
|
359
|
+
isRecordingInProgress() &&
|
|
346
360
|
state.$rToken !== recordingToken
|
|
347
361
|
)
|
|
348
362
|
) {
|