@cloudcare/browser-core 3.1.3 → 3.1.6
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/configuration/configuration.js +18 -0
- 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 +2 -2
- 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/tools.js +66 -18
- package/cjs/helper/tools.js.map +1 -1
- package/esm/browser/cookie.js +17 -3
- package/esm/browser/cookie.js.map +1 -1
- package/esm/configuration/configuration.js +17 -0
- 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 +2 -2
- 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/tools.js +62 -17
- package/esm/helper/tools.js.map +1 -1
- package/package.json +2 -2
- package/src/browser/cookie.js +22 -3
- package/src/configuration/configuration.js +27 -1
- package/src/configuration/transportConfiguration.js +19 -13
- package/src/dataMap.js +2 -2
- package/src/helper/deviceInfo.js +23 -20
- package/src/helper/tools.js +70 -18
- package/src/.DS_Store +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-core",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
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": "
|
|
23
|
+
"gitHead": "8ddcdc7a34fe8d8f1637cde3670fc18529352e28"
|
|
24
24
|
}
|
package/src/browser/cookie.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
findCommaSeparatedValue,
|
|
3
|
+
UUID,
|
|
4
|
+
ONE_SECOND,
|
|
5
|
+
findCommaSeparatedValues
|
|
6
|
+
} from '../helper/tools'
|
|
2
7
|
export var COOKIE_ACCESS_DELAY = ONE_SECOND
|
|
3
8
|
|
|
4
9
|
export function setCookie(name, value, expireDelay, options) {
|
|
@@ -23,7 +28,21 @@ export function setCookie(name, value, expireDelay, options) {
|
|
|
23
28
|
export function getCookie(name) {
|
|
24
29
|
return findCommaSeparatedValue(document.cookie, name)
|
|
25
30
|
}
|
|
31
|
+
var initCookieParsed
|
|
32
|
+
/**
|
|
33
|
+
* Returns a cached value of the cookie. Use this during SDK initialization (and whenever possible)
|
|
34
|
+
* to avoid accessing document.cookie multiple times.
|
|
35
|
+
*/
|
|
36
|
+
export function getInitCookie(name) {
|
|
37
|
+
if (!initCookieParsed) {
|
|
38
|
+
initCookieParsed = findCommaSeparatedValues(document.cookie)
|
|
39
|
+
}
|
|
40
|
+
return initCookieParsed.get(name)
|
|
41
|
+
}
|
|
26
42
|
|
|
43
|
+
export function resetInitCookies() {
|
|
44
|
+
initCookieParsed = undefined
|
|
45
|
+
}
|
|
27
46
|
export function deleteCookie(name, options) {
|
|
28
47
|
setCookie(name, '', 0, options)
|
|
29
48
|
}
|
|
@@ -35,7 +54,7 @@ export function areCookiesAuthorized(options) {
|
|
|
35
54
|
try {
|
|
36
55
|
// Use a unique cookie name to avoid issues when the SDK is initialized multiple times during
|
|
37
56
|
// the test cookie lifetime
|
|
38
|
-
var testCookieName = `
|
|
57
|
+
var testCookieName = `gc_cookie_test_${UUID()}`
|
|
39
58
|
var testCookieValue = 'test'
|
|
40
59
|
setCookie(testCookieName, testCookieValue, ONE_SECOND, options)
|
|
41
60
|
return getCookie(testCookieName) === testCookieValue
|
|
@@ -54,7 +73,7 @@ export function getCurrentSite() {
|
|
|
54
73
|
if (getCurrentSiteCache === undefined) {
|
|
55
74
|
// Use a unique cookie name to avoid issues when the SDK is initialized multiple times during
|
|
56
75
|
// the test cookie lifetime
|
|
57
|
-
var testCookieName = `
|
|
76
|
+
var testCookieName = `gc_site_test_${UUID()}`
|
|
58
77
|
var testCookieValue = 'test'
|
|
59
78
|
|
|
60
79
|
var domainLevels = window.location.hostname.split('.')
|
|
@@ -89,7 +89,33 @@ export function validateAndBuildConfiguration(initConfiguration) {
|
|
|
89
89
|
computeTransportConfiguration(initConfiguration)
|
|
90
90
|
)
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
export function validatePostRequestRequireParamsConfiguration(
|
|
93
|
+
initConfiguration
|
|
94
|
+
) {
|
|
95
|
+
if (
|
|
96
|
+
!initConfiguration.site &&
|
|
97
|
+
!initConfiguration.datakitOrigin &&
|
|
98
|
+
!initConfiguration.datakitUrl
|
|
99
|
+
) {
|
|
100
|
+
display.error(
|
|
101
|
+
'datakitOrigin or site is not configured, no RUM data will be collected.'
|
|
102
|
+
)
|
|
103
|
+
return false
|
|
104
|
+
}
|
|
105
|
+
// if (!initConfiguration.datakitUrl && !initConfiguration.datakitOrigin) {
|
|
106
|
+
// display.error(
|
|
107
|
+
// 'datakitOrigin is not configured, no RUM data will be collected.'
|
|
108
|
+
// )
|
|
109
|
+
// return false
|
|
110
|
+
// }
|
|
111
|
+
if (initConfiguration.site && !initConfiguration.clientToken) {
|
|
112
|
+
display.error(
|
|
113
|
+
'clientToken is not configured, no RUM data will be collected.'
|
|
114
|
+
)
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
return true
|
|
118
|
+
}
|
|
93
119
|
export function buildCookieOptions(initConfiguration) {
|
|
94
120
|
var cookieOptions = {}
|
|
95
121
|
|
|
@@ -5,17 +5,29 @@ var typeMap = {
|
|
|
5
5
|
log: '/logging',
|
|
6
6
|
sessionReplay: '/rum/replay'
|
|
7
7
|
}
|
|
8
|
-
function getEndPointUrl(
|
|
8
|
+
function getEndPointUrl(configuration, type) {
|
|
9
9
|
// type: rum, log,replay
|
|
10
10
|
var subUrl = typeMap[type]
|
|
11
11
|
if (!subUrl) return ''
|
|
12
|
+
var url =
|
|
13
|
+
configuration.datakitOrigin ||
|
|
14
|
+
configuration.datakitUrl ||
|
|
15
|
+
configuration.site
|
|
12
16
|
if (url.indexOf('/') === 0) {
|
|
13
17
|
// 绝对路径这种 /xxx
|
|
14
18
|
url = location.origin + trim(url)
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
var endpoint = url
|
|
21
|
+
if (url.lastIndexOf('/') === url.length - 1) {
|
|
22
|
+
endpoint = trim(url) + 'v1/write' + subUrl
|
|
23
|
+
} else {
|
|
24
|
+
endpoint = trim(url) + '/v1/write' + subUrl
|
|
25
|
+
}
|
|
26
|
+
if (configuration.site && configuration.clientToken) {
|
|
27
|
+
endpoint =
|
|
28
|
+
endpoint + '?token=' + configuration.clientToken + '&to_headless=true'
|
|
29
|
+
}
|
|
30
|
+
return endpoint
|
|
19
31
|
}
|
|
20
32
|
|
|
21
33
|
function trim(str) {
|
|
@@ -44,15 +56,9 @@ export function computeTransportConfiguration(initConfiguration) {
|
|
|
44
56
|
isServerError = initConfiguration.isServerError
|
|
45
57
|
}
|
|
46
58
|
return {
|
|
47
|
-
rumEndpoint: getEndPointUrl(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
),
|
|
51
|
-
logsEndpoint: getEndPointUrl(initConfiguration.datakitOrigin, 'log'),
|
|
52
|
-
sessionReplayEndPoint: getEndPointUrl(
|
|
53
|
-
initConfiguration.datakitOrigin,
|
|
54
|
-
'sessionReplay'
|
|
55
|
-
),
|
|
59
|
+
rumEndpoint: getEndPointUrl(initConfiguration, 'rum'),
|
|
60
|
+
logsEndpoint: getEndPointUrl(initConfiguration, 'log'),
|
|
61
|
+
sessionReplayEndPoint: getEndPointUrl(initConfiguration, 'sessionReplay'),
|
|
56
62
|
isIntakeUrl: isIntakeUrl,
|
|
57
63
|
isServerError: isServerError
|
|
58
64
|
}
|
package/src/dataMap.js
CHANGED
|
@@ -28,10 +28,10 @@ export var commonTags = {
|
|
|
28
28
|
view_host: 'view.host',
|
|
29
29
|
view_path: 'view.path',
|
|
30
30
|
view_name: 'view.path', // 冗余一个字段
|
|
31
|
-
view_path_group: 'view.path_group'
|
|
32
|
-
view_url_query: 'view.url_query'
|
|
31
|
+
view_path_group: 'view.path_group'
|
|
33
32
|
}
|
|
34
33
|
export var commonFields = {
|
|
34
|
+
view_url_query: 'view.url_query',
|
|
35
35
|
action_id: 'action.id',
|
|
36
36
|
action_ids: 'action.ids',
|
|
37
37
|
view_in_foreground: 'view.in_foreground',
|
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/tools.js
CHANGED
|
@@ -1518,9 +1518,36 @@ export function getNavigationStart() {
|
|
|
1518
1518
|
}
|
|
1519
1519
|
return navigationStart
|
|
1520
1520
|
}
|
|
1521
|
+
|
|
1522
|
+
var COMMA_SEPARATED_KEY_VALUE = /([\w-]+)\s*=\s*([^;]+)/g
|
|
1521
1523
|
export function findCommaSeparatedValue(rawString, name) {
|
|
1522
|
-
|
|
1523
|
-
|
|
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
|
|
1524
1551
|
}
|
|
1525
1552
|
export function findByPath(source, path) {
|
|
1526
1553
|
var pathArr = path.split('.')
|
|
@@ -1594,29 +1621,54 @@ export function isPercentage(value) {
|
|
|
1594
1621
|
export function getLocationOrigin() {
|
|
1595
1622
|
return getLinkElementOrigin(window.location)
|
|
1596
1623
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1624
|
+
export var Browser = {
|
|
1625
|
+
IE: 0,
|
|
1626
|
+
CHROMIUM: 1,
|
|
1627
|
+
SAFARI: 2,
|
|
1628
|
+
OTHER: 3
|
|
1629
|
+
}
|
|
1599
1630
|
export function isIE() {
|
|
1600
|
-
|
|
1601
|
-
browserIsIE = Boolean(document.documentMode)
|
|
1602
|
-
}
|
|
1603
|
-
return browserIsIE
|
|
1631
|
+
return detectBrowserCached() === Browser.IE
|
|
1604
1632
|
}
|
|
1605
|
-
var browserIsChromium
|
|
1606
1633
|
export function isChromium() {
|
|
1607
|
-
|
|
1608
|
-
browserIsChromium =
|
|
1609
|
-
!!window.chrome || /HeadlessChrome/.test(window.navigator.userAgent)
|
|
1610
|
-
}
|
|
1611
|
-
return browserIsChromium
|
|
1634
|
+
return detectBrowserCached() === Browser.CHROMIUM
|
|
1612
1635
|
}
|
|
1613
|
-
var browserIsSafari
|
|
1614
1636
|
export function isSafari() {
|
|
1615
|
-
|
|
1616
|
-
|
|
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
|
|
1649
|
+
}
|
|
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
|
|
1617
1663
|
}
|
|
1618
|
-
|
|
1664
|
+
|
|
1665
|
+
if (browserWindow.document.documentMode) {
|
|
1666
|
+
return Browser.IE
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
return Browser.OTHER
|
|
1619
1670
|
}
|
|
1671
|
+
|
|
1620
1672
|
/**
|
|
1621
1673
|
* IE fallback
|
|
1622
1674
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/origin
|
package/src/.DS_Store
DELETED
|
Binary file
|