@cloudcare/browser-core 3.1.2 → 3.1.5
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.
- package/cjs/browser/cookie.js +18 -2
- package/cjs/browser/cookie.js.map +1 -1
- package/cjs/browser/htmlDomUtils.js +4 -1
- package/cjs/browser/htmlDomUtils.js.map +1 -1
- package/cjs/configuration/configuration.js +20 -1
- package/cjs/configuration/configuration.js.map +1 -1
- package/cjs/configuration/transportConfiguration.js +15 -6
- package/cjs/configuration/transportConfiguration.js.map +1 -1
- package/cjs/dataMap.js +7 -3
- package/cjs/dataMap.js.map +1 -1
- package/cjs/helper/deviceInfo.js +23 -21
- package/cjs/helper/deviceInfo.js.map +1 -1
- package/cjs/helper/errorTools.js +2 -1
- package/cjs/helper/errorTools.js.map +1 -1
- package/cjs/helper/monitor.js +1 -0
- package/cjs/helper/monitor.js.map +1 -1
- package/cjs/helper/serialisation/rowData.js +7 -5
- package/cjs/helper/serialisation/rowData.js.map +1 -1
- package/cjs/helper/tools.js +67 -18
- package/cjs/helper/tools.js.map +1 -1
- package/cjs/transport/batch.js +23 -10
- package/cjs/transport/batch.js.map +1 -1
- package/cjs/transport/httpRequest.js +31 -12
- package/cjs/transport/httpRequest.js.map +1 -1
- package/cjs/transport/startBatchWithReplica.js +2 -2
- package/cjs/transport/startBatchWithReplica.js.map +1 -1
- package/esm/browser/cookie.js +17 -3
- package/esm/browser/cookie.js.map +1 -1
- package/esm/browser/htmlDomUtils.js +3 -1
- package/esm/browser/htmlDomUtils.js.map +1 -1
- package/esm/configuration/configuration.js +19 -1
- package/esm/configuration/configuration.js.map +1 -1
- package/esm/configuration/transportConfiguration.js +15 -6
- package/esm/configuration/transportConfiguration.js.map +1 -1
- package/esm/dataMap.js +7 -3
- package/esm/dataMap.js.map +1 -1
- package/esm/helper/deviceInfo.js +23 -21
- package/esm/helper/deviceInfo.js.map +1 -1
- package/esm/helper/errorTools.js +1 -0
- package/esm/helper/errorTools.js.map +1 -1
- package/esm/helper/monitor.js +1 -0
- package/esm/helper/monitor.js.map +1 -1
- package/esm/helper/serialisation/rowData.js +8 -6
- package/esm/helper/serialisation/rowData.js.map +1 -1
- package/esm/helper/tools.js +63 -17
- package/esm/helper/tools.js.map +1 -1
- package/esm/transport/batch.js +24 -11
- package/esm/transport/batch.js.map +1 -1
- package/esm/transport/httpRequest.js +31 -12
- package/esm/transport/httpRequest.js.map +1 -1
- package/esm/transport/startBatchWithReplica.js +2 -2
- package/esm/transport/startBatchWithReplica.js.map +1 -1
- package/package.json +2 -2
- package/src/browser/cookie.js +22 -3
- package/src/browser/htmlDomUtils.js +3 -1
- package/src/configuration/configuration.js +29 -2
- package/src/configuration/transportConfiguration.js +19 -13
- package/src/dataMap.js +9 -3
- package/src/helper/deviceInfo.js +23 -20
- package/src/helper/errorTools.js +1 -0
- package/src/helper/monitor.js +1 -0
- package/src/helper/serialisation/rowData.js +9 -6
- package/src/helper/tools.js +71 -18
- package/src/transport/batch.js +28 -12
- package/src/transport/httpRequest.js +46 -11
- package/src/transport/startBatchWithReplica.js +3 -1
- package/src/.DS_Store +0 -0
package/src/helper/deviceInfo.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { display } from '../helper/display'
|
|
2
|
+
import { monitor } from '../helper/monitor'
|
|
2
3
|
var VariableLibrary = {
|
|
3
4
|
navigator:
|
|
4
5
|
typeof window !== 'undefined' && typeof window.navigator != 'undefined'
|
|
@@ -80,7 +81,7 @@ var VariableLibrary = {
|
|
|
80
81
|
// 方法库
|
|
81
82
|
var MethodLibrary = {
|
|
82
83
|
// 获取匹配库
|
|
83
|
-
getMatchMap: function (u) {
|
|
84
|
+
getMatchMap: monitor(function (u) {
|
|
84
85
|
return {
|
|
85
86
|
// 内核
|
|
86
87
|
Trident: u.indexOf('Trident') > -1 || u.indexOf('NET CLR') > -1,
|
|
@@ -154,9 +155,9 @@ var MethodLibrary = {
|
|
|
154
155
|
Tablet: u.indexOf('Tablet') > -1 || u.indexOf('Nexus 7') > -1,
|
|
155
156
|
iPad: u.indexOf('iPad') > -1
|
|
156
157
|
}
|
|
157
|
-
},
|
|
158
|
+
}),
|
|
158
159
|
// 在信息map和匹配库中进行匹配
|
|
159
|
-
matchInfoMap: function (_this) {
|
|
160
|
+
matchInfoMap: monitor(function (_this) {
|
|
160
161
|
var u = VariableLibrary.navigator.userAgent || ''
|
|
161
162
|
var match = MethodLibrary.getMatchMap(u)
|
|
162
163
|
for (var s in VariableLibrary.infoMap) {
|
|
@@ -167,15 +168,15 @@ var MethodLibrary = {
|
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
}
|
|
170
|
-
},
|
|
171
|
+
}),
|
|
171
172
|
// 获取当前操作系统
|
|
172
|
-
getOS: function () {
|
|
173
|
+
getOS: monitor(function () {
|
|
173
174
|
var _this = this
|
|
174
175
|
MethodLibrary.matchInfoMap(_this)
|
|
175
176
|
return _this.os || 'Unknown'
|
|
176
|
-
},
|
|
177
|
+
}),
|
|
177
178
|
// 获取操作系统版本
|
|
178
|
-
getOSVersion: function () {
|
|
179
|
+
getOSVersion: monitor(function () {
|
|
179
180
|
var _this = this
|
|
180
181
|
var u = VariableLibrary.navigator.userAgent || ''
|
|
181
182
|
_this.osVersion = ''
|
|
@@ -229,9 +230,9 @@ var MethodLibrary = {
|
|
|
229
230
|
version: _this.osVersion,
|
|
230
231
|
osMajor: _this.osMajor
|
|
231
232
|
}
|
|
232
|
-
},
|
|
233
|
+
}),
|
|
233
234
|
// 获取横竖屏状态
|
|
234
|
-
getOrientationStatu: function () {
|
|
235
|
+
getOrientationStatu: monitor(function () {
|
|
235
236
|
var orientationStatus = ''
|
|
236
237
|
var orientation = window.matchMedia('(orientation: portrait)')
|
|
237
238
|
if (orientation.matches) {
|
|
@@ -240,16 +241,16 @@ var MethodLibrary = {
|
|
|
240
241
|
orientationStatus = '横屏'
|
|
241
242
|
}
|
|
242
243
|
return orientationStatus
|
|
243
|
-
},
|
|
244
|
+
}),
|
|
244
245
|
// 获取设备类型
|
|
245
|
-
getDeviceType: function () {
|
|
246
|
+
getDeviceType: monitor(function () {
|
|
246
247
|
var _this = this
|
|
247
248
|
_this.device = 'PC'
|
|
248
249
|
MethodLibrary.matchInfoMap(_this)
|
|
249
250
|
return _this.device
|
|
250
|
-
},
|
|
251
|
+
}),
|
|
251
252
|
// 获取网络状态
|
|
252
|
-
getNetwork: function () {
|
|
253
|
+
getNetwork: monitor(function () {
|
|
253
254
|
var connection =
|
|
254
255
|
window.navigator.connection ||
|
|
255
256
|
window.navigator.mozConnection ||
|
|
@@ -289,9 +290,9 @@ var MethodLibrary = {
|
|
|
289
290
|
}
|
|
290
291
|
}
|
|
291
292
|
return result
|
|
292
|
-
},
|
|
293
|
+
}),
|
|
293
294
|
// 获取当前语言
|
|
294
|
-
getLanguage: function () {
|
|
295
|
+
getLanguage: monitor(function () {
|
|
295
296
|
var _this = this
|
|
296
297
|
_this.language = (function () {
|
|
297
298
|
var language =
|
|
@@ -305,9 +306,9 @@ var MethodLibrary = {
|
|
|
305
306
|
return arr.join('_')
|
|
306
307
|
})()
|
|
307
308
|
return _this.language
|
|
308
|
-
},
|
|
309
|
+
}),
|
|
309
310
|
// 浏览器信息
|
|
310
|
-
getBrowserInfo: function () {
|
|
311
|
+
getBrowserInfo: monitor(function () {
|
|
311
312
|
var _this = this
|
|
312
313
|
MethodLibrary.matchInfoMap(_this)
|
|
313
314
|
|
|
@@ -345,6 +346,7 @@ var MethodLibrary = {
|
|
|
345
346
|
match['360SE'] = true
|
|
346
347
|
} else if (
|
|
347
348
|
VariableLibrary.navigator &&
|
|
349
|
+
VariableLibrary.navigator.connection &&
|
|
348
350
|
typeof VariableLibrary.navigator['connection']['saveData'] ==
|
|
349
351
|
'undefined'
|
|
350
352
|
) {
|
|
@@ -589,9 +591,9 @@ var MethodLibrary = {
|
|
|
589
591
|
engine: _this.engine,
|
|
590
592
|
browserMajor: _this.browserMajor
|
|
591
593
|
}
|
|
592
|
-
},
|
|
594
|
+
}),
|
|
593
595
|
// 获取地理位置
|
|
594
|
-
getGeoPostion: function (callback) {
|
|
596
|
+
getGeoPostion: monitor(function (callback) {
|
|
595
597
|
navigator &&
|
|
596
598
|
navigator.geolocation &&
|
|
597
599
|
navigator.geolocation.getCurrentPosition(
|
|
@@ -604,12 +606,13 @@ var MethodLibrary = {
|
|
|
604
606
|
display.warn(error)
|
|
605
607
|
}
|
|
606
608
|
)
|
|
607
|
-
}
|
|
609
|
+
})
|
|
608
610
|
}
|
|
609
611
|
var _deviceInfo = {}
|
|
610
612
|
if (typeof window !== 'undefined') {
|
|
611
613
|
_deviceInfo = {
|
|
612
614
|
os: MethodLibrary.getOS(),
|
|
615
|
+
MethodLibrary,
|
|
613
616
|
osVersion: MethodLibrary.getOSVersion().version,
|
|
614
617
|
osVersionMajor: MethodLibrary.getOSVersion().osMajor,
|
|
615
618
|
browser: MethodLibrary.getBrowserInfo().browser,
|
package/src/helper/errorTools.js
CHANGED
|
@@ -2,6 +2,7 @@ import { each, noop } from './tools'
|
|
|
2
2
|
import { jsonStringify } from '../helper/serialisation/jsonStringify'
|
|
3
3
|
import { computeStackTrace } from '../tracekit'
|
|
4
4
|
import { callMonitored } from '../helper/monitor'
|
|
5
|
+
import { sanitize } from '../helper/sanitize'
|
|
5
6
|
export var NO_ERROR_STACK_PRESENT_MESSAGE =
|
|
6
7
|
'No stack, consider using an instance of Error'
|
|
7
8
|
export var ErrorSource = {
|
package/src/helper/monitor.js
CHANGED
|
@@ -38,6 +38,7 @@ export function callMonitored(fn, context, args) {
|
|
|
38
38
|
|
|
39
39
|
export function displayIfDebugEnabled(api) {
|
|
40
40
|
var args = [].slice.call(arguments, 1)
|
|
41
|
+
// display.apply(null, [api, '[MONITOR]'].concat(args))
|
|
41
42
|
if (debugMode) {
|
|
42
43
|
display.apply(null, [api, '[MONITOR]'].concat(args))
|
|
43
44
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsonStringify } from './jsonStringify'
|
|
2
|
-
import { isString } from '../tools'
|
|
2
|
+
import { isString, isNumber } from '../tools'
|
|
3
3
|
export function escapeRowData(str) {
|
|
4
4
|
if (typeof str === 'object' && str) {
|
|
5
5
|
str = jsonStringify(str)
|
|
@@ -12,12 +12,15 @@ export function escapeRowData(str) {
|
|
|
12
12
|
})
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export function escapeJsonValue(value) {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
} else {
|
|
19
|
-
|
|
15
|
+
export function escapeJsonValue(value, isTag) {
|
|
16
|
+
if (typeof value === 'object' && value) {
|
|
17
|
+
value = jsonStringify(value)
|
|
18
|
+
} else if (isTag) {
|
|
19
|
+
// tag json 只能是字符串
|
|
20
|
+
value = '' + value
|
|
20
21
|
}
|
|
22
|
+
|
|
23
|
+
return value
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
export function escapeFieldValueStr(str) {
|
package/src/helper/tools.js
CHANGED
|
@@ -228,6 +228,7 @@ export var matchList = function (list, value, useStartsWith) {
|
|
|
228
228
|
} catch (e) {
|
|
229
229
|
display.error(e)
|
|
230
230
|
}
|
|
231
|
+
return false
|
|
231
232
|
})
|
|
232
233
|
}
|
|
233
234
|
// https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/selector/escapeSelector.js
|
|
@@ -1517,9 +1518,36 @@ export function getNavigationStart() {
|
|
|
1517
1518
|
}
|
|
1518
1519
|
return navigationStart
|
|
1519
1520
|
}
|
|
1521
|
+
|
|
1522
|
+
var COMMA_SEPARATED_KEY_VALUE = /([\w-]+)\s*=\s*([^;]+)/g
|
|
1520
1523
|
export function findCommaSeparatedValue(rawString, name) {
|
|
1521
|
-
|
|
1522
|
-
|
|
1524
|
+
COMMA_SEPARATED_KEY_VALUE.lastIndex = 0
|
|
1525
|
+
// eslint-disable-next-line no-constant-condition
|
|
1526
|
+
while (true) {
|
|
1527
|
+
var match = COMMA_SEPARATED_KEY_VALUE.exec(rawString)
|
|
1528
|
+
if (match) {
|
|
1529
|
+
if (match[1] === name) {
|
|
1530
|
+
return match[2]
|
|
1531
|
+
}
|
|
1532
|
+
} else {
|
|
1533
|
+
break
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
export function findCommaSeparatedValues(rawString) {
|
|
1539
|
+
var result = new Map()
|
|
1540
|
+
COMMA_SEPARATED_KEY_VALUE.lastIndex = 0
|
|
1541
|
+
// eslint-disable-next-line no-constant-condition
|
|
1542
|
+
while (true) {
|
|
1543
|
+
var match = COMMA_SEPARATED_KEY_VALUE.exec(rawString)
|
|
1544
|
+
if (match) {
|
|
1545
|
+
result.set(match[1], match[2])
|
|
1546
|
+
} else {
|
|
1547
|
+
break
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
return result
|
|
1523
1551
|
}
|
|
1524
1552
|
export function findByPath(source, path) {
|
|
1525
1553
|
var pathArr = path.split('.')
|
|
@@ -1593,29 +1621,54 @@ export function isPercentage(value) {
|
|
|
1593
1621
|
export function getLocationOrigin() {
|
|
1594
1622
|
return getLinkElementOrigin(window.location)
|
|
1595
1623
|
}
|
|
1596
|
-
|
|
1597
|
-
|
|
1624
|
+
export var Browser = {
|
|
1625
|
+
IE: 0,
|
|
1626
|
+
CHROMIUM: 1,
|
|
1627
|
+
SAFARI: 2,
|
|
1628
|
+
OTHER: 3
|
|
1629
|
+
}
|
|
1598
1630
|
export function isIE() {
|
|
1599
|
-
|
|
1600
|
-
browserIsIE = Boolean(document.documentMode)
|
|
1601
|
-
}
|
|
1602
|
-
return browserIsIE
|
|
1631
|
+
return detectBrowserCached() === Browser.IE
|
|
1603
1632
|
}
|
|
1604
|
-
var browserIsChromium
|
|
1605
1633
|
export function isChromium() {
|
|
1606
|
-
|
|
1607
|
-
browserIsChromium =
|
|
1608
|
-
!!window.chrome || /HeadlessChrome/.test(window.navigator.userAgent)
|
|
1609
|
-
}
|
|
1610
|
-
return browserIsChromium
|
|
1634
|
+
return detectBrowserCached() === Browser.CHROMIUM
|
|
1611
1635
|
}
|
|
1612
|
-
var browserIsSafari
|
|
1613
1636
|
export function isSafari() {
|
|
1614
|
-
|
|
1615
|
-
|
|
1637
|
+
return detectBrowserCached() === Browser.SAFARI
|
|
1638
|
+
}
|
|
1639
|
+
var browserCache
|
|
1640
|
+
function detectBrowserCached() {
|
|
1641
|
+
return isNullUndefinedDefaultValue(
|
|
1642
|
+
browserCache,
|
|
1643
|
+
(browserCache = detectBrowser())
|
|
1644
|
+
)
|
|
1645
|
+
}
|
|
1646
|
+
export function detectBrowser(browserWindow) {
|
|
1647
|
+
if (typeof browserWindow === 'undefined') {
|
|
1648
|
+
browserWindow = window
|
|
1616
1649
|
}
|
|
1617
|
-
|
|
1650
|
+
var userAgent = browserWindow.navigator.userAgent
|
|
1651
|
+
if (browserWindow.chrome || /HeadlessChrome/.test(userAgent)) {
|
|
1652
|
+
return Browser.CHROMIUM
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
if (
|
|
1656
|
+
// navigator.vendor is deprecated, but it is the most resilient way we found to detect
|
|
1657
|
+
// "Apple maintained browsers" (AKA Safari). If one day it gets removed, we still have the
|
|
1658
|
+
// useragent test as a semi-working fallback.
|
|
1659
|
+
browserWindow.navigator.vendor?.indexOf('Apple') === 0 ||
|
|
1660
|
+
(/safari/i.test(userAgent) && !/chrome|android/i.test(userAgent))
|
|
1661
|
+
) {
|
|
1662
|
+
return Browser.SAFARI
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
if (browserWindow.document.documentMode) {
|
|
1666
|
+
return Browser.IE
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
return Browser.OTHER
|
|
1618
1670
|
}
|
|
1671
|
+
|
|
1619
1672
|
/**
|
|
1620
1673
|
* IE fallback
|
|
1621
1674
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/origin
|
package/src/transport/batch.js
CHANGED
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
isArray,
|
|
8
8
|
extend,
|
|
9
9
|
isString,
|
|
10
|
-
toServerDuration,
|
|
11
|
-
isBoolean,
|
|
12
10
|
isEmptyObject,
|
|
13
11
|
isObject
|
|
14
12
|
} from '../helper/tools'
|
|
@@ -21,6 +19,7 @@ import { commonTags, dataMap, commonFields } from '../dataMap'
|
|
|
21
19
|
import { RumEventType } from '../helper/enums'
|
|
22
20
|
import { computeBytesCount } from '../helper/byteUtils'
|
|
23
21
|
import { isPageExitReason } from '../browser/pageExitObservable'
|
|
22
|
+
import { jsonStringify } from '../helper/serialisation/jsonStringify'
|
|
24
23
|
// https://en.wikipedia.org/wiki/UTF-8
|
|
25
24
|
// eslint-disable-next-line no-control-regex
|
|
26
25
|
var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/
|
|
@@ -46,7 +45,7 @@ export var processedMessageByDataMap = function (message) {
|
|
|
46
45
|
var _value = findByPath(message, value_path)
|
|
47
46
|
filterFileds.push(_key)
|
|
48
47
|
if (_value || isNumber(_value)) {
|
|
49
|
-
rowData.tags[_key] = escapeJsonValue(_value)
|
|
48
|
+
rowData.tags[_key] = escapeJsonValue(_value, true)
|
|
50
49
|
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value))
|
|
51
50
|
}
|
|
52
51
|
})
|
|
@@ -59,7 +58,7 @@ export var processedMessageByDataMap = function (message) {
|
|
|
59
58
|
var _valueData = findByPath(message, value_path)
|
|
60
59
|
filterFileds.push(_key)
|
|
61
60
|
if (_valueData !== undefined && _valueData !== null) {
|
|
62
|
-
rowData.fields[_key] = _valueData // 这里不需要转译
|
|
61
|
+
rowData.fields[_key] = escapeJsonValue(_valueData) // 这里不需要转译
|
|
63
62
|
fieldsStr.push(
|
|
64
63
|
escapeRowData(_key) + '=' + escapeRowField(_valueData)
|
|
65
64
|
)
|
|
@@ -68,7 +67,7 @@ export var processedMessageByDataMap = function (message) {
|
|
|
68
67
|
var _valueData = findByPath(message, _value)
|
|
69
68
|
filterFileds.push(_key)
|
|
70
69
|
if (_valueData !== undefined && _valueData !== null) {
|
|
71
|
-
rowData.fields[_key] = _valueData // 这里不需要转译
|
|
70
|
+
rowData.fields[_key] = escapeJsonValue(_valueData) // 这里不需要转译
|
|
72
71
|
fieldsStr.push(
|
|
73
72
|
escapeRowData(_key) + '=' + escapeRowField(_valueData)
|
|
74
73
|
)
|
|
@@ -88,12 +87,12 @@ export var processedMessageByDataMap = function (message) {
|
|
|
88
87
|
filterFileds.push(_key)
|
|
89
88
|
if (_value !== undefined && _value !== null) {
|
|
90
89
|
_tagKeys.push(_key)
|
|
91
|
-
rowData.fields[_key] = _value // 这里不需要转译
|
|
90
|
+
rowData.fields[_key] = escapeJsonValue(_value) // 这里不需要转译
|
|
92
91
|
fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_value))
|
|
93
92
|
}
|
|
94
93
|
})
|
|
95
94
|
if (_tagKeys.length) {
|
|
96
|
-
rowData.fields[CUSTOM_KEYS] =
|
|
95
|
+
rowData.fields[CUSTOM_KEYS] = escapeJsonValue(_tagKeys)
|
|
97
96
|
fieldsStr.push(
|
|
98
97
|
escapeRowData(CUSTOM_KEYS) + '=' + escapeRowField(_tagKeys)
|
|
99
98
|
)
|
|
@@ -107,7 +106,7 @@ export var processedMessageByDataMap = function (message) {
|
|
|
107
106
|
value !== undefined &&
|
|
108
107
|
value !== null
|
|
109
108
|
) {
|
|
110
|
-
rowData.fields[key] = value // 这里不需要转译
|
|
109
|
+
rowData.fields[key] = escapeJsonValue(value) // 这里不需要转译
|
|
111
110
|
fieldsStr.push(escapeRowData(key) + '=' + escapeRowField(value))
|
|
112
111
|
}
|
|
113
112
|
})
|
|
@@ -121,7 +120,7 @@ export var processedMessageByDataMap = function (message) {
|
|
|
121
120
|
hasFileds = true
|
|
122
121
|
}
|
|
123
122
|
rowStr = rowStr + ' ' + message.date
|
|
124
|
-
rowData.time =
|
|
123
|
+
rowData.time = message.date // 这里不需要转译
|
|
125
124
|
}
|
|
126
125
|
})
|
|
127
126
|
return {
|
|
@@ -129,12 +128,18 @@ export var processedMessageByDataMap = function (message) {
|
|
|
129
128
|
rowData: hasFileds ? rowData : undefined
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
|
-
var batch = function (
|
|
131
|
+
var batch = function (
|
|
132
|
+
request,
|
|
133
|
+
flushController,
|
|
134
|
+
messageBytesLimit,
|
|
135
|
+
sendContentTypeByJson
|
|
136
|
+
) {
|
|
133
137
|
this.pushOnlyBuffer = []
|
|
134
138
|
this.upsertBuffer = {}
|
|
135
139
|
this.request = request
|
|
136
140
|
this.flushController = flushController
|
|
137
141
|
this.messageBytesLimit = messageBytesLimit
|
|
142
|
+
this.sendContentTypeByJson = sendContentTypeByJson
|
|
138
143
|
var _this = this
|
|
139
144
|
this.flushController.flushObservable.subscribe(function (event) {
|
|
140
145
|
_this.flush(event)
|
|
@@ -151,8 +156,14 @@ batch.prototype.flush = function (event) {
|
|
|
151
156
|
this.pushOnlyBuffer = []
|
|
152
157
|
this.upsertBuffer = {}
|
|
153
158
|
if (messages.length > 0) {
|
|
159
|
+
var payloadData = ''
|
|
160
|
+
if (this.sendContentTypeByJson) {
|
|
161
|
+
payloadData = '[' + messages.join(',') + ']'
|
|
162
|
+
} else {
|
|
163
|
+
payloadData = messages.join('\n')
|
|
164
|
+
}
|
|
154
165
|
var payload = {
|
|
155
|
-
data:
|
|
166
|
+
data: payloadData,
|
|
156
167
|
bytesCount: event.bytesCount,
|
|
157
168
|
flushReason: event.reason
|
|
158
169
|
}
|
|
@@ -182,7 +193,12 @@ batch.prototype.addOrUpdate = function (message, key) {
|
|
|
182
193
|
this.push(processedMessage, messageBytesCount, key)
|
|
183
194
|
}
|
|
184
195
|
batch.prototype.process = function (message) {
|
|
185
|
-
var processedMessage =
|
|
196
|
+
var processedMessage = ''
|
|
197
|
+
if (this.sendContentTypeByJson) {
|
|
198
|
+
processedMessage = jsonStringify(processedMessageByDataMap(message).rowData)
|
|
199
|
+
} else {
|
|
200
|
+
processedMessage = processedMessageByDataMap(message).rowStr
|
|
201
|
+
}
|
|
186
202
|
var messageBytesCount = computeBytesCount(processedMessage)
|
|
187
203
|
return {
|
|
188
204
|
processedMessage: processedMessage,
|
|
@@ -13,10 +13,24 @@ function addBatchPrecision(url) {
|
|
|
13
13
|
if (!url) return url
|
|
14
14
|
return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms'
|
|
15
15
|
}
|
|
16
|
-
export function createHttpRequest(
|
|
16
|
+
export function createHttpRequest(
|
|
17
|
+
endpointUrl,
|
|
18
|
+
bytesLimit,
|
|
19
|
+
sendContentTypeByJson,
|
|
20
|
+
reportError
|
|
21
|
+
) {
|
|
22
|
+
var contentType = sendContentTypeByJson
|
|
23
|
+
? 'application/json; charset=UTF-8'
|
|
24
|
+
: undefined
|
|
17
25
|
var retryState = newRetryState()
|
|
18
26
|
var sendStrategyForRetry = function (payload, onResponse) {
|
|
19
|
-
return fetchKeepAliveStrategy(
|
|
27
|
+
return fetchKeepAliveStrategy(
|
|
28
|
+
endpointUrl,
|
|
29
|
+
bytesLimit,
|
|
30
|
+
contentType,
|
|
31
|
+
payload,
|
|
32
|
+
onResponse
|
|
33
|
+
)
|
|
20
34
|
}
|
|
21
35
|
|
|
22
36
|
return {
|
|
@@ -34,19 +48,28 @@ export function createHttpRequest(endpointUrl, bytesLimit, reportError) {
|
|
|
34
48
|
* keep using sendBeaconStrategy on exit
|
|
35
49
|
*/
|
|
36
50
|
sendOnExit: function (payload) {
|
|
37
|
-
sendBeaconStrategy(endpointUrl, bytesLimit, payload)
|
|
51
|
+
sendBeaconStrategy(endpointUrl, bytesLimit, contentType, payload)
|
|
38
52
|
}
|
|
39
53
|
}
|
|
40
54
|
}
|
|
41
55
|
|
|
42
|
-
function sendBeaconStrategy(endpointUrl, bytesLimit, payload) {
|
|
56
|
+
function sendBeaconStrategy(endpointUrl, bytesLimit, contentType, payload) {
|
|
43
57
|
var data = payload.data
|
|
44
58
|
var bytesCount = payload.bytesCount
|
|
45
59
|
var url = addBatchPrecision(endpointUrl)
|
|
46
60
|
var canUseBeacon = !!navigator.sendBeacon && bytesCount < bytesLimit
|
|
47
61
|
if (canUseBeacon) {
|
|
48
62
|
try {
|
|
49
|
-
var
|
|
63
|
+
var beaconData
|
|
64
|
+
if (contentType) {
|
|
65
|
+
beaconData = new Blob([data], {
|
|
66
|
+
type: contentType
|
|
67
|
+
})
|
|
68
|
+
} else {
|
|
69
|
+
beaconData = data
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
var isQueued = navigator.sendBeacon(url, beaconData)
|
|
50
73
|
|
|
51
74
|
if (isQueued) {
|
|
52
75
|
return
|
|
@@ -55,12 +78,13 @@ function sendBeaconStrategy(endpointUrl, bytesLimit, payload) {
|
|
|
55
78
|
// reportBeaconError(e)
|
|
56
79
|
}
|
|
57
80
|
}
|
|
58
|
-
sendXHR(url, data)
|
|
81
|
+
sendXHR(url, contentType, data)
|
|
59
82
|
}
|
|
60
83
|
|
|
61
84
|
export function fetchKeepAliveStrategy(
|
|
62
85
|
endpointUrl,
|
|
63
86
|
bytesLimit,
|
|
87
|
+
contentType,
|
|
64
88
|
payload,
|
|
65
89
|
onResponse
|
|
66
90
|
) {
|
|
@@ -69,12 +93,18 @@ export function fetchKeepAliveStrategy(
|
|
|
69
93
|
var url = addBatchPrecision(endpointUrl)
|
|
70
94
|
var canUseKeepAlive = isKeepAliveSupported() && bytesCount < bytesLimit
|
|
71
95
|
if (canUseKeepAlive) {
|
|
72
|
-
|
|
96
|
+
var fetchOption = {
|
|
73
97
|
method: 'POST',
|
|
74
98
|
body: data,
|
|
75
99
|
keepalive: true,
|
|
76
100
|
mode: 'cors'
|
|
77
|
-
}
|
|
101
|
+
}
|
|
102
|
+
if (contentType) {
|
|
103
|
+
fetchOption.headers = {
|
|
104
|
+
'Content-Type': contentType
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
fetch(url, fetchOption).then(
|
|
78
108
|
monitor(function (response) {
|
|
79
109
|
if (typeof onResponse === 'function') {
|
|
80
110
|
onResponse({ status: response.status, type: response.type })
|
|
@@ -82,11 +112,11 @@ export function fetchKeepAliveStrategy(
|
|
|
82
112
|
}),
|
|
83
113
|
monitor(function () {
|
|
84
114
|
// failed to queue the request
|
|
85
|
-
sendXHR(url, data, onResponse)
|
|
115
|
+
sendXHR(url, contentType, data, onResponse)
|
|
86
116
|
})
|
|
87
117
|
)
|
|
88
118
|
} else {
|
|
89
|
-
sendXHR(url, data, onResponse)
|
|
119
|
+
sendXHR(url, contentType, data, onResponse)
|
|
90
120
|
}
|
|
91
121
|
}
|
|
92
122
|
|
|
@@ -99,9 +129,14 @@ function isKeepAliveSupported() {
|
|
|
99
129
|
}
|
|
100
130
|
}
|
|
101
131
|
|
|
102
|
-
function sendXHR(url, data, onResponse) {
|
|
132
|
+
function sendXHR(url, contentType, data, onResponse) {
|
|
103
133
|
const request = new XMLHttpRequest()
|
|
104
134
|
request.open('POST', url, true)
|
|
135
|
+
if (contentType) {
|
|
136
|
+
//application/json; charset=UTF-8
|
|
137
|
+
request.setRequestHeader('Content-Type', contentType)
|
|
138
|
+
}
|
|
139
|
+
|
|
105
140
|
addEventListener(
|
|
106
141
|
request,
|
|
107
142
|
'loadend',
|
|
@@ -15,6 +15,7 @@ export function startBatchWithReplica(
|
|
|
15
15
|
createHttpRequest(
|
|
16
16
|
endpointUrl,
|
|
17
17
|
configuration.batchBytesLimit,
|
|
18
|
+
configuration.sendContentTypeByJson,
|
|
18
19
|
reportError
|
|
19
20
|
),
|
|
20
21
|
createFlushController({
|
|
@@ -24,7 +25,8 @@ export function startBatchWithReplica(
|
|
|
24
25
|
pageExitObservable: pageExitObservable,
|
|
25
26
|
sessionExpireObservable: sessionExpireObservable
|
|
26
27
|
}),
|
|
27
|
-
configuration.messageBytesLimit
|
|
28
|
+
configuration.messageBytesLimit,
|
|
29
|
+
configuration.sendContentTypeByJson
|
|
28
30
|
)
|
|
29
31
|
}
|
|
30
32
|
|
package/src/.DS_Store
DELETED
|
Binary file
|