@cloudcare/browser-core 2.0.17 → 3.0.22

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 (45) hide show
  1. package/cjs/dataMap.js +1 -0
  2. package/cjs/helper/byteUtils.js +33 -0
  3. package/cjs/helper/deviceInfo.js +23 -17
  4. package/cjs/helper/limitModification.js +1 -1
  5. package/cjs/helper/tools.js +0 -2
  6. package/cjs/init.js +4 -4
  7. package/cjs/tracekit/tracekit.js +34 -24
  8. package/cjs/transport/eventBridge.js +35 -0
  9. package/cjs/transport/httpRequest.js +1 -1
  10. package/cjs/transport/index.js +21 -1
  11. package/cjs/transport/sendWithRetryStrategy.js +9 -9
  12. package/cjs/user/user.js +0 -1
  13. package/cjs/worker.js +13 -0
  14. package/esm/dataMap.js +1 -0
  15. package/esm/helper/byteUtils.js +30 -0
  16. package/esm/helper/deviceInfo.js +23 -17
  17. package/esm/helper/limitModification.js +22 -5
  18. package/esm/helper/readBytesFromStream.js +1 -1
  19. package/esm/helper/sanitize.js +5 -3
  20. package/esm/helper/serialisation/jsonStringify.js +4 -2
  21. package/esm/helper/serialisation/rowData.js +4 -2
  22. package/esm/helper/tools.js +12 -12
  23. package/esm/init.js +10 -8
  24. package/esm/tracekit/computeStackTrace.js +3 -1
  25. package/esm/tracekit/tracekit.js +33 -24
  26. package/esm/transport/eventBridge.js +26 -0
  27. package/esm/transport/flushController.js +5 -7
  28. package/esm/transport/httpRequest.js +1 -1
  29. package/esm/transport/index.js +3 -2
  30. package/esm/transport/sendWithRetryStrategy.js +9 -9
  31. package/esm/user/user.js +0 -1
  32. package/esm/worker.js +1 -0
  33. package/package.json +2 -2
  34. package/src/dataMap.js +1 -0
  35. package/src/helper/byteUtils.js +12 -0
  36. package/src/helper/deviceInfo.js +24 -17
  37. package/src/helper/tools.js +0 -2
  38. package/src/init.js +4 -4
  39. package/src/tracekit/tracekit.js +31 -30
  40. package/src/transport/eventBridge.js +24 -0
  41. package/src/transport/httpRequest.js +1 -0
  42. package/src/transport/index.js +2 -1
  43. package/src/transport/sendWithRetryStrategy.js +17 -5
  44. package/src/user/user.js +0 -1
  45. package/src/worker.js +1 -0
@@ -1,10 +1,10 @@
1
1
  import { instrumentMethodAndCallOriginal } from '../helper/instrumentMethod'
2
+ import { isNullUndefinedDefaultValue } from '../helper/tools'
2
3
  import { computeStackTrace } from './computeStackTrace'
3
4
 
4
5
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types
5
6
  var ERROR_TYPES_RE =
6
- /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/
7
-
7
+ /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?([\s\S]*)$/
8
8
  /**
9
9
  * Cross-browser collection of unhandled errors
10
10
  *
@@ -41,10 +41,10 @@ export function startUnhandledErrorCollection(callback) {
41
41
  var _instrumentOnError = instrumentOnError(callback)
42
42
  var _instrumentUnhandledRejection = instrumentUnhandledRejection(callback)
43
43
  return {
44
- stop: function() {
44
+ stop: function () {
45
45
  _instrumentOnError.stop()
46
46
  _instrumentUnhandledRejection.stop()
47
- },
47
+ }
48
48
  }
49
49
  }
50
50
 
@@ -53,48 +53,49 @@ export function startUnhandledErrorCollection(callback) {
53
53
  */
