@cloudcare/rum-uniapp 2.1.15 → 2.1.17

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.
Files changed (41) hide show
  1. package/cjs/boot/buildEnv.js +1 -1
  2. package/cjs/boot/rum.entry.js +78 -56
  3. package/cjs/boot/rum.js +4 -3
  4. package/cjs/core/baseInfo.js +15 -1
  5. package/cjs/core/boundedBuffer.js +10 -6
  6. package/cjs/core/contextManager.js +84 -0
  7. package/cjs/core/dataMap.js +6 -1
  8. package/cjs/core/heavyCustomerDataWarning.js +31 -0
  9. package/cjs/core/transport.js +6 -28
  10. package/cjs/core/user.js +40 -0
  11. package/cjs/core/xhrProxy.js +13 -17
  12. package/cjs/helper/byteUtils.js +39 -0
  13. package/cjs/helper/commonContext.js +14 -0
  14. package/cjs/helper/jsonStringify.js +57 -0
  15. package/cjs/helper/tracekit.js +23 -4
  16. package/cjs/helper/utils.js +160 -130
  17. package/cjs/rumEventsCollection/assembly.js +6 -1
  18. package/cjs/rumEventsCollection/error/errorCollection.js +20 -24
  19. package/cjs/rumEventsCollection/page/index.js +3 -2
  20. package/cjs/rumEventsCollection/resource/resourceCollection.js +3 -1
  21. package/esm/boot/buildEnv.js +1 -1
  22. package/esm/boot/rum.entry.js +73 -55
  23. package/esm/boot/rum.js +4 -2
  24. package/esm/core/baseInfo.js +13 -1
  25. package/esm/core/boundedBuffer.js +9 -6
  26. package/esm/core/contextManager.js +70 -0
  27. package/esm/core/dataMap.js +4 -0
  28. package/esm/core/heavyCustomerDataWarning.js +19 -0
  29. package/esm/core/transport.js +6 -29
  30. package/esm/core/user.js +31 -0
  31. package/esm/core/xhrProxy.js +13 -17
  32. package/esm/helper/byteUtils.js +29 -0
  33. package/esm/helper/commonContext.js +7 -0
  34. package/esm/helper/jsonStringify.js +46 -0
  35. package/esm/helper/tracekit.js +22 -4
  36. package/esm/helper/utils.js +144 -115
  37. package/esm/rumEventsCollection/assembly.js +6 -1
  38. package/esm/rumEventsCollection/error/errorCollection.js +20 -25
  39. package/esm/rumEventsCollection/page/index.js +4 -3
  40. package/esm/rumEventsCollection/resource/resourceCollection.js +2 -1
  41. package/package.json +43 -43
@@ -1,14 +1,42 @@
1
- import { isPercentage, extend2Lev, extend, now, createContextManager, defineGlobal, getGlobalObject, isString, isObject } from '../helper/utils';
1
+ import { isPercentage, extend2Lev, defineGlobal, getGlobalObject, now, deepClone } from '../helper/utils';
2
2
  import { startRum } from './rum';
3
3
  import { ActionType } from '../helper/enums';
