@cloudcare/browser-core 1.0.11 → 1.0.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.
@@ -43,7 +43,11 @@ var DEFAULT_CONFIGURATION = {
43
43
  //是否开启交互action收集
44
44
  allowedDDTracingOrigins: [],
45
45
  //
46
- beforeSend: function beforeSend(event) {}
46
+ beforeSend: function beforeSend(event) {},
47
+ isServerError: function isServerError(request) {
48
+ return false;
49
+ } // 判断请求是否为error 请求
50
+
47
51
  };
48
52
  exports.DEFAULT_CONFIGURATION = DEFAULT_CONFIGURATION;
49
53
 
@@ -105,7 +109,11 @@ function commonInit(userConfiguration, buildEnv) {
105
109
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
106
110
  }
107
111
 
108
- return (0, _tools.extend2Lev)(DEFAULT_CONFIGURATION, transportConfiguration);
112
+ if ('isServerError' in userConfiguration && (0, _tools.isFunction)(userConfiguration.isServerError) && (0, _tools.isBoolean)(userConfiguration.isServerError())) {
113
+ transportConfiguration.isServerError = userConfiguration.isServerError;
114
+ }
115
+
116
+ return (0, _tools.extend2Lev)({}, DEFAULT_CONFIGURATION, transportConfiguration);
109
117
  }
110
118
 
111
119
  function mustUseSecureCookie(userConfiguration) {
@@ -113,7 +113,7 @@ function trackNetworkError(configuration, errorObservable) {
113
113
  });
114
114
 