54
54
  function instrumentOnError(callback) {
55
55
  return instrumentMethodAndCallOriginal(window, 'onerror', {
56
- before: function(message, url, lineNo, columnNo, errorObj) {
57
- var stack
58
- if (errorObj) {
59
- stack = computeStackTrace(errorObj)
60
- callback(stack, errorObj)
56
+ before: function (messageObj, url, line, column, errorObj) {
57
+ var stackTrace
58
+ if (errorObj instanceof Error) {
59
+ stackTrace = computeStackTrace(errorObj)
61
60
  } else {
62
61
  var location = {
63
62
  url: url,
64
- column: columnNo,
65
- line: lineNo,
66
- }
67
- var name
68
- var msg = message
69
- if ({}.toString.call(message) === '[object String]') {
70
- var groups = ERROR_TYPES_RE.exec(msg)
71
- if (groups) {
72
- name = groups[1]
73
- msg = groups[2]
74
- }
63
+ column: column,
64
+ line: line
75
65
  }
66
+ var parse = tryToParseMessage(messageObj)
76
67
 
77
- stack = {
78
- name: name,
79
- message: typeof msg === 'string' ? msg : undefined,
80
- stack: [location],
68
+ stackTrace = {
69
+ name: parse.name,
70
+ message: parse.message,
71
+ stack: [location]
81
72
  }
82
-
83
- callback(stack, message)
84
73
  }
85
- },
74
+ callback(stackTrace, isNullUndefinedDefaultValue(errorObj, messageObj))
75
+ }
86
76
  })
87
77
  }
88
-
78
+ function tryToParseMessage(messageObj) {
79
+ let name
80
+ let message
81
+ if ({}.toString.call(messageObj) === '[object String]') {
82
+ var groups = ERROR_TYPES_RE.exec(messageObj)
83
+ if (groups) {
84
+ name = groups[1]
85
+ message = groups[2]
86
+ }
87
+ }
88
+ return { name: name, message: message }
89
+ }
89
90
  /**
90
91
  * Install a global onunhandledrejection handler
91
92
  */
92
93
  function instrumentUnhandledRejection(callback) {
93
94
  return instrumentMethodAndCallOriginal(window, 'onunhandledrejection', {
94
- before: function(e) {
95
+ before: function (e) {
95
96
  var reason = e.reason || 'Empty reason'
96
97
  var stack = computeStackTrace(reason)
97
98
  callback(stack, reason)
98
- },
99
+ }
99
100
  })
100
101
  }
@@ -0,0 +1,24 @@
1
+ import { getGlobalObject } from '../init'
2
+
3
+ function getEventBridgeGlobal() {
4
+ return getGlobalObject().FTWebViewJavascriptBridge
5
+ }
6
+ export function getEventBridge() {
7
+ var eventBridgeGlobal = getEventBridgeGlobal()
8
+
9
+ if (!eventBridgeGlobal) {
10
+ return
11
+ }
12
+
13
+ return {
14
+ send(eventType, event) {
15
+ eventBridgeGlobal.sendEvent(
16
+ JSON.stringify({ name: eventType, data: event })
17
+ )
18
+ }
19
+ }
20
+ }
21
+ export function canUseEventBridge() {
22
+ var bridge = getEventBridge()
23
+ return !!bridge
24
+ }
@@ -24,6 +24,7 @@ export function createHttpRequest(endpointUrl, bytesLimit, reportError) {
24
24
  payload,
25
25
  retryState,
26
26
  sendStrategyForRetry,
27
+ endpointUrl,
27
28
  reportError
28
29
  )
29
30
  },
@@ -1,4 +1,5 @@
1
1
  export { createHttpRequest } from './httpRequest'
2
- export { Batch } from './batch'
2
+ export { Batch, processedMessageByDataMap } from './batch'
3
3
  export { startBatchWithReplica } from './startBatchWithReplica'
4
4
  export { createFlushController } from './flushController'
5
+ export { getEventBridge, canUseEventBridge } from './eventBridge'
@@ -23,6 +23,7 @@ export function sendWithRetryStrategy(
23
23
  payload,
24
24
  state,
25
25
  sendStrategy,
26
+ endpointUrl,
26
27
  reportError
27
28
  ) {
28
29
  if (
@@ -36,12 +37,13 @@ export function sendWithRetryStrategy(
36
37
  RetryReason.AFTER_SUCCESS,
37
38
  state,
38
39
  sendStrategy,
40
+ endpointUrl,
39
41
  reportError
40
42
  )
41
43
  },
42
44
  onFailure: function () {
43
45
  state.queuedPayloads.enqueue(payload)
44
- scheduleRetry(state, sendStrategy, reportError)
46
+ scheduleRetry(state, sendStrategy, endpointUrl, reportError)
45
47
  }
46
48
  })
