@cloudcare/browser-core 1.1.1 → 1.1.3

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.
@@ -57,7 +57,11 @@ var DEFAULT_CONFIGURATION = {
57
57
  beforeSend: function beforeSend(event) {},
58
58
  isServerError: function isServerError(request) {
59
59
  return false;
60
- } // 判断请求是否为error 请求
60
+ },
61
+ // 判断请求是否为error 请求
62
+ isIntakeUrl: function isIntakeUrl(url) {
63
+ return false;
64
+ } // 自定义方法根据请求资源 url 判断是否需要采集对应资源数据,默认都采集。 返回:false 表示要采集,true 表示不需要采集
61
65
 
62
66
  };
63
67
  exports.DEFAULT_CONFIGURATION = DEFAULT_CONFIGURATION;
@@ -137,6 +141,10 @@ function commonInit(userConfiguration, buildEnv) {
137
141
  transportConfiguration.isServerError = userConfiguration.isServerError;
138
142
  }
139
143
 
144
+ if ('isIntakeUrl' in userConfiguration && (0, _tools.isFunction)(userConfiguration.isIntakeUrl) && (0, _tools.isBoolean)(userConfiguration.isIntakeUrl())) {
145
+ transportConfiguration.isIntakeUrl = userConfiguration.isIntakeUrl;
146
+ }
147
+
140
148
  if ('traceId128Bit' in userConfiguration) {
141
149
  transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit;
142
150
  }
@@ -178,7 +186,8 @@ function isIntakeRequest(url, configuration) {
178
186
  isIntake = true;
179
187
  break;
180
188
  }
181
- }
189
+ } // datakit 地址,log 地址,以及客户自定义过滤方法定义url
190
+
182
191
 
183
- return isIntake;
192
+ return isIntake || configuration.isIntakeUrl(url);
184
193
  }
package/cjs/fetchProxy.js CHANGED
@@ -80,7 +80,6 @@ function beforeSend(input, init) {
80
80
  init: init,
81
81
  input: input,
82
82
  method: method,
83
- startTime: (0, _tools.relativeNow)(),
84
83
  startClocks: startClocks,
85
84
  url: url
86
85
  };
