@cloudcare/browser-core 3.1.2 → 3.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.
- package/cjs/browser/htmlDomUtils.js +4 -1
- package/cjs/browser/htmlDomUtils.js.map +1 -1
- package/cjs/configuration/configuration.js +2 -1
- package/cjs/configuration/configuration.js.map +1 -1
- package/cjs/dataMap.js +7 -3
- package/cjs/dataMap.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 +1 -0
- 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/htmlDomUtils.js +3 -1
- package/esm/browser/htmlDomUtils.js.map +1 -1
- package/esm/configuration/configuration.js +2 -1
- package/esm/configuration/configuration.js.map +1 -1
- package/esm/dataMap.js +7 -3
- package/esm/dataMap.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 +1 -0
- 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/htmlDomUtils.js +3 -1
- package/src/configuration/configuration.js +2 -1
- package/src/dataMap.js +9 -3
- 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 +1 -0
- package/src/transport/batch.js +28 -12
- package/src/transport/httpRequest.js +46 -11
- package/src/transport/startBatchWithReplica.js +3 -1
|
@@ -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
|
|