47
49
  } else {
@@ -49,7 +51,7 @@ export function sendWithRetryStrategy(
49
51
  }
50
52
  }
51
53
 
52
- function scheduleRetry(state, sendStrategy, reportError) {
54
+ function scheduleRetry(state, sendStrategy, endpointUrl, reportError) {
53
55
  if (state.transportStatus !== TransportStatus.DOWN) {
54
56
  return
55
57
  }
@@ -68,6 +70,7 @@ function scheduleRetry(state, sendStrategy, reportError) {
68
70
  RetryReason.AFTER_RESUME,
69
71
  state,
70
72
  sendStrategy,
73
+ endpointUrl,
71
74
  reportError
72
75
  )
73
76
  },
@@ -76,7 +79,7 @@ function scheduleRetry(state, sendStrategy, reportError) {
76
79
  MAX_BACKOFF_TIME,
77
80
  state.currentBackoffTime * 2
78
81
  )
79
- scheduleRetry(state, sendStrategy, reportError)
82
+ scheduleRetry(state, sendStrategy, endpointUrl, reportError)
80
83
  }
81
84
  })
82
85
  }, state.currentBackoffTime)
@@ -103,7 +106,13 @@ function send(payload, state, sendStrategy, responseData) {
103
106
  })
104
107
  }
105
108
 
106
- function retryQueuedPayloads(reason, state, sendStrategy, reportError) {
109
+ function retryQueuedPayloads(
110
+ reason,
111
+ state,
112
+ sendStrategy,
113
+ endpointUrl,
114
+ reportError
115
+ ) {
107
116
  if (
108
117
  reason === RetryReason.AFTER_SUCCESS &&
109
118
  state.queuedPayloads.isFull() &&
@@ -111,7 +120,9 @@ function retryQueuedPayloads(reason, state, sendStrategy, reportError) {
111
120
  ) {
112
121
  reportError({
113
122
  message:
114
- 'Reached max events size queued for upload: ' +
123
+ 'Reached max ' +
124
+ endpointUrl +
125
+ ' events size queued for upload: ' +
115
126
  MAX_QUEUE_BYTES_COUNT / ONE_MEBI_BYTE +
116
127
  'MiB',
117
128
  source: ErrorSource.AGENT,
@@ -126,6 +137,7 @@ function retryQueuedPayloads(reason, state, sendStrategy, reportError) {
126
137
  previousQueue.dequeue(),
127
138
  state,
128
139
  sendStrategy,
140
+ endpointUrl,
129
141
  reportError
130
142
  )
131
143
  }
package/src/user/user.js CHANGED
@@ -4,7 +4,6 @@ import { assign, getType, each } from '../helper/tools'
4
4
  /**
5
5
  * Clone input data and ensure known user properties (id, name, email)
6
6
  * are strings, as defined here:
7
- * https://docs.datadoghq.com/logs/log_configuration/attributes_naming_convention/#user-related-attributes
8
7
  */
9
8
  export function sanitizeUser(newUser) {
10
9
  // We shallow clone only to prevent mutation of user data.
package/src/worker.js ADDED
@@ -0,0 +1 @@
1
+ export { concatBuffers } from './helper/byteUtils'