@@ -98,7 +97,7 @@ function afterSend(responsePromise, context) {
98
97
  while (1) {
99
98
  switch (_context.prev = _context.next) {
100
99
  case 0:
101
- context.duration = (0, _tools.elapsed)(context.startClocks.relative, (0, _tools.relativeNow)());
100
+ context.duration = (0, _tools.elapsed)(context.startClocks.timeStamp, (0, _tools.timeStampNow)());
102
101
 
103
102
  if (!('stack' in response || response instanceof Error)) {
104
103
  _context.next = 9;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ONE_SECOND = exports.ONE_MINUTE = exports.ONE_KILO_BYTE = exports.ONE_HOUR = void 0;
6
+ exports.ONE_YEAR = exports.ONE_SECOND = exports.ONE_MINUTE = exports.ONE_KILO_BYTE = exports.ONE_HOUR = exports.ONE_DAY = void 0;
7
7
  exports.UUID = UUID;
8
8
  exports.addEvent = exports._URL = void 0;
9
9
  exports.addEventListener = addEventListener;
@@ -15,6 +15,7 @@ exports.clocksNow = clocksNow;
15
15
  exports.clocksOrigin = clocksOrigin;
16
16
  exports.coverExtend = exports.cookie = void 0;
17
17
  exports.createContextManager = createContextManager;
18
+ exports.dateNow = dateNow;
18
19
  exports.decodeURIComponent = void 0;
19
20
  exports.deepClone = deepClone;
20
21
  exports.deepSnakeCase = deepSnakeCase;
@@ -45,7 +46,9 @@ exports.isObject = exports.isNumber = exports.isJSONString = exports.isFunction
45
46
  exports.isPercentage = isPercentage;
46
47
  exports.isUndefined = exports.isSupportCors = exports.isString = void 0;
47
48
  exports.jsonStringify = jsonStringify;
48
- exports.map = exports.localStorage = exports.loadScript = exports.keys = void 0;
49
+ exports.localStorage = exports.loadScript = exports.keys = void 0;
50
+ exports.looksLikeRelativeTime = looksLikeRelativeTime;
51
+ exports.map = void 0;
49
52
  exports.mapValues = mapValues;
50
53
  exports.mediaQueriesSupported = void 0;
51
54
  exports.mergeInto = mergeInto;
@@ -62,10 +65,10 @@ exports.replaceNumberCharByPath = replaceNumberCharByPath;
62
65
  exports.round = round;
63
66
  exports.safeJSONParse = void 0;
64
67
  exports.safeTruncate = safeTruncate;
65
- exports.sessionStorage = exports.searchObjString = exports.searchObjDate = exports.searchConfigData = void 0;
68
+ exports.searchObjDate = exports.searchConfigData = void 0;
69
+ exports.sessionStorage = exports.searchObjString = void 0;
66
70
  exports.shallowClone = shallowClone;
67
- exports.strToUnicode = void 0;
68
- exports.throttle = exports.strip_sa_properties = exports.strip_empty_properties = exports.stringSplice = void 0;
71
+ exports.throttle = exports.strip_sa_properties = exports.strip_empty_properties = exports.stringSplice = exports.strToUnicode = void 0;
69
72
  exports.timeStampNow = timeStampNow;
70
73
  exports.toArray = exports.tirm = void 0;
71
74
  exports.toServerDuration = toServerDuration;
@@ -1770,6 +1773,10 @@ var ONE_MINUTE = 60 * ONE_SECOND;
1770
1773
  exports.ONE_MINUTE = ONE_MINUTE;
1771
1774
  var ONE_HOUR = 60 * ONE_MINUTE;
1772
1775
  exports.ONE_HOUR = ONE_HOUR;
1776
+ var ONE_DAY = 24 * ONE_HOUR;
1777
+ exports.ONE_DAY = ONE_DAY;
1778
+ var ONE_YEAR = 365 * ONE_DAY;
1779
+ exports.ONE_YEAR = ONE_YEAR;
1773
1780
  var ONE_KILO_BYTE = 1024;
1774
1781
  /**
1775
1782
  * Return true if the draw is successful
@@ -1819,7 +1826,7 @@ function preferredNow() {
1819
1826
  }
1820
1827
 
1821
1828
  function getTimestamp(relativeTime) {
1822
- return Math.floor(getNavigationStart() + relativeTime);
1829
+ return Math.round(getNavigationStart() + relativeTime);
1823
1830
  }
1824
1831
 
1825
1832
  function relativeNow() {
@@ -1834,7 +1841,20 @@ function clocksNow() {
1834
1841
  }
1835
1842
 
1836
1843
  function timeStampNow() {
1837
- return Date.now();
1844
+ return dateNow();
1845
+ }
1846
+
1847
+ function looksLikeRelativeTime(time) {
1848
+ return time < ONE_YEAR;
1849
+ }
1850
+
1851
+ function dateNow() {
1852
+ // Do not use `Date.now` because sometimes websites are wrongly "polyfilling" it. For example, we
1853
+ // had some users using a very old version of `datejs`, which patched `Date.now` to return a Date
1854
+ // instance instead of a timestamp[1]. Those users are unlikely to fix this, so let's handle this
1855
+ // case ourselves.
1856
+ // [1]: https://github.com/datejs/Datejs/blob/97f5c7c58c5bc5accdab8aa7602b6ac56462d778/src/core-debug.js#L14-L16
1857
+ return new Date().getTime();
1838
1858
  }
1839
1859
 
1840
1860
  function elapsed(start, end) {
@@ -1859,9 +1879,19 @@ function preferredTimeStamp(clocks) {
1859
1879
  function relativeToClocks(relative) {
1860
1880
  return {
1861
1881
  relative: relative,
1862
- timeStamp: getTimestamp(relative)
1882
+ timeStamp: getCorrectedTimeStamp(relative)
1863
1883
  };
1864
1884
  }
1885
+
1886
+ function getCorrectedTimeStamp(relativeTime) {
1887
+ var correctedOrigin = dateNow() - performance.now(); // apply correction only for positive drift
1888
+
1889
+ if (correctedOrigin > getNavigationStart()) {
1890
+ return Math.round(correctedOrigin + relativeTime);
1891
+ }
1892
+
1893
+ return getTimestamp(relativeTime);
1894
+ }
1865
1895
  /**
1866
1896
  * Navigation start slightly change on some rare cases
1867
1897
  */
package/cjs/xhrProxy.js CHANGED
@@ -93,7 +93,7 @@ function proxyXhr() {
93
93
 
94
94
  hasBeenReported = true;
95
95
  var xhrCompleteContext = (0, _tools.extend)({}, xhrPendingContext, {
96
- duration: (0, _tools.elapsed)(xhrPendingContext.startClocks.relative, (0, _tools.relativeNow)()),
96
+ duration: (0, _tools.elapsed)(xhrPendingContext.startClocks.timeStamp, (0, _tools.timeStampNow)()),
97
97
  response: _this.response,
98
98
  status: _this.status
99
99
  });
@@ -43,7 +43,11 @@ export var DEFAULT_CONFIGURATION = {
43
43
  beforeSend: function beforeSend(event) {},
44
44
  isServerError: function isServerError(request) {
45
45
  return false;
46
- } // 判断请求是否为error 请求
46
+ },
47
+ // 判断请求是否为error 请求
48
+ isIntakeUrl: function isIntakeUrl(url) {
49
+ return false;
50
+ } // 自定义方法根据请求资源 url 判断是否需要采集对应资源数据,默认都采集。 返回:false 表示要采集,true 表示不需要采集
47
51
 
48
52
  };
49
53
 
@@ -122,6 +126,10 @@ export function commonInit(userConfiguration, buildEnv) {
122
126
  transportConfiguration.isServerError = userConfiguration.isServerError;
123
127
  }
124
128
 
129
+ if ('isIntakeUrl' in userConfiguration && isFunction(userConfiguration.isIntakeUrl) && isBoolean(userConfiguration.isIntakeUrl())) {
130
+ transportConfiguration.isIntakeUrl = userConfiguration.isIntakeUrl;
131
+ }
132
+
125
133
  if ('traceId128Bit' in userConfiguration) {
126
134
  transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit;
127
135
  }
@@ -161,7 +169,8 @@ export function isIntakeRequest(url, configuration) {
161
169
  isIntake = true;
162
170
  break;
163
171
  }
164
- }
172
+ } // datakit 地址,log 地址,以及客户自定义过滤方法定义url
173
+
165
174
 
166
- return isIntake;
175
+ return isIntake || configuration.isIntakeUrl(url);
167
176
  }
package/esm/fetchProxy.js CHANGED
@@ -2,7 +2,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
2
2
 
3
3
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
4
 
5
- import { each, relativeNow, clocksNow, elapsed } from './helper/tools';
5
+ import { each, timeStampNow, clocksNow, elapsed } from './helper/tools';
6
6
  import { computeStackTrace } from './tracekit';
7
7
  import { toStackTraceString } from './helper/errorTools';
8
8
  import { normalizeUrl } from './helper/urlPolyfill';
@@ -64,7 +64,6 @@ function beforeSend(input, init) {
64
64
  init: init,
65
65
  input: input,
66
66
  method: method,
67
- startTime: relativeNow(),
68
67
  startClocks: startClocks,
69
68
  url: url
70
69
  };
@@ -77,7 +76,7 @@ function beforeSend(input, init) {
77
76
  function afterSend(responsePromise, context) {
78
77
  var reportFetch = /*#__PURE__*/function () {
79
78
  var _ref = _asyncToGenerator(function* (response) {
80
- context.duration = elapsed(context.startClocks.relative, relativeNow());
79
+ context.duration = elapsed(context.startClocks.timeStamp, timeStampNow());
81
80
 
82
81
  if ('stack' in response || response instanceof Error) {
83
82
  context.status = 0;
@@ -1487,6 +1487,8 @@ export function noop() {}
1487
1487
  export var ONE_SECOND = 1000;
1488
1488
  export var ONE_MINUTE = 60 * ONE_SECOND;
1489
1489
  export var ONE_HOUR = 60 * ONE_MINUTE;
1490
+ export var ONE_DAY = 24 * ONE_HOUR;
1491
+ export var ONE_YEAR = 365 * ONE_DAY;
1490
1492
  export var ONE_KILO_BYTE = 1024;
1491
1493
  /**
1492
1494
  * Return true if the draw is successful
@@ -1527,7 +1529,7 @@ export function preferredNow() {
1527
1529
  return relativeNow();
1528
1530
  }
1529
1531
  export function getTimestamp(relativeTime) {
1530
- return Math.floor(getNavigationStart() + relativeTime);
1532
+ return Math.round(getNavigationStart() + relativeTime);
1531
1533
  }
1532
1534
  export function relativeNow() {
1533
1535
  return performance.now();
@@ -1539,7 +1541,18 @@ export function clocksNow() {
1539
1541
  };
1540
1542
  }
1541
1543
  export function timeStampNow() {
1542
- return Date.now();
1544
+ return dateNow();
1545
+ }
1546
+ export function looksLikeRelativeTime(time) {
1547
+ return time < ONE_YEAR;
1548
+ }
1549
+ export function dateNow() {
1550
+ // Do not use `Date.now` because sometimes websites are wrongly "polyfilling" it. For example, we
1551
+ // had some users using a very old version of `datejs`, which patched `Date.now` to return a Date
1552
+ // instance instead of a timestamp[1]. Those users are unlikely to fix this, so let's handle this
1553
+ // case ourselves.
1554
+ // [1]: https://github.com/datejs/Datejs/blob/97f5c7c58c5bc5accdab8aa7602b6ac56462d778/src/core-debug.js#L14-L16
1555
+ return new Date().getTime();
1543
1556
  }
1544
1557
  export function elapsed(start, end) {
1545
1558
  return end - start;
@@ -1559,13 +1572,24 @@ export function preferredTimeStamp(clocks) {
1559
1572
  export function relativeToClocks(relative) {
1560
1573
  return {
1561
1574
  relative: relative,
1562
- timeStamp: getTimestamp(relative)
1575
+ timeStamp: getCorrectedTimeStamp(relative)
1563
1576
  };
1564
1577
  }
1578
+
1579
+ function getCorrectedTimeStamp(relativeTime) {
1580
+ var correctedOrigin = dateNow() - performance.now(); // apply correction only for positive drift
1581
+
1582
+ if (correctedOrigin > getNavigationStart()) {
1583
+ return Math.round(correctedOrigin + relativeTime);
1584
+ }
1585
+
1586
+ return getTimestamp(relativeTime);
1587
+ }
1565
1588
  /**
1566
1589
  * Navigation start slightly change on some rare cases
1567
1590
  */
1568
1591
 
1592
+
1569
1593
  var navigationStart;
1570
1594
  export function getNavigationStart() {
1571
1595
  if (navigationStart === undefined) {
package/esm/xhrProxy.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { normalizeUrl } from './helper/urlPolyfill';
2
- import { each, relativeNow, clocksNow, elapsed, extend } from './helper/tools';
2
+ import { each, relativeNow, clocksNow, elapsed, extend, timeStampNow } from './helper/tools';
3
3
  var xhrProxySingleton;
4
4
  var beforeSendCallbacks = [];
5
5
  var onRequestCompleteCallbacks = [];
@@ -81,7 +81,7 @@ function proxyXhr() {
81
81
 
82
82
  hasBeenReported = true;
83
83
  var xhrCompleteContext = extend({}, xhrPendingContext, {
84
- duration: elapsed(xhrPendingContext.startClocks.relative, relativeNow()),
84
+ duration: elapsed(xhrPendingContext.startClocks.timeStamp, timeStampNow()),
85
85
  response: _this.response,
86
86
  status: _this.status
87
87
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/browser-core",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
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": "6637896a7d66c35f8b37da75b14d234d049c79d5"
23
+ "gitHead": "8cd2d38961b7663bde39072730de22bcf4ba9c2b"
24
24
  }
@@ -43,7 +43,8 @@ export var DEFAULT_CONFIGURATION = {
43
43
  isJsBirdge: false,// 是否需要对webview 发送数据,需要装我们对应ios sdk
44
44
  isLineProtocolToJson: false,
45
45
  beforeSend: function (event) {},
46
- isServerError: function(request) {return false} // 判断请求是否为error 请求
46
+ isServerError: function(request) {return false}, // 判断请求是否为error 请求
47
+ isIntakeUrl: function(url) { return false } // 自定义方法根据请求资源 url 判断是否需要采集对应资源数据,默认都采集。 返回:false 表示要采集,true 表示不需要采集
47
48
  }
48
49
  function trim(str) {
49
50
  return str.replace(TRIM_REGIX, '')
@@ -117,6 +118,9 @@ export function commonInit(userConfiguration, buildEnv) {
117
118
  if ('isServerError' in userConfiguration && isFunction(userConfiguration.isServerError) && isBoolean(userConfiguration.isServerError())) {
118
119
  transportConfiguration.isServerError = userConfiguration.isServerError
119
120
  }
121
+ if ('isIntakeUrl' in userConfiguration && isFunction(userConfiguration.isIntakeUrl) && isBoolean(userConfiguration.isIntakeUrl())) {
122
+ transportConfiguration.isIntakeUrl = userConfiguration.isIntakeUrl
123
+ }
120
124
  if ('traceId128Bit' in userConfiguration) {
121
125
  transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit
122
126
  }
@@ -152,5 +156,6 @@ export function isIntakeRequest(url, configuration) {
152
156
  break;
153
157
  }
154
158
  }
155
- return isIntake
159
+ // datakit 地址,log 地址,以及客户自定义过滤方法定义url
160
+ return isIntake || configuration.isIntakeUrl(url)
156
161
  }
package/src/fetchProxy.js CHANGED
@@ -1,4 +1,4 @@
1
- import { each, relativeNow, clocksNow, elapsed } from './helper/tools'
1
+ import { each, timeStampNow, clocksNow, elapsed } from './helper/tools'
2
2
  import { computeStackTrace } from './tracekit'
3
3
  import { toStackTraceString } from './helper/errorTools'
4
4
  import { normalizeUrl } from './helper/urlPolyfill'
@@ -63,7 +63,6 @@ function beforeSend(input, init) {
63
63
  init: init,
64
64
  input: input,
65
65
  method: method,
66
- startTime: relativeNow(),
67
66
  startClocks: startClocks,
68
67
  url: url
69
68
  }
@@ -76,7 +75,7 @@ function beforeSend(input, init) {
76
75
 
77
76
  function afterSend(responsePromise, context) {
78
77
  var reportFetch = async function (response) {
79
- context.duration = elapsed(context.startClocks.relative, relativeNow())
78
+ context.duration = elapsed(context.startClocks.timeStamp, timeStampNow())
80
79
 
81
80
  if ('stack' in response || response instanceof Error) {
82
81
  context.status = 0
@@ -1463,6 +1463,8 @@ export function noop() {}
1463
1463
  export var ONE_SECOND = 1000
1464
1464
  export var ONE_MINUTE = 60 * ONE_SECOND
1465
1465
  export var ONE_HOUR = 60 * ONE_MINUTE
1466
+ export var ONE_DAY = 24 * ONE_HOUR
1467
+ export var ONE_YEAR = 365 * ONE_DAY
1466
1468
  export var ONE_KILO_BYTE = 1024
1467
1469
  /**
1468
1470
  * Return true if the draw is successful
@@ -1504,7 +1506,7 @@ export function preferredNow() {
1504
1506
  return relativeNow()
1505
1507
  }
1506
1508
  export function getTimestamp(relativeTime) {
1507
- return Math.floor(getNavigationStart() + relativeTime)
1509
+ return Math.round(getNavigationStart() + relativeTime)
1508
1510
  }
1509
1511
  export function relativeNow() {
1510
1512
  return performance.now()
@@ -1514,8 +1516,21 @@ export function clocksNow() {
1514
1516
  return { relative: relativeNow(), timeStamp: timeStampNow() }
1515
1517
  }
1516
1518
  export function timeStampNow() {
1517
- return Date.now()
1519
+ return dateNow()
1518
1520
  }
1521
+
1522
+ export function looksLikeRelativeTime(time) {
1523
+ return time < ONE_YEAR
1524
+ }
1525
+ export function dateNow() {
1526
+ // Do not use `Date.now` because sometimes websites are wrongly "polyfilling" it. For example, we
1527
+ // had some users using a very old version of `datejs`, which patched `Date.now` to return a Date
1528
+ // instance instead of a timestamp[1]. Those users are unlikely to fix this, so let's handle this
1529
+ // case ourselves.
1530
+ // [1]: https://github.com/datejs/Datejs/blob/97f5c7c58c5bc5accdab8aa7602b6ac56462d778/src/core-debug.js#L14-L16
1531
+ return new Date().getTime()
1532
+ }
1533
+
1519
1534
  export function elapsed(start, end) {
1520
1535
  return end - start
1521
1536
  }
@@ -1530,7 +1545,15 @@ export function preferredTimeStamp(clocks) {
1530
1545
  return getTimestamp(clocks.relative)
1531
1546
  }
1532
1547
  export function relativeToClocks(relative) {
1533
- return { relative: relative, timeStamp: getTimestamp(relative) }
1548
+ return { relative: relative, timeStamp: getCorrectedTimeStamp(relative) }
1549
+ }
1550
+ function getCorrectedTimeStamp(relativeTime) {
1551
+ const correctedOrigin = dateNow() - performance.now()
1552
+ // apply correction only for positive drift
1553
+ if (correctedOrigin > getNavigationStart()) {
1554
+ return Math.round(correctedOrigin + relativeTime)
1555
+ }
1556
+ return getTimestamp(relativeTime)
1534
1557
  }
1535
1558
  /**
1536
1559
  * Navigation start slightly change on some rare cases
package/src/xhrProxy.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { normalizeUrl } from './helper/urlPolyfill'
2
- import { each, relativeNow, clocksNow, elapsed, extend } from './helper/tools'
2
+ import { each, relativeNow, clocksNow, elapsed, extend, timeStampNow } from './helper/tools'
3
3
 
4
4
  var xhrProxySingleton
5
5
  var beforeSendCallbacks = []
@@ -78,8 +78,8 @@ function proxyXhr() {
78
78
  hasBeenReported = true
79
79
  var xhrCompleteContext = extend({}, xhrPendingContext, {
80
80
  duration: elapsed(
81
- xhrPendingContext.startClocks.relative,
82
- relativeNow()
81
+ xhrPendingContext.startClocks.timeStamp,
82
+ timeStampNow()
83
83
  ),
84
84
  response: _this.response,
85
85
  status: _this.status