@cloudcare/browser-core 3.2.22 → 3.2.25
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/addEventListener.js +4 -2
- package/cjs/browser/addEventListener.js.map +1 -1
- package/cjs/browser/asyncClocks.js +68 -0
- package/cjs/browser/asyncClocks.js.map +1 -0
- package/cjs/dataMap.js +1 -0
- package/cjs/dataMap.js.map +1 -1
- package/cjs/helper/deviceInfo.js +6 -1
- package/cjs/helper/deviceInfo.js.map +1 -1
- package/cjs/helper/getZoneJsOriginalValue.js +2 -1
- package/cjs/helper/getZoneJsOriginalValue.js.map +1 -1
- package/cjs/helper/valueHistory.js +19 -6
- package/cjs/helper/valueHistory.js.map +1 -1
- package/cjs/session/sessionStoreOperations.js +4 -4
- package/cjs/session/sessionStoreOperations.js.map +1 -1
- package/cjs/tracekit/computeStackTrace.js +1 -1
- package/cjs/tracekit/computeStackTrace.js.map +1 -1
- package/cjs/transport/eventBridge.js +8 -1
- package/cjs/transport/eventBridge.js.map +1 -1
- package/esm/browser/addEventListener.js +4 -2
- package/esm/browser/addEventListener.js.map +1 -1
- package/esm/browser/asyncClocks.js +60 -0
- package/esm/browser/asyncClocks.js.map +1 -0
- package/esm/dataMap.js +1 -0
- package/esm/dataMap.js.map +1 -1
- package/esm/helper/deviceInfo.js +6 -1
- package/esm/helper/deviceInfo.js.map +1 -1
- package/esm/helper/getZoneJsOriginalValue.js +2 -1
- package/esm/helper/getZoneJsOriginalValue.js.map +1 -1
- package/esm/helper/valueHistory.js +19 -6
- package/esm/helper/valueHistory.js.map +1 -1
- package/esm/session/sessionStoreOperations.js +4 -4
- package/esm/session/sessionStoreOperations.js.map +1 -1
- package/esm/tracekit/computeStackTrace.js +1 -1
- package/esm/tracekit/computeStackTrace.js.map +1 -1
- package/esm/transport/eventBridge.js +8 -1
- package/esm/transport/eventBridge.js.map +1 -1
- package/package.json +2 -2
- package/src/browser/addEventListener.js +7 -2
- package/src/browser/asyncClocks.js +69 -0
- package/src/dataMap.js +1 -0
- package/src/helper/deviceInfo.js +6 -1
- package/src/helper/getZoneJsOriginalValue.js +2 -1
- package/src/helper/valueHistory.js +18 -6
- package/src/session/sessionStoreOperations.js +4 -16
- package/src/tracekit/computeStackTrace.js +2 -1
- package/src/transport/eventBridge.js +20 -2
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { addEventListener } from './addEventListener'
|
|
2
|
+
import { display } from '../helper/display'
|
|
3
|
+
import { trim } from '../configuration/transportConfiguration'
|
|
4
|
+
let timeOffset
|
|
5
|
+
export function fetchAndApplyRemoteClocks(initConfiguration, callback) {
|
|
6
|
+
const start = performance.now()
|
|
7
|
+
fetchRemoteClocks(initConfiguration, (serverTimestamp) => {
|
|
8
|
+
const end = performance.now()
|
|
9
|
+
const rtt = end - start
|
|
10
|
+
callback(applyRemoteClocks(serverTimestamp, rtt))
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
function applyRemoteClocks(serverTimestamp, rtt) {
|
|
14
|
+
const estimatedClientTime =
|
|
15
|
+
performance.timing.navigationStart + start + rtt / 2
|
|
16
|
+
|
|
17
|
+
// 计算时间偏移
|
|
18
|
+
const offset = serverTimestamp - estimatedClientTime
|
|
19
|
+
return offset
|
|
20
|
+
}
|
|
21
|
+
export function fetchRemoteClocks(configuration, callback) {
|
|
22
|
+
const xhr = new XMLHttpRequest()
|
|
23
|
+
|
|
24
|
+
addEventListener(xhr, 'load', function () {
|
|
25
|
+
if (xhr.status === 200) {
|
|
26
|
+
const remoteConfiguration = JSON.parse(xhr.responseText)
|
|
27
|
+
callback(remoteConfiguration.content)
|
|
28
|
+
} else {
|
|
29
|
+
displayRemoteClocksFetchingError()
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
addEventListener(xhr, 'error', function () {
|
|
34
|
+
callback({})
|
|
35
|
+
displayRemoteClocksFetchingError()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
xhr.open('GET', buildEndpoint(configuration))
|
|
39
|
+
xhr.send()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function buildEndpoint(configuration) {
|
|
43
|
+
var url =
|
|
44
|
+
configuration.datakitOrigin ||
|
|
45
|
+
configuration.datakitUrl ||
|
|
46
|
+
configuration.site
|
|
47
|
+
if (url.indexOf('/') === 0) {
|
|
48
|
+
// 绝对路径这种 /xxx
|
|
49
|
+
url = location.origin + trim(url)
|
|
50
|
+
}
|
|
51
|
+
var endpoint = url
|
|
52
|
+
if (url.lastIndexOf('/') === url.length - 1) {
|
|
53
|
+
endpoint = trim(url) + 'v1/env_variable'
|
|
54
|
+
} else {
|
|
55
|
+
endpoint = trim(url) + '/v1/env_variable'
|
|
56
|
+
}
|
|
57
|
+
// 这里需要加上token和app_id
|
|
58
|
+
endpoint += '?app_id=' + configuration.applicationId
|
|
59
|
+
//testing-openway.dataflux.cn/v1/env_variable?token=a47fb0cdddaa4561a90d941317cdbc0b&app_id=d1b454d0_22eb_11ef_9b66_95ca11aa2c6c&to_headless=true
|
|
60
|
+
if (configuration.site && configuration.clientToken) {
|
|
61
|
+
endpoint =
|
|
62
|
+
endpoint + '&token=' + configuration.clientToken + '&to_headless=true'
|
|
63
|
+
}
|
|
64
|
+
return endpoint
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function displayRemoteClocksFetchingError() {
|
|
68
|
+
display.error('Error fetching the remote configuration.')
|
|
69
|
+
}
|
package/src/dataMap.js
CHANGED
|
@@ -22,6 +22,7 @@ export var commonTags = {
|
|
|
22
22
|
browser_version_major: 'device.browser_version_major',
|
|
23
23
|
screen_size: 'device.screen_size',
|
|
24
24
|
network_type: 'device.network_type',
|
|
25
|
+
time_zone: 'device.time_zone',
|
|
25
26
|
device: 'device.device',
|
|
26
27
|
view_id: 'view.id',
|
|
27
28
|
view_referrer: 'view.referrer',
|
package/src/helper/deviceInfo.js
CHANGED
|
@@ -307,6 +307,10 @@ var MethodLibrary = {
|
|
|
307
307
|
})()
|
|
308
308
|
return _this.language
|
|
309
309
|
}),
|
|
310
|
+
getTimeZone: monitor(function () {
|
|
311
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
312
|
+
return timeZone
|
|
313
|
+
}),
|
|
310
314
|
// 浏览器信息
|
|
311
315
|
getBrowserInfo: monitor(function () {
|
|
312
316
|
var _this = this
|
|
@@ -619,7 +623,8 @@ if (typeof window !== 'undefined') {
|
|
|
619
623
|
browserVersionMajor: MethodLibrary.getBrowserInfo().browserMajor,
|
|
620
624
|
screenSize: window.screen.width + '*' + window.screen.height,
|
|
621
625
|
networkType: MethodLibrary.getNetwork(),
|
|
622
|
-
device: MethodLibrary.getDeviceType()
|
|
626
|
+
device: MethodLibrary.getDeviceType(),
|
|
627
|
+
timeZone: MethodLibrary.getTimeZone()
|
|
623
628
|
}
|
|
624
629
|
}
|
|
625
630
|
export var deviceInfo = _deviceInfo
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getGlobalObject } from '../init'
|
|
1
2
|
/**
|
|
2
3
|
* Gets the original value for a DOM API that was potentially patched by Zone.js.
|
|
3
4
|
*
|
|
@@ -12,7 +13,7 @@
|
|
|
12
13
|
* [1]: https://github.com/angular/angular/tree/main/packages/zone.js
|
|
13
14
|
*/
|
|
14
15
|
export function getZoneJsOriginalValue(target, name) {
|
|
15
|
-
var browserWindow =
|
|
16
|
+
var browserWindow = getGlobalObject()
|
|
16
17
|
var original
|
|
17
18
|
if (
|
|
18
19
|
browserWindow.Zone &&
|
|
@@ -3,7 +3,13 @@ import { setInterval, clearInterval } from './timer'
|
|
|
3
3
|
var END_OF_TIMES = Infinity
|
|
4
4
|
|
|
5
5
|
export var CLEAR_OLD_VALUES_INTERVAL = ONE_MINUTE
|
|
6
|
+
let cleanupHistoriesInterval = null
|
|
6
7
|
|
|
8
|
+
const cleanupTasks = new Set()
|
|
9
|
+
|
|
10
|
+
function cleanupHistories() {
|
|
11
|
+
cleanupTasks.forEach((task) => task())
|
|
12
|
+
}
|
|
7
13
|
/**
|
|
8
14
|
*
|
|
9
15
|
* @param {expireDelay,maxEntries } params
|
|
@@ -14,11 +20,13 @@ export function createValueHistory(params) {
|
|
|
14
20
|
var maxEntries = params.maxEntries
|
|
15
21
|
|
|
16
22
|
var entries = []
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
if (cleanupHistoriesInterval) {
|
|
24
|
+
cleanupHistoriesInterval = setInterval(function () {
|
|
25
|
+
return clearExpiredValues()
|
|
26
|
+
}, CLEAR_OLD_VALUES_INTERVAL)
|
|
27
|
+
}
|
|
20
28
|
|
|
21
|
-
function
|
|
29
|
+
function clearExpiredValues() {
|
|
22
30
|
var oldTimeThreshold = relativeNow() - expireDelay
|
|
23
31
|
while (
|
|
24
32
|
entries.length > 0 &&
|
|
@@ -27,7 +35,7 @@ export function createValueHistory(params) {
|
|
|
27
35
|
entries.pop()
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
|
-
|
|
38
|
+
cleanupTasks.add(clearExpiredValues)
|
|
31
39
|
function add(value, startTime) {
|
|
32
40
|
var entry = {
|
|
33
41
|
value: value,
|
|
@@ -103,7 +111,11 @@ export function createValueHistory(params) {
|
|
|
103
111
|
* Stop internal garbage collection of past entries.
|
|
104
112
|
*/
|
|
105
113
|
function stop() {
|
|
106
|
-
|
|
114
|
+
cleanupTasks.delete(clearExpiredValues)
|
|
115
|
+
if (cleanupTasks.size === 0 && cleanupHistoriesInterval) {
|
|
116
|
+
clearInterval(cleanupHistoriesInterval)
|
|
117
|
+
cleanupHistoriesInterval = null
|
|
118
|
+
}
|
|
107
119
|
}
|
|
108
120
|
|
|
109
121
|
return {
|
|
@@ -48,10 +48,7 @@ export function processSessionStoreOperations(
|
|
|
48
48
|
let currentStore = retrieveStore()
|
|
49
49
|
if (isLockEnabled) {
|
|
50
50
|
// if someone has lock, retry later
|
|
51
|
-
if (
|
|
52
|
-
currentStore.lock &&
|
|
53
|
-
!isSessionInNotStartedState(currentStore.session)
|
|
54
|
-
) {
|
|
51
|
+
if (currentStore.lock) {
|
|
55
52
|
retryLater(operations, sessionStoreStrategy, numberOfRetries)
|
|
56
53
|
return
|
|
57
54
|
}
|
|
@@ -60,10 +57,7 @@ export function processSessionStoreOperations(
|
|
|
60
57
|
persistWithLock(currentStore.session)
|
|
61
58
|
// if lock is not acquired, retry later
|
|
62
59
|
currentStore = retrieveStore()
|
|
63
|
-
if (
|
|
64
|
-
currentStore.lock !== currentLock &&
|
|
65
|
-
!isSessionInNotStartedState(currentStore.session)
|
|
66
|
-
) {
|
|
60
|
+
if (currentStore.lock !== currentLock) {
|
|
67
61
|
retryLater(operations, sessionStoreStrategy, numberOfRetries)
|
|
68
62
|
return
|
|
69
63
|
}
|
|
@@ -72,10 +66,7 @@ export function processSessionStoreOperations(
|
|
|
72
66
|
if (isLockEnabled) {
|
|
73
67
|
// if lock corrupted after process, retry later
|
|
74
68
|
currentStore = retrieveStore()
|
|
75
|
-
if (
|
|
76
|
-
currentStore.lock !== currentLock &&
|
|
77
|
-
!isSessionInNotStartedState(currentStore.session)
|
|
78
|
-
) {
|
|
69
|
+
if (currentStore.lock !== currentLock) {
|
|
79
70
|
retryLater(operations, sessionStoreStrategy, numberOfRetries)
|
|
80
71
|
return
|
|
81
72
|
}
|
|
@@ -96,10 +87,7 @@ export function processSessionStoreOperations(
|
|
|
96
87
|
if (!(processedSession && isSessionInExpiredState(processedSession))) {
|
|
97
88
|
// if lock corrupted after persist, retry later
|
|
98
89
|
currentStore = retrieveStore()
|
|
99
|
-
if (
|
|
100
|
-
currentStore.lock !== currentLock &&
|
|
101
|
-
!isSessionInNotStartedState(currentStore.session)
|
|
102
|
-
) {
|
|
90
|
+
if (currentStore.lock !== currentLock) {
|
|
103
91
|
retryLater(operations, sessionStoreStrategy, numberOfRetries)
|
|
104
92
|
return
|
|
105
93
|
}
|
|
@@ -36,6 +36,7 @@ export function computeStackTrace(ex) {
|
|
|
36
36
|
}
|
|
37
37
|
var fileUrl =
|
|
38
38
|
'((?:file|https?|blob|chrome-extension|electron|native|eval|webpack|<anonymous>|\\w+\\.|\\/).*?)'
|
|
39
|
+
|
|
39
40
|
var filePosition = '(?::(\\d+))'
|
|
40
41
|
var CHROME_LINE_RE = new RegExp(
|
|
41
42
|
'^\\s*at (.*?) ?\\(' +
|
|
@@ -117,7 +118,7 @@ function parseWinLine(line) {
|
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
var GECKO_LINE_RE =
|
|
120
|
-
/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|capacitor|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i
|
|
121
|
+
/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|capacitor|\[native).*?|[^@]*bundle|\[wasm code\])(?::(\d+))?(?::(\d+))?\s*$/i
|
|
121
122
|
var GECKO_EVAL_RE = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i
|
|
122
123
|
|
|
123
124
|
function parseGeckoLine(line) {
|
|
@@ -24,7 +24,11 @@ export function getEventBridge() {
|
|
|
24
24
|
)
|
|
25
25
|
},
|
|
26
26
|
getAllowedWebViewHosts() {
|
|
27
|
-
return JSON.parse(
|
|
27
|
+
return JSON.parse(
|
|
28
|
+
(eventBridgeGlobal.getAllowedWebViewHosts &&
|
|
29
|
+
eventBridgeGlobal.getAllowedWebViewHosts()) ||
|
|
30
|
+
'[]'
|
|
31
|
+
)
|
|
28
32
|
},
|
|
29
33
|
send(eventType, event, viewId) {
|
|
30
34
|
const view = viewId ? { id: viewId } : undefined
|
|
@@ -45,8 +49,22 @@ export function bridgeSupports(capability) {
|
|
|
45
49
|
export function canUseEventBridge(
|
|
46
50
|
currentHost = getGlobalObject().location?.hostname
|
|
47
51
|
) {
|
|
52
|
+
const eventBridgeGlobal = getEventBridgeGlobal()
|
|
53
|
+
if (
|
|
54
|
+
eventBridgeGlobal &&
|
|
55
|
+
eventBridgeGlobal.getAllowedWebViewHosts === undefined
|
|
56
|
+
) {
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
if (
|
|
60
|
+
eventBridgeGlobal &&
|
|
61
|
+
eventBridgeGlobal.getAllowedWebViewHosts &&
|
|
62
|
+
(eventBridgeGlobal.getAllowedWebViewHosts() === null ||
|
|
63
|
+
eventBridgeGlobal.getAllowedWebViewHosts() === undefined)
|
|
64
|
+
) {
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
48
67
|
var bridge = getEventBridge()
|
|
49
|
-
|
|
50
68
|
return (
|
|
51
69
|
!!bridge &&
|
|
52
70
|
bridge
|