@cloudcare/browser-core 3.1.3 → 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.
@@ -5,17 +5,29 @@ var typeMap = {
5
5
  log: '/logging',
6
6
  sessionReplay: '/rum/replay'
7
7
  }
8
- function getEndPointUrl(url, type) {
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
- if (url.lastIndexOf('/') === url.length - 1)
17
- return trim(url) + 'v1/write' + subUrl
18
- return trim(url) + '/v1/write' + subUrl
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
- initConfiguration.datakitUrl || initConfiguration.datakitOrigin,
49
- 'rum'
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
  }
@@ -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,
@@ -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
- var matches = rawString.match('(?:^|;)\\s*' + name + '\\s*=\\s*([^;]+)')
1523
- return matches ? matches[1] : undefined
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
- var browserIsIE
1624
+ export var Browser = {
1625
+ IE: 0,
1626
+ CHROMIUM: 1,
1627
+ SAFARI: 2,
1628
+ OTHER: 3
1629
+ }
1599
1630
  export function isIE() {
1600
- if (browserIsIE === undefined) {
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
- if (browserIsChromium === undefined) {
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
- if (browserIsSafari === undefined) {
1616
- browserIsSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
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
- return browserIsSafari
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