@cloudcare/browser-core 3.0.22 → 3.0.29

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 (47) hide show
  1. package/cjs/browser/addEventListener.js +9 -7
  2. package/cjs/browser/fetchObservable.js +5 -3
  3. package/cjs/console/consoleObservable.js +5 -1
  4. package/cjs/dataMap.js +5 -1
  5. package/cjs/helper/errorTools.js +7 -3
  6. package/cjs/helper/instrumentMethod.js +4 -2
  7. package/cjs/helper/monitor.js +59 -0
  8. package/cjs/helper/readBytesFromStream.js +5 -3
  9. package/cjs/helper/timer.js +4 -2
  10. package/cjs/helper/tools.js +2 -20
  11. package/cjs/index.js +13 -0
  12. package/cjs/init.js +13 -19
  13. package/cjs/report/reportObservable.js +4 -3
  14. package/cjs/transport/batch.js +2 -2
  15. package/cjs/transport/httpRequest.js +5 -3
  16. package/esm/browser/addEventListener.js +8 -7
  17. package/esm/browser/fetchObservable.js +4 -3
  18. package/esm/console/consoleObservable.js +4 -1
  19. package/esm/dataMap.js +5 -1
  20. package/esm/helper/errorTools.js +6 -3
  21. package/esm/helper/instrumentMethod.js +3 -2
  22. package/esm/helper/monitor.js +40 -0
  23. package/esm/helper/readBytesFromStream.js +4 -3
  24. package/esm/helper/timer.js +3 -2
  25. package/esm/helper/tools.js +2 -18
  26. package/esm/index.js +1 -0
  27. package/esm/init.js +12 -18
  28. package/esm/report/reportObservable.js +3 -3
  29. package/esm/transport/batch.js +2 -2
  30. package/esm/transport/httpRequest.js +4 -3
  31. package/package.json +2 -2
  32. package/src/browser/addEventListener.js +8 -7
  33. package/src/browser/fetchObservable.js +12 -3
  34. package/src/console/consoleObservable.js +4 -2
  35. package/src/dataMap.js +6 -1
  36. package/src/helper/errorTools.js +6 -5
  37. package/src/helper/instrumentMethod.js +5 -2
  38. package/src/helper/monitor.js +44 -0
  39. package/src/helper/observable.js +10 -8
  40. package/src/helper/readBytesFromStream.js +5 -5
  41. package/src/helper/timer.js +3 -3
  42. package/src/helper/tools.js +1 -17
  43. package/src/index.js +1 -0
  44. package/src/init.js +19 -21
  45. package/src/report/reportObservable.js +3 -2
  46. package/src/transport/batch.js +4 -4
  47. package/src/transport/httpRequest.js +5 -4
package/src/init.js CHANGED
@@ -1,27 +1,25 @@
1
- import { extend, each } from './helper/tools'
2
- export function makeGlobal(stub) {
3
- var global = extend({}, stub, {
4
- onReady: function (callback) {
5
- callback()
6
- }
7
- })
8
- return global
9
- }
1
+ import { each, assign } from './helper/tools'
2
+ import { setDebugMode } from './helper/monitor'
3
+ import { catchUserErrors } from './helper/catchUserErrors'
4
+
10
5
  export function makePublicApi(stub) {
11
- var publicApi = extend({}, stub, {
12
- onReady: function (callback) {
13
- callback()
14
- }
15
- })
6
+ var publicApi = assign(
7
+ {
8
+ onReady: function (callback) {
9
+ callback()
10
+ }
11
+ },
12
+ stub
13
+ )
16
14
 
17
15
  // Add an "hidden" property to set debug mode. We define it that way to hide it
18
16
  // as much as possible but of course it's not a real protection.
19
- // Object.defineProperty(publicApi, '_setDebug', {
20
- // get: function () {
21
- // return setDebugMode
22
- // },
23
- // enumerable: false
24
- // })
17
+ Object.defineProperty(publicApi, '_setDebug', {
18
+ get: function () {
19
+ return setDebugMode
20
+ },
21
+ enumerable: false
22
+ })
25
23
 
26
24
  return publicApi
27
25
  }
@@ -30,7 +28,7 @@ export function defineGlobal(global, name, api) {
30
28
  global[name] = api
31
29
  if (existingGlobalVariable && existingGlobalVariable.q) {
32
30
  each(existingGlobalVariable.q, function (fn) {
33
- fn()
31
+ catchUserErrors(fn, 'onReady callback threw an error:')()
34
32
  })
35
33
  }
36
34
  }
@@ -3,6 +3,7 @@ import { mergeObservables, Observable } from '../helper/observable'
3
3
  import { includes, safeTruncate, filter, each } from '../helper/tools'
4
4
  import { addEventListener } from '../browser/addEventListener'
5
5
  import { DOM_EVENT } from '../helper/enums'
6
+ import { monitor } from '../helper/monitor'
6
7
  export var RawReportType = {
7
8
  intervention: 'intervention',
8
9
  deprecation: 'deprecation',
@@ -30,11 +31,11 @@ function createReportObservable(reportTypes) {
30
31
  return
31
32
  }
32
33
 
33
- var handleReports = function (reports) {
34
+ var handleReports = monitor(function (reports) {
34
35
  each(reports, function (report) {
35
36
  observable.notify(buildRawReportFromReport(report))
36
37
  })
37
- }
38
+ })
38
39
 
39
40
  var observer = new window.ReportingObserver(handleReports, {
40
41
  types: reportTypes,
@@ -76,13 +76,13 @@ export var processedMessageByDataMap = function (message) {
76
76
  }
77
77
  })
78
78
  if (
79
- message.tags &&
80
- isObject(message.tags) &&
81
- !isEmptyObject(message.tags)
79
+ message.context &&
80
+ isObject(message.context) &&
81
+ !isEmptyObject(message.context)
82
82
  ) {
83
83
  // 自定义tag, 存储成field
84
84
  var _tagKeys = []
85
- each(message.tags, function (_value, _key) {
85
+ each(message.context, function (_value, _key) {
86
86
  // 如果和之前tag重名,则舍弃
87
87
  if (filterFileds.indexOf(_key) > -1) return
88
88
  filterFileds.push(_key)
@@ -1,5 +1,6 @@
1
1
  import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'
2
2
  import { addEventListener } from '../browser/addEventListener'
3
+ import { monitor } from '../helper/monitor'
3
4
  /**
4
5
  * Use POST request without content type to:
5
6
  * - avoid CORS preflight requests
@@ -74,15 +75,15 @@ export function fetchKeepAliveStrategy(
74
75
  keepalive: true,
75
76
  mode: 'cors'
76
77
  }).then(
77
- function (response) {
78
+ monitor(function (response) {
78
79
  if (typeof onResponse === 'function') {
79
80
  onResponse({ status: response.status, type: response.type })
80
81
  }
81
- },
82
- function () {
82
+ }),
83
+ monitor(function () {
83
84
  // failed to queue the request
84
85
  sendXHR(url, data, onResponse)
85
- }
86
+ })
86
87
  )
87
88
  } else {
88
89
  sendXHR(url, data, onResponse)