web-tracing-core 2.1.0 → 2.1.2
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/__test__/performance.spec.ts +3 -0
- package/__test__/utils/index.ts +33 -0
- package/dist/README.md +8 -0
- package/dist/index.cjs +23 -4
- package/dist/index.iife.js +23 -4
- package/dist/index.iife.min.js +9 -9
- package/dist/index.mjs +23 -4
- package/dist/package.json +1 -1
- package/index.ts +1 -0
- package/package.json +2 -2
- package/src/lib/intersectionObserver.ts +6 -1
- package/src/utils/global.ts +2 -1
- package/src/utils/index.ts +4 -3
- package/src/utils/polyfill.ts +11 -0
- package/src/utils/session.ts +3 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
if (typeof window === "undefined" && typeof global !== "undefined") {
|
|
2
|
+
global.window = global;
|
|
3
|
+
global.self = global;
|
|
4
|
+
if (!global.requestAnimationFrame) {
|
|
5
|
+
global.requestAnimationFrame = (callback) => setTimeout(callback, 0);
|
|
6
|
+
}
|
|
7
|
+
if (!global.cancelAnimationFrame) {
|
|
8
|
+
global.cancelAnimationFrame = (id) => clearTimeout(id);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
function isType(type) {
|
|
2
13
|
return function(value) {
|
|
3
14
|
return Object.prototype.toString.call(value) === `[object ${type}]`;
|
|
@@ -18,7 +29,7 @@ function isEmpty(wat) {
|
|
|
18
29
|
}
|
|
19
30
|
|
|
20
31
|
const isBrowserEnv = isWindow(typeof window !== "undefined" ? window : 0);
|
|
21
|
-
const isElectronEnv = !!window
|
|
32
|
+
const isElectronEnv = typeof window !== "undefined" && !!window.process?.versions?.electron;
|
|
22
33
|
const isTestEnv = typeof navigator !== "undefined" && navigator.userAgent.includes("jsdom") || // @ts-expect-error: jsdom
|
|
23
34
|
typeof window !== "undefined" && window.jsdom;
|
|
24
35
|
function getGlobal() {
|
|
@@ -677,6 +688,8 @@ function uuid() {
|
|
|
677
688
|
return `${guid.slice(0, 8)}-${guid.slice(8, 16)}-${guid.slice(16)}`;
|
|
678
689
|
}
|
|
679
690
|
function getCookieByName(name) {
|
|
691
|
+
if (typeof document === "undefined")
|
|
692
|
+
return void 0;
|
|
680
693
|
const result = document.cookie.match(new RegExp(`${name}=([^;]+)(;|$)`));
|
|
681
694
|
return result ? result[1] : void 0;
|
|
682
695
|
}
|
|
@@ -760,7 +773,7 @@ const arrayFilter = Array.prototype.filter || function filterPolyfill(fn) {
|
|
|
760
773
|
function filter(arr, fn) {
|
|
761
774
|
return arrayFilter.call(arr, fn);
|
|
762
775
|
}
|
|
763
|
-
const nextTime = window.requestIdleCallback || window.requestAnimationFrame || ((callback) => setTimeout(callback, 17));
|
|
776
|
+
const nextTime = typeof window !== "undefined" && window.requestIdleCallback || typeof window !== "undefined" && window.requestAnimationFrame || ((callback) => setTimeout(callback, 17));
|
|
764
777
|
function isObjectOverSizeLimit(object, limitInKB) {
|
|
765
778
|
const serializedObject = JSON.stringify(object);
|
|
766
779
|
const sizeInBytes = new TextEncoder().encode(serializedObject).length;
|
|
@@ -2832,7 +2845,9 @@ function refreshSession() {
|
|
|
2832
2845
|
function getSessionId() {
|
|
2833
2846
|
return getCookieByName(SESSION_KEY) || refreshSession();
|
|
2834
2847
|
}
|
|
2835
|
-
|
|
2848
|
+
if (typeof document !== "undefined") {
|
|
2849
|
+
refreshSession();
|
|
2850
|
+
}
|
|
2836
2851
|
|
|
2837
2852
|
function is_ipv4(d) {
|
|
2838
2853
|
return regex_v4.test(d);
|
|
@@ -15677,7 +15692,11 @@ class Intersection {
|
|
|
15677
15692
|
sendData.emit({
|
|
15678
15693
|
eventType: SEDNEVENTTYPES.INTERSECTION,
|
|
15679
15694
|
triggerPageUrl: getLocationHref(),
|
|
15680
|
-
|
|
15695
|
+
threshold: targetObj.threshold,
|
|
15696
|
+
observeTime: targetObj.observeTime,
|
|
15697
|
+
showTime: targetObj.showTime,
|
|
15698
|
+
showEndTime: targetObj.showEndTime,
|
|
15699
|
+
params: targetObj.params
|
|
15681
15700
|
});
|
|
15682
15701
|
}
|
|
15683
15702
|
/**
|
package/dist/package.json
CHANGED
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "web-tracing-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "基于 JS 跨平台插件,为前端项目提供【 埋点、行为、性能、异常、请求、资源、路由、曝光、录屏 】监控手段",
|
|
5
|
-
"main": "./dist/index.
|
|
5
|
+
"main": "./dist/index.mjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"jsdelivr": "./dist/index.iife.min.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -69,10 +69,15 @@ class Intersection {
|
|
|
69
69
|
* 发送事件
|
|
70
70
|
*/
|
|
71
71
|
private sendEvent(targetObj: TargetMap) {
|
|
72
|
+
// 只发送必要的数据,不包含 DOM 元素
|
|
72
73
|
sendData.emit({
|
|
73
74
|
eventType: SEDNEVENTTYPES.INTERSECTION,
|
|
74
75
|
triggerPageUrl: getLocationHref(),
|
|
75
|
-
|
|
76
|
+
threshold: targetObj.threshold,
|
|
77
|
+
observeTime: targetObj.observeTime,
|
|
78
|
+
showTime: targetObj.showTime,
|
|
79
|
+
showEndTime: targetObj.showEndTime,
|
|
80
|
+
params: targetObj.params
|
|
76
81
|
})
|
|
77
82
|
}
|
|
78
83
|
/**
|
package/src/utils/global.ts
CHANGED
|
@@ -9,7 +9,8 @@ export const isBrowserEnv = isWindow(typeof window !== 'undefined' ? window : 0)
|
|
|
9
9
|
/**
|
|
10
10
|
* 是否为 electron 环境
|
|
11
11
|
*/
|
|
12
|
-
export const isElectronEnv =
|
|
12
|
+
export const isElectronEnv =
|
|
13
|
+
typeof window !== 'undefined' && !!(window as any).process?.versions?.electron
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* 是否为测试环境
|
package/src/utils/index.ts
CHANGED
|
@@ -284,6 +284,7 @@ export function uuid() {
|
|
|
284
284
|
* @returns
|
|
285
285
|
*/
|
|
286
286
|
export function getCookieByName(name: string) {
|
|
287
|
+
if (typeof document === 'undefined') return undefined
|
|
287
288
|
const result = document.cookie.match(new RegExp(`${name}=([^;]+)(;|$)`))
|
|
288
289
|
return result ? result[1] : undefined
|
|
289
290
|
}
|
|
@@ -459,9 +460,9 @@ export function trim(str = '') {
|
|
|
459
460
|
* 关于 requestIdleCallback 和 requestAnimationFrame 可以参考 https://www.cnblogs.com/cangqinglang/p/13877078.html
|
|
460
461
|
*/
|
|
461
462
|
export const nextTime =
|
|
462
|
-
window.requestIdleCallback ||
|
|
463
|
-
window.requestAnimationFrame ||
|
|
464
|
-
(callback => setTimeout(callback, 17))
|
|
463
|
+
(typeof window !== 'undefined' && window.requestIdleCallback) ||
|
|
464
|
+
(typeof window !== 'undefined' && window.requestAnimationFrame) ||
|
|
465
|
+
((callback: any) => setTimeout(callback, 17))
|
|
465
466
|
|
|
466
467
|
/**
|
|
467
468
|
* 取消异步执行
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
if (typeof window === 'undefined' && typeof global !== 'undefined') {
|
|
2
|
+
;(global as any).window = global
|
|
3
|
+
;(global as any).self = global
|
|
4
|
+
if (!(global as any).requestAnimationFrame) {
|
|
5
|
+
;(global as any).requestAnimationFrame = (callback: any) =>
|
|
6
|
+
setTimeout(callback, 0)
|
|
7
|
+
}
|
|
8
|
+
if (!(global as any).cancelAnimationFrame) {
|
|
9
|
+
;(global as any).cancelAnimationFrame = (id: any) => clearTimeout(id)
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/utils/session.ts
CHANGED