115
115
  function handleCompleteRequest(type, request) {
116
- if (!(0, _configuration.isIntakeRequest)(request.url, configuration) && (!configuration.isEnabled('remove-network-errors') || !request.isAborted) && (isRejected(request) || isServerError(request))) {
116
+ if (!(0, _configuration.isIntakeRequest)(request.url, configuration) && !request.isAborted && (isRejected(request) || isServerError(request) || configuration.isServerError(request))) {
117
117
  errorObservable.notify({
118
118
  message: format(type) + ' error ' + request.method + ' ' + request.url,
119
119
  resource: {
package/cjs/xhrProxy.js CHANGED
@@ -85,6 +85,8 @@ function proxyXhr() {
85
85
  var hasBeenReported = false;
86
86
 
87
87
  var reportXhr = function reportXhr() {
88
+ _this.removeEventListener('loadend', reportXhr);
89
+
88
90
  if (hasBeenReported) {
89
91
  return;
90
92
  }
@@ -1,4 +1,4 @@
1
- import { ONE_KILO_BYTE, ONE_SECOND, extend2Lev, isArray, includes } from './helper/tools';
1
+ import { ONE_KILO_BYTE, ONE_SECOND, extend2Lev, isArray, includes, isFunction, isBoolean } from './helper/tools';
2
2
  import { getCurrentSite } from './cookie';
3
3
  import { haveSameOrigin } from './helper/urlPolyfill';
4
4
  var TRIM_REGIX = /^\s+|\s+$/g;
@@ -30,7 +30,11 @@ export var DEFAULT_CONFIGURATION = {
30
30
  //是否开启交互action收集
31
31
  allowedDDTracingOrigins: [],
32
32
  //
33
- beforeSend: function beforeSend(event) {}
33
+ beforeSend: function beforeSend(event) {},
34
+ isServerError: function isServerError(request) {
35
+ return false;
36
+ } // 判断请求是否为error 请求
37
+
34
38
  };
35
39
 
36
40
  function trim(str) {
@@ -91,7 +95,11 @@ export function commonInit(userConfiguration, buildEnv) {
91
95
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
92
96
  }
93
97
 
94
- return extend2Lev(DEFAULT_CONFIGURATION, transportConfiguration);
98
+ if ('isServerError' in userConfiguration && isFunction(userConfiguration.isServerError) && isBoolean(userConfiguration.isServerError())) {
99
+ transportConfiguration.isServerError = userConfiguration.isServerError;
100
+ }
101
+
102
+ return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration);
95
103
  }
96
104
 
97
105
  function mustUseSecureCookie(userConfiguration) {
@@ -87,7 +87,7 @@ export function trackNetworkError(configuration, errorObservable) {
87
87
  });
88
88
 
89
89
  function handleCompleteRequest(type, request) {
90
- if (!isIntakeRequest(request.url, configuration) && (!configuration.isEnabled('remove-network-errors') || !request.isAborted) && (isRejected(request) || isServerError(request))) {
90
+ if (!isIntakeRequest(request.url, configuration) && !request.isAborted && (isRejected(request) || isServerError(request) || configuration.isServerError(request))) {
91
91
  errorObservable.notify({
92
92
  message: format(type) + ' error ' + request.method + ' ' + request.url,
93
93
  resource: {
package/esm/xhrProxy.js CHANGED
@@ -73,6 +73,8 @@ function proxyXhr() {
73
73
  var hasBeenReported = false;
74
74
 
75
75
  var reportXhr = function reportXhr() {
76
+ _this.removeEventListener('loadend', reportXhr);
77
+
76
78
  if (hasBeenReported) {
77
79
  return;
78
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/browser-core",
3
- "version": "1.0.11",
3
+ "version": "1.0.15",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "scripts": {
@@ -20,5 +20,5 @@
20
20
  "author": "dataflux",
21
21
  "license": "MIT",
22
22
  "description": "DataFlux RUM Web 端数据指标监控",
23
- "gitHead": "ac9b2312dd535b5f0b8522a4ca1ad8eceac769b8"
23
+ "gitHead": "d8b3295bcb924ddd649b22ecffcf3ec6ccb4072d"
24
24
  }
@@ -3,7 +3,9 @@ import {
3
3
  ONE_SECOND,
4
4
  extend2Lev,
5
5
  isArray,
6
- includes
6
+ includes,
7
+ isFunction,
8
+ isBoolean
7
9
  } from './helper/tools'
8
10
  import { getCurrentSite } from './cookie'
9
11
  import { haveSameOrigin } from './helper/urlPolyfill'
@@ -32,7 +34,8 @@ export var DEFAULT_CONFIGURATION = {
32
34
  logsEndpoint: '',
33
35
  trackInteractions: false, //是否开启交互action收集
34
36
  allowedDDTracingOrigins: [], //
35
- beforeSend: function (event) {}
37
+ beforeSend: function (event) {},
38
+ isServerError: function(request) {return false} // 判断请求是否为error 请求
36
39
  }
37
40
  function trim(str) {
38
41
  return str.replace(TRIM_REGIX, '')
@@ -94,7 +97,10 @@ export function commonInit(userConfiguration, buildEnv) {
94
97
  if ('trackInteractions' in userConfiguration) {
95
98
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions
96
99
  }
97
- return extend2Lev(DEFAULT_CONFIGURATION, transportConfiguration)
100
+ if ('isServerError' in userConfiguration && isFunction(userConfiguration.isServerError) && isBoolean(userConfiguration.isServerError())) {
101
+ transportConfiguration.isServerError = userConfiguration.isServerError
102
+ }
103
+ return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration)
98
104
  }
99
105
  function mustUseSecureCookie(userConfiguration) {
100
106
  return (
@@ -108,9 +108,8 @@ export function trackNetworkError(configuration, errorObservable) {
108
108
  function handleCompleteRequest(type, request) {
109
109
  if (
110
110
  !isIntakeRequest(request.url, configuration) &&
111
- (!configuration.isEnabled('remove-network-errors') ||
112
- !request.isAborted) &&
113
- (isRejected(request) || isServerError(request))
111
+ !request.isAborted &&
112
+ (isRejected(request) || isServerError(request) || configuration.isServerError(request))
114
113
  ) {
115
114
  errorObservable.notify({
116
115
  message: format(type) + ' error ' + request.method + ' ' + request.url,
package/src/xhrProxy.js CHANGED
@@ -71,6 +71,7 @@ function proxyXhr() {
71
71
 
72
72
  var hasBeenReported = false
73
73
  var reportXhr = function () {
74
+ _this.removeEventListener('loadend', reportXhr)
74
75
  if (hasBeenReported) {
75
76
  return
76
77
  }
@@ -83,7 +84,6 @@ function proxyXhr() {
83
84
  response: _this.response,
84
85
  status: _this.status
85
86
  })
86
-
87
87
  each(onRequestCompleteCallbacks, function (callback) {
88
88
  callback(xhrCompleteContext, _this)
89
89
  })