4
+ import { buildCommonContext } from '../helper/commonContext';
5
+ import { BoundedBuffer } from '../core/boundedBuffer';
6
+ import { createContextManager } from '../core/contextManager';
7
+ import { CustomerDataType } from '../core/heavyCustomerDataWarning';
8
+ import { checkUser, sanitizeUser } from '../core/user';
9
+ import { sdk } from '../core/sdk';
4
10
  export var makeRum = function makeRum(startRumImpl) {
5
11
  var isAlreadyInitialized = false;
6
- var globalContextManager = createContextManager();
7
- var user = {};
12
+ var globalContextManager = createContextManager(CustomerDataType.GlobalContext);
13
+ var userContextManager = createContextManager(CustomerDataType.User); // var user = {}
8
14
 
9
- var _getInternalContext = function getInternalContext() {};
15
+ var getInternalContextStrategy = function getInternalContextStrategy() {
16
+ return undefined;
17
+ };
18
+
19
+ var bufferApiCalls = new BoundedBuffer();
20
+
21
+ var _addActionStrategy = function addActionStrategy(action, commonContext) {
22
+ if (typeof commonContext == 'undefined') {
23
+ commonContext = buildCommonContext(globalContextManager, userContextManager);
24
+ }
10
25
 
11
- var addActionStrategy = function addActionStrategy() {};
26
+ bufferApiCalls.add(function () {
27
+ return _addActionStrategy(action, commonContext);
28
+ });
29
+ };
30
+
31
+ var _addErrorStrategy = function addErrorStrategy(providedError, commonContext) {
32
+ if (typeof commonContext == 'undefined') {
33
+ commonContext = buildCommonContext(globalContextManager, userContextManager);
34
+ }
35
+
36
+ bufferApiCalls.add(function () {
37
+ return _addErrorStrategy(providedError, commonContext);
38
+ });
39
+ };
12
40
 
13
41
  var rumGlobal = {
14
42
  init: function init(Vue, userConfiguration) {
@@ -23,14 +51,13 @@ export var makeRum = function makeRum(startRumImpl) {
23
51
  }
24
52
 
25
53
  var _startRumImpl = startRumImpl(Vue, userConfiguration, function () {
26
- return {
27
- user: user,
28
- context: globalContextManager.get()
29
- };
54
+ return buildCommonContext(globalContextManager, userContextManager);
30
55
  });
31
56
 
32
- _getInternalContext = _startRumImpl.getInternalContext;
33
- addActionStrategy = _startRumImpl.addAction;
57
+ getInternalContextStrategy = _startRumImpl.getInternalContext;
58
+ _addActionStrategy = _startRumImpl.addAction;
59
+ _addErrorStrategy = _startRumImpl.addError;
60
+ bufferApiCalls.drain();
34
61
  isAlreadyInitialized = true;
35
62
  },
36
63
  initVue3: function initVue3(userConfiguration) {
@@ -39,38 +66,51 @@ export var makeRum = function makeRum(startRumImpl) {
39
66
  }, userConfiguration));
40
67
  },
41
68
  getInternalContext: function getInternalContext(startTime) {
42
- return _getInternalContext(startTime);
69
+ return getInternalContextStrategy(startTime);
43
70
  },
44
- addRumGlobalContext: globalContextManager.add,
45
- removeRumGlobalContext: globalContextManager.remove,
46
- getRumGlobalContext: globalContextManager.get,
47
- setRumGlobalContext: globalContextManager.set,
71
+ addRumGlobalContext: globalContextManager.setContextProperty,
72
+ removeRumGlobalContext: globalContextManager.removeContextProperty,
73
+ getRumGlobalContext: globalContextManager.getContext,
74
+ setRumGlobalContext: globalContextManager.setContext,
75
+ clearRumGlobalContext: globalContextManager.clearContext,
48
76
  addAction: function addAction(name, context) {
49
- if (isObject(context) && isString(name)) {
50
- addActionStrategy({
51
- name: name,
52
- context: extend2Lev({}, context),
53
- startClocks: now(),
54
- type: ActionType.custom
55
- });
56
- }
77
+ _addActionStrategy({
78
+ name: name,
79
+ context: deepClone(context),
80
+ startClocks: now(),
81
+ type: ActionType.custom
82
+ });
57
83
  },
84
+ addError: function addError(error, context) {
85
+ _addErrorStrategy({
86
+ error: error,
87
+ context: extend2Lev({}, context),
88
+ startTime: now()
89
+ });
90
+ },
91
+ setUserProperty: function setUserProperty(key, property) {
92
+ var newUser = {};
93
+ newUser[key] = property;
94
+ var sanitizedProperty = sanitizeUser(newUser)[key];
95
+ userContextManager.setContextProperty(key, sanitizedProperty);
96
+ },
97
+ removeUserProperty: userContextManager.removeContextProperty,
58
98
  setUser: function setUser(newUser) {
59
- var sanitizedUser = sanitizeUser(newUser);
60
-
61
- if (sanitizedUser) {
62
- user = sanitizedUser;
63
- } else {
64
- console.error('Unsupported user:', newUser);
99
+ if (checkUser(newUser)) {
100
+ userContextManager.setContext(sanitizeUser(newUser));
65
101
  }
66
102
  },
67
- removeUser: function removeUser() {
68
- user = {};
69
- }
103
+ getUser: userContextManager.getContext,
104
+ removeUser: userContextManager.clearContext
70
105
  };
71
106
  return rumGlobal;
72
107
 
73
108
  function canInitRum(userConfiguration) {
109
+ if (!sdk) {
110
+ console.error('DATAFLUX_RUM unsupport platform, Fail to start.');
111
+ return false;
112
+ }
113
+
74
114
  if (isAlreadyInitialized) {
75
115
  console.error('DATAFLUX_RUM is already initialized.');
76
116
  return false;
@@ -93,28 +133,6 @@ export var makeRum = function makeRum(startRumImpl) {
93
133
 
94
134
  return true;
95
135
  }
96
-
97
- function sanitizeUser(newUser) {
98
- if (typeof newUser !== 'object' || !newUser) {
99
- return;
100
- }
101
-
102
- var result = extend2Lev({}, newUser);
103
-
104
- if ('id' in result) {
105
- result.id = String(result.id);
106
- }
107
-
108
- if ('name' in result) {
109
- result.name = String(result.name);
110
- }
111
-
112
- if ('email' in result) {
113
- result.email = String(result.email);
114
- }
115
-
116
- return result;
117
- }
118
136
  };
119
137
  export var datafluxRum = makeRum(startRum);
120
138
  defineGlobal(getGlobalObject(), 'DATAFLUX_RUM_MIN', datafluxRum);
package/esm/boot/rum.js CHANGED
@@ -14,7 +14,6 @@ import { startSetDataColloction } from '../rumEventsCollection/setDataCollection
14
14
  import { startActionCollection } from '../rumEventsCollection/action/actionCollection';
15
15
  import { sessionManagement } from '../core/sessionManagement';
16
16
  import { startInternalContext } from '../rumEventsCollection/internalContext';
17
- import { sdk } from '../core/sdk';
18
17
  export var startRum = function startRum(Vue, userConfiguration, getCommonContext) {
19
18
  var configuration = commonInit(userConfiguration, buildEnv);
20
19
  var lifeCycle = new LifeCycle();
@@ -25,7 +24,9 @@ export var startRum = function startRum(Vue, userConfiguration, getCommonContext
25
24
  startAppCollection(lifeCycle, configuration);
26
25
  startResourceCollection(lifeCycle, configuration);
27
26
  startViewCollection(lifeCycle, configuration, Vue);
28
- startErrorCollection(lifeCycle, configuration);
27
+
28
+ var _startErrorCollection = startErrorCollection(lifeCycle, configuration);
29
+
29
30
  startRequestCollection(lifeCycle, configuration);
30
31
  startPagePerformanceObservable(lifeCycle, configuration);
31
32
  startSetDataColloction(lifeCycle, Vue);
@@ -35,6 +36,7 @@ export var startRum = function startRum(Vue, userConfiguration, getCommonContext
35
36
  var internalContext = startInternalContext(userConfiguration.applicationId, session, parentContexts);
36
37
  return {
37
38
  addAction: _startActionCollection.addAction,
39
+ addError: _startErrorCollection.addError,
38
40
  getInternalContext: internalContext.get
39
41
  };
40
42
  };
@@ -20,7 +20,7 @@ class BaseInfo {
20
20
  osVersion = osInfo[0] || '';
21
21
  }
22
22
 
23
- var osVersionMajor = osVersion.split('.').length && osVersion.split('.')[0];
23
+ var osVersionMajor = osVersion && osVersion.split('.').length && osVersion.split('.')[0];
24
24
  this.deviceInfo = {
25
25
  screenSize: "".concat(deviceInfo.screenWidth, "*").concat(deviceInfo.screenHeight, " "),
26
26
  platform: deviceInfo.platform,
@@ -62,6 +62,18 @@ class BaseInfo {
62
62
  });
63
63
  }
64
64
 
65
+ getLaunchOptions() {
66
+ if (sdk.getLaunchOptionsSync) {
67
+ var res = sdk.getLaunchOptionsSync();
68
+ return {
69
+ query: res && res.query || {},
70
+ referrerInfo: res && res.referrerInfo || {}
71
+ };
72
+ } else {
73
+ return {};
74
+ }
75
+ }
76
+
65
77
  }
66
78
 
67
79
  export default new BaseInfo();
@@ -1,18 +1,21 @@
1
+ import { each } from '../helper/utils';
2
+ var BUFFER_LIMIT = 500;
3
+
1
4
  var _BoundedBuffer = function _BoundedBuffer() {
2
5
  this.buffer = [];
3
6
  };
4
7
 
5
8
  _BoundedBuffer.prototype = {
6
- add: function add(item) {
7
- var length = this.buffer.push(item);
9
+ add: function add(callback) {
10
+ var length = this.buffer.push(callback);
8
11
 
9
- if (length > this.limit) {
12
+ if (length > BUFFER_LIMIT) {
10
13
  this.buffer.splice(0, 1);
11
14
  }
12
15
  },
13
- drain: function drain(fn) {
14
- this.buffer.forEach(function (item) {
15
- fn(item);
16
+ drain: function drain() {
17
+ each(this.buffer, function (callback) {
18
+ callback();
16
19
  });
17
20
  this.buffer.length = 0;
18
21
  }
@@ -0,0 +1,70 @@
1
+ import { computeBytesCount } from '../helper/byteUtils';
2
+ import { deepClone, throttle } from '../helper/utils';
3
+ import { jsonStringify } from '../helper/jsonStringify';
4
+ import { warnIfCustomerDataLimitReached } from './heavyCustomerDataWarning';
5
+ export var BYTES_COMPUTATION_THROTTLING_DELAY = 200;
6
+ export function createContextManager(customerDataType, computeBytesCountImpl) {
7
+ if (typeof computeBytesCountImpl === 'undefined') {
8
+ computeBytesCountImpl = computeBytesCount;
9
+ }
10
+
11
+ var context = {};
12
+ var bytesCountCache;
13
+ var alreadyWarned = false; // Throttle the bytes computation to minimize the impact on performance.
14
+ // Especially useful if the user call context APIs synchronously multiple times in a row
15
+
16
+ var computeBytesCountThrottled = throttle(function (context) {
17
+ bytesCountCache = computeBytesCountImpl(jsonStringify(context));
18
+
19
+ if (!alreadyWarned) {
20
+ alreadyWarned = warnIfCustomerDataLimitReached(bytesCountCache, customerDataType);
21
+ }
22
+ }, BYTES_COMPUTATION_THROTTLING_DELAY).throttled;
23
+ return {
24
+ getBytesCount: function getBytesCount() {
25
+ return bytesCountCache;
26
+ },
27
+
28
+ /** @deprecated use getContext instead */
29
+ get: function get() {
30
+ return context;
31
+ },
32
+
33
+ /** @deprecated use setContextProperty instead */
34
+ add: function add(key, value) {
35
+ context[key] = value;
36
+ computeBytesCountThrottled(context);
37
+ },
38
+
39
+ /** @deprecated renamed to removeContextProperty */
40
+ remove: function remove(key) {
41
+ delete context[key];
42
+ computeBytesCountThrottled(context);
43
+ },
44
+
45
+ /** @deprecated use setContext instead */
46
+ set: function set(newContext) {
47
+ context = newContext;
48
+ computeBytesCountThrottled(context);
49
+ },
50
+ getContext: function getContext() {
51
+ return deepClone(context);
52
+ },
53
+ setContext: function setContext(newContext) {
54
+ context = deepClone(newContext);
55
+ computeBytesCountThrottled(context);
56
+ },
57
+ setContextProperty: function setContextProperty(key, property) {
58
+ context[key] = deepClone(property);
59
+ computeBytesCountThrottled(context);
60
+ },
61
+ removeContextProperty: function removeContextProperty(key) {
62
+ delete context[key];
63
+ computeBytesCountThrottled(context);
64
+ },
65
+ clearContext: function clearContext() {
66
+ context = {};
67
+ bytesCountCache = 0;
68
+ }
69
+ };
70
+ }
@@ -29,6 +29,10 @@ export var commonTags = {
29
29
  view_name: 'page.route',
30
30
  view_referer: 'page.referer'
31
31
  };
32
+ export var commonFields = {
33
+ app_launch_query: 'app.launch.query',
34
+ app_launch_referrer_info: 'app.launch.referrer_info'
35
+ };
32
36
  export var dataMap = {
33
37
  view: {
34
38
  type: RumEventType.VIEW,
@@ -0,0 +1,19 @@
1
+ import { ONE_KIBI_BYTE } from '../helper/byteUtils'; // RUM and logs batch bytes limit is 16KB
2
+ // ensure that we leave room for other event attributes and maintain a decent amount of event per batch
3
+ // (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
4
+
5
+ export var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE;
6
+ export var CustomerDataType = {
7
+ FeatureFlag: 'feature flag evaluation',
8
+ User: 'user',
9
+ GlobalContext: 'global context',
10
+ LoggerContext: 'logger context'
11
+ };
12
+ export function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {
13
+ if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {
14
+ console.warn('The ' + customerDataType + 'data is over ' + CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE + " KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.");
15
+ return true;
16
+ }
17
+
18
+ return false;
19
+ }
@@ -1,7 +1,8 @@
1
1
  import { findByPath, escapeRowData, isNumber, each, isString, values, extend, isObject, isEmptyObject, isArray, escapeRowField, escapeJsonValue, toServerDuration } from '../helper/utils';
2
2
  import { sdk } from '../core/sdk';
3
+ import { computeBytesCount } from '../helper/byteUtils';
3
4
  import { LifeCycleEventType } from '../core/lifeCycle';
4
- import { commonTags, dataMap } from './dataMap'; // https://en.wikipedia.org/wiki/UTF-8
5
+ import { commonTags, dataMap, commonFields } from './dataMap'; // https://en.wikipedia.org/wiki/UTF-8
5
6
 
6
7
  var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
7
8
  var CUSTOM_KEYS = 'custom_keys';
@@ -64,8 +65,9 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
64
65
  tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
65
66
  }
66
67
  });
68
+ var fields = extend({}, commonFields, value.fields);
67
69
  var fieldsStr = [];
68
- each(value.fields, function (_value, _key) {
70
+ each(fields, function (_value, _key) {
69
71
  if (isArray(_value) && _value.length === 2) {
70
72
  var type = _value[0],
71
73
  value_path = _value[1];
@@ -170,31 +172,6 @@ batch.prototype = {
170
172
  processSendData: function processSendData(message) {
171
173
  return processedMessageByDataMap(message).rowStr;
172
174
  },
173
- sizeInBytes: function sizeInBytes(candidate) {
174
- // Accurate byte size computations can degrade performances when there is a lot of events to process
175
- if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {
176
- return candidate.length;
177
- }
178
-
179
- var total = 0,
180
- charCode; // utf-8编码
181
-
182
- for (var i = 0, len = candidate.length; i < len; i++) {
183
- charCode = candidate.charCodeAt(i);
184
-
185
- if (charCode <= 0x007f) {
186
- total += 1;
187
- } else if (charCode <= 0x07ff) {
188
- total += 2;
189
- } else if (charCode <= 0xffff) {
190
- total += 3;
191
- } else {
192
- total += 4;
193
- }
194
- }
195
-
196
- return total;
197
- },
198
175
  addOrUpdate: function addOrUpdate(message, key) {
199
176
  var process = this.process(message);
200
177
  if (!process.processedMessage || process.processedMessage === '') return;
@@ -220,7 +197,7 @@ batch.prototype = {
220
197
  },
221
198
  process: function process(message) {
222
199
  var processedMessage = this.processSendData(message);
223
- var messageBytesSize = this.sizeInBytes(processedMessage);
200
+ var messageBytesSize = computeBytesCount(processedMessage);
224
201
  return {
225
202
  processedMessage: processedMessage,
226
203
  messageBytesSize: messageBytesSize
@@ -244,7 +221,7 @@ batch.prototype = {
244
221
  remove: function remove(key) {
245
222
  var removedMessage = this.upsertBuffer[key];
246
223
  delete this.upsertBuffer[key];
247
- var messageBytesSize = this.sizeInBytes(removedMessage);
224
+ var messageBytesSize = computeBytesCount(removedMessage);
248
225
  this.bufferBytesSize -= messageBytesSize;
249
226
  this.bufferMessageCount -= 1;
250
227
 
@@ -0,0 +1,31 @@
1
+ import { extend, getType, each } from '../helper/utils';
2
+ /**
3
+ * Clone input data and ensure known user properties (id, name, email)
4
+ * are strings, as defined here:
5
+ * https://docs.datadoghq.com/logs/log_configuration/attributes_naming_convention/#user-related-attributes
6
+ */
7
+
8
+ export function sanitizeUser(newUser) {
9
+ // We shallow clone only to prevent mutation of user data.
10
+ var user = extend({}, newUser);
11
+ var keys = ['id', 'name', 'email'];
12
+ each(keys, function (key) {
13
+ if (key in user) {
14
+ user[key] = String(user[key]);
15
+ }
16
+ });
17
+ return user;
18
+ }
19
+ /**
20
+ * Simple check to ensure user is valid
21
+ */
22
+
23
+ export function checkUser(newUser) {
24
+ var isValid = getType(newUser) === 'object';
25
+
26
+ if (!isValid) {
27
+ console.error('Unsupported user:', newUser);
28
+ }
29
+
30
+ return isValid;
31
+ }
@@ -46,27 +46,23 @@ function proxyXhr(userConfiguration) {
46
46
  dataflux_xhr.startTime = now();
47
47
  var originalSuccess = arguments[0].success;
48
48
 
49
- if (typeof originalSuccess === 'function') {
50
- arguments[0].success = function () {
51
- reportXhr(arguments[0]);
49
+ arguments[0].success = function () {
50
+ reportXhr(arguments[0]);
52
51
 
53
- if (originalSuccess) {
54
- originalSuccess.apply(_this, arguments);
55
- }
56
- };
57
- }
52
+ if (typeof originalSuccess === 'function') {
53
+ originalSuccess.apply(_this, arguments);
54
+ }
55
+ };
58
56
 
59
57
  var originalFail = arguments[0].fail;
60
58
 
61
- if (typeof originalFail === 'function') {
62
- arguments[0].fail = function () {
63
- reportXhr(arguments[0]);
59
+ arguments[0].fail = function () {
60
+ reportXhr(arguments[0]);
64
61
 
65
- if (originalFail) {
66
- originalFail.apply(_this, arguments);
67
- }
68
- };
69
- }
62
+ if (typeof originalFail === 'function') {
63
+ originalFail.apply(_this, arguments);
64
+ }
65
+ };
70
66
 
71
67
  var hasBeenReported = false;
72
68
 
@@ -92,7 +88,7 @@ function proxyXhr(userConfiguration) {
92
88
  var result = originalXhrRequest.call(this, dataflux_xhr.option); // 判断结果是否为promise
93
89
 
94
90
  var isPromise = function isPromise(obj) {
95
- return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
91
+ return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
96
92
  };
97
93
 
98
94
  if (isPromise(result) && userConfiguration.isVue2) {
@@ -0,0 +1,29 @@
1
+ export var ONE_KIBI_BYTE = 1024;
2
+ export var ONE_MEBI_BYTE = 1024 * ONE_KIBI_BYTE; // eslint-disable-next-line no-control-regex
3
+
4
+ var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
5
+ export function computeBytesCount(candidate) {
6
+ // Accurate byte size computations can degrade performances when there is a lot of events to process
7
+ if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {
8
+ return candidate.length;
9
+ }
10
+
11
+ var total = 0,
12
+ charCode; // utf-8编码
13
+
14
+ for (var i = 0, len = candidate.length; i < len; i++) {
15
+ charCode = candidate.charCodeAt(i);
16
+
17
+ if (charCode <= 0x007f) {
18
+ total += 1;
19
+ } else if (charCode <= 0x07ff) {
20
+ total += 2;
21
+ } else if (charCode <= 0xffff) {
22
+ total += 3;
23
+ } else {
24
+ total += 4;
25
+ }
26
+ }
27
+
28
+ return total;
29
+ }
@@ -0,0 +1,7 @@
1
+ export function buildCommonContext(globalContextManager, userContextManager) {
2
+ return {
3
+ context: globalContextManager.getContext(),
4
+ user: userContextManager.getContext() // hasReplay: recorderApi.isRecording() ? true : undefined,
5
+
6
+ };
7
+ }
@@ -0,0 +1,46 @@
1
+ import { noop } from './utils';
2
+ /**
3
+ * Custom implementation of JSON.stringify that ignores some toJSON methods. We need to do that
4
+ * because some sites badly override toJSON on certain objects. Removing all toJSON methods from
5
+ * nested values would be too costly, so we just detach them from the root value, and native classes
6
+ * used to build JSON values (Array and Object).
7
+ *
8
+ * Note: this still assumes that JSON.stringify is correct.
9
+ */
10
+
11
+ export function jsonStringify(value, replacer, space) {
12
+ if (typeof value !== 'object' || value === null) {
13
+ return JSON.stringify(value);
14
+ } // Note: The order matter here. We need to detach toJSON methods on parent classes before their
15
+ // subclasses.
16
+
17
+
18
+ var restoreObjectPrototypeToJson = detachToJsonMethod(Object.prototype);
19
+ var restoreArrayPrototypeToJson = detachToJsonMethod(Array.prototype);
20
+ var restoreValuePrototypeToJson = detachToJsonMethod(Object.getPrototypeOf(value));
21
+ var restoreValueToJson = detachToJsonMethod(value);
22
+
23
+ try {
24
+ return JSON.stringify(value, replacer, space);
25
+ } catch (error) {
26
+ return '<error: unable to serialize object>';
27
+ } finally {
28
+ restoreObjectPrototypeToJson();
29
+ restoreArrayPrototypeToJson();
30
+ restoreValuePrototypeToJson();
31
+ restoreValueToJson();
32
+ }
33
+ }
34
+ export function detachToJsonMethod(value) {
35
+ var object = value;
36
+ var objectToJson = object.toJSON;
37
+
38
+ if (objectToJson) {
39
+ delete object.toJSON;
40
+ return () => {
41
+ object.toJSON = objectToJson;
42
+ };
43
+ }
44
+
45
+ return noop;
46
+ }
@@ -81,6 +81,7 @@ export var report = function reportModuleWrapper() {
81
81
  installGlobalUnhandledRejectionHandler();
82
82
  installGlobalOnPageNotFoundHandler();
83
83
  installGlobalOnMemoryWarningHandler();
84
+ installGlobalOnLazyLoadErrorHandler();
84
85
  handlers.push(handler);
85
86
  }
86
87
  /**
@@ -128,7 +129,8 @@ export var report = function reportModuleWrapper() {
128
129
  var onErrorHandlerInstalled;
129
130
  var onUnhandledRejectionHandlerInstalled;
130
131
  var onPageNotFoundHandlerInstalled;
131
- var onOnMemoryWarningHandlerInstalled;
132
+ var onMemoryWarningHandlerInstalled;
133
+ var onLazyLoadErrorHandlerInstalled;
132
134
  /**
133
135
  * Ensures all global unhandled exceptions are recorded.
134
136
  * Supported by Gecko and IE.
@@ -261,7 +263,7 @@ export var report = function reportModuleWrapper() {
261
263
  }
262
264
 
263
265
  function installGlobalOnMemoryWarningHandler() {
264
- if (onOnMemoryWarningHandlerInstalled || !sdk.onMemoryWarning) {
266
+ if (onMemoryWarningHandlerInstalled || !sdk.onMemoryWarning) {
265
267
  return;
266
268
  }
267
269
 
@@ -294,7 +296,23 @@ export var report = function reportModuleWrapper() {
294
296
  name: '内存不足告警'
295
297
  }, true, {});
296
298
  });
297
- onOnMemoryWarningHandlerInstalled = true;
299
+ onMemoryWarningHandlerInstalled = true;
300
+ }
301
+
302
+ function installGlobalOnLazyLoadErrorHandler() {
303
+ if (onLazyLoadErrorHandlerInstalled || !sdk.onLazyLoadError) {
304
+ return;
305
+ }
306
+
307
+ sdk.onLazyLoadError(res => {
308
+ var subpackage = res.subpackage || [];
309
+ notifyHandlers({
310
+ message: res.errMsg || '',
311
+ type: 'lazyloaderror',
312
+ name: subpackage.join(',') + 'load error'
313
+ }, true, {});
314
+ });
315
+ onLazyLoadErrorHandlerInstalled = true;
298
316
  }
299
317
  /**
300
318
  * Reports an unhandled Error.
@@ -904,7 +922,7 @@ export var computeStackTrace = function computeStackTraceWrapper() {
904
922
  var ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;
905
923
 
906
924
  function extractMessage(ex) {
907
- var message = ex && ex.message;
925
+ var message = ex && ex.message; // console.log('message',message)
908
926
 
909
927
  if (!message) {
910
928
  return 'No error message';