tdem-web-sdk 1.0.1
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/README.md +946 -0
- package/lib/packages/core/src/constant/config.d.ts +14 -0
- package/lib/packages/core/src/constant/global.d.ts +1 -0
- package/lib/packages/core/src/constant/index.d.ts +9 -0
- package/lib/packages/core/src/constant/report-ignore.d.ts +2 -0
- package/lib/packages/core/src/core.d.ts +150 -0
- package/lib/packages/core/src/hooks/afterRequestHooks.d.ts +3 -0
- package/lib/packages/core/src/hooks/beforeRequestHooks.d.ts +9 -0
- package/lib/packages/core/src/hooks/modifyRequestHooks.d.ts +3 -0
- package/lib/packages/core/src/index.d.ts +9 -0
- package/lib/packages/core/src/interface/config.d.ts +77 -0
- package/lib/packages/core/src/interface/env.d.ts +11 -0
- package/lib/packages/core/src/interface/event.d.ts +465 -0
- package/lib/packages/core/src/interface/index.d.ts +5 -0
- package/lib/packages/core/src/interface/log.d.ts +130 -0
- package/lib/packages/core/src/interface/send.d.ts +36 -0
- package/lib/packages/core/src/pipes/event-pipes.d.ts +22 -0
- package/lib/packages/core/src/pipes/group-by-from.d.ts +8 -0
- package/lib/packages/core/src/pipes/index.d.ts +16 -0
- package/lib/packages/core/src/pipes/remove-payload.d.ts +2 -0
- package/lib/packages/core/src/pipes/repeat-limit.d.ts +3 -0
- package/lib/packages/core/src/pipes/sample.d.ts +3 -0
- package/lib/packages/core/src/pipes/tdem-sample-gate.d.ts +36 -0
- package/lib/packages/core/src/pipes/throttle.d.ts +3 -0
- package/lib/packages/core/src/pipes/trace/index.d.ts +34 -0
- package/lib/packages/core/src/pipes/trace/jwt.d.ts +12 -0
- package/lib/packages/core/src/pipes/trace/ot-js.d.ts +14 -0
- package/lib/packages/core/src/pipes/trace/uuid.d.ts +2 -0
- package/lib/packages/core/src/plugin.d.ts +33 -0
- package/lib/packages/core/src/polyfill.d.ts +0 -0
- package/lib/packages/core/src/util/destroy.d.ts +2 -0
- package/lib/packages/core/src/util/event-emitter.d.ts +18 -0
- package/lib/packages/core/src/util/index.d.ts +70 -0
- package/lib/packages/core/src/util/storage.d.ts +12 -0
- package/lib/packages/web-sdk/src/constant/index.d.ts +8 -0
- package/lib/packages/web-sdk/src/index.d.ts +4 -0
- package/lib/packages/web-sdk/src/interface/index.d.ts +104 -0
- package/lib/packages/web-sdk/src/pipes/refresh-network.d.ts +2 -0
- package/lib/packages/web-sdk/src/plugins/aid.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/asset-speed.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/bridge-speed.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/cgi-speed/hack-http.d.ts +17 -0
- package/lib/packages/web-sdk/src/plugins/cgi-speed/index.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/cgi-speed/trace.d.ts +8 -0
- package/lib/packages/web-sdk/src/plugins/cgi-speed/utils.d.ts +33 -0
- package/lib/packages/web-sdk/src/plugins/click-element.d.ts +8 -0
- package/lib/packages/web-sdk/src/plugins/console-info.d.ts +6 -0
- package/lib/packages/web-sdk/src/plugins/device-info.d.ts +24 -0
- package/lib/packages/web-sdk/src/plugins/finger/finger-print.d.ts +8 -0
- package/lib/packages/web-sdk/src/plugins/finger/finger-util.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/finger/index.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/finger/murmur-hash-32.d.ts +9 -0
- package/lib/packages/web-sdk/src/plugins/finger/murmur-hash.d.ts +2 -0
- package/lib/packages/web-sdk/src/plugins/ie-patch.d.ts +6 -0
- package/lib/packages/web-sdk/src/plugins/index.d.ts +17 -0
- package/lib/packages/web-sdk/src/plugins/on-close.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/on-error.d.ts +6 -0
- package/lib/packages/web-sdk/src/plugins/page-performance.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/click-detector.d.ts +129 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/compression-worker.d.ts +54 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/constants.d.ts +39 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/event-buffer.d.ts +89 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/index.d.ts +22 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/logger.d.ts +35 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/mutation-merger.d.ts +112 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/privacy.d.ts +87 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/recorder-manager.d.ts +83 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/sampler-manager.d.ts +67 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/session-manager.d.ts +74 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/types.d.ts +222 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/uploader.d.ts +36 -0
- package/lib/packages/web-sdk/src/plugins/spa.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/struggle-monitor.d.ts +38 -0
- package/lib/packages/web-sdk/src/plugins/tdem-config.d.ts +13 -0
- package/lib/packages/web-sdk/src/plugins/tti.d.ts +1 -0
- package/lib/packages/web-sdk/src/plugins/web-vitals.d.ts +6 -0
- package/lib/packages/web-sdk/src/polyfill.d.ts +0 -0
- package/lib/packages/web-sdk/src/tdem.d.ts +51 -0
- package/lib/packages/web-sdk/src/util/device-type.d.ts +3 -0
- package/lib/packages/web-sdk/src/util/event.d.ts +9 -0
- package/lib/packages/web-sdk/src/util/hack-websocket.d.ts +4 -0
- package/lib/packages/web-sdk/src/util/index.d.ts +4 -0
- package/lib/packages/web-sdk/src/util/ot-js.d.ts +14 -0
- package/lib/packages/web-sdk/src/util/replay-context.d.ts +54 -0
- package/lib/packages/web-sdk/src/util/shared-session.d.ts +40 -0
- package/lib/packages/web-sdk/src/util/uuid.d.ts +1 -0
- package/lib/packages/web-sdk/src/utils/math.d.ts +26 -0
- package/lib/tdem.f.min.js +10 -0
- package/lib/tdem.global.min.js +10 -0
- package/lib/tdem.ie.min.js +10 -0
- package/lib/tdem.min.js +10 -0
- package/package.json +20 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClickDetector - 点击检测器
|
|
3
|
+
*
|
|
4
|
+
* 检测用户体验问题:
|
|
5
|
+
* - 慢点击(点击后响应缓慢)
|
|
6
|
+
* - 愤怒点击(短时间内多次点击同一元素)
|
|
7
|
+
* - 死点击(点击无响应)
|
|
8
|
+
*/
|
|
9
|
+
/** 点击检测器选项 */
|
|
10
|
+
export interface ClickDetectorOptions {
|
|
11
|
+
/** 慢点击超时时间(毫秒),默认 7000 */
|
|
12
|
+
slowClickTimeout?: number;
|
|
13
|
+
/** 慢点击阈值(毫秒),超过此时间认为是慢点击,默认 3000 */
|
|
14
|
+
slowClickThreshold?: number;
|
|
15
|
+
/** 愤怒点击次数阈值,默认 5 */
|
|
16
|
+
rageClickCount?: number;
|
|
17
|
+
/** 愤怒点击时间窗口(毫秒),默认 1000 */
|
|
18
|
+
rageClickWindow?: number;
|
|
19
|
+
/** 慢点击回调 */
|
|
20
|
+
onSlowClick?: (data: SlowClickData) => void;
|
|
21
|
+
/** 愤怒点击回调 */
|
|
22
|
+
onRageClick?: (data: RageClickData) => void;
|
|
23
|
+
/** 死点击回调 */
|
|
24
|
+
onDeadClick?: (data: DeadClickData) => void;
|
|
25
|
+
}
|
|
26
|
+
/** 慢点击数据 */
|
|
27
|
+
export interface SlowClickData {
|
|
28
|
+
/** 点击的元素信息 */
|
|
29
|
+
node: ClickNodeInfo;
|
|
30
|
+
/** 点击后到响应的时间(毫秒) */
|
|
31
|
+
timeAfterClickMs: number;
|
|
32
|
+
/** 结束原因 */
|
|
33
|
+
endReason: 'timeout' | 'mutation' | 'navigation';
|
|
34
|
+
/** 点击时间戳 */
|
|
35
|
+
timestamp: number;
|
|
36
|
+
}
|
|
37
|
+
/** 愤怒点击数据 */
|
|
38
|
+
export interface RageClickData {
|
|
39
|
+
/** 点击的元素信息 */
|
|
40
|
+
node: ClickNodeInfo;
|
|
41
|
+
/** 点击次数 */
|
|
42
|
+
clickCount: number;
|
|
43
|
+
/** 时间窗口(毫秒) */
|
|
44
|
+
timeWindowMs: number;
|
|
45
|
+
/** 开始时间戳 */
|
|
46
|
+
timestamp: number;
|
|
47
|
+
}
|
|
48
|
+
/** 死点击数据 */
|
|
49
|
+
export interface DeadClickData {
|
|
50
|
+
/** 点击的元素信息 */
|
|
51
|
+
node: ClickNodeInfo;
|
|
52
|
+
/** 点击时间戳 */
|
|
53
|
+
timestamp: number;
|
|
54
|
+
}
|
|
55
|
+
/** 点击节点信息 */
|
|
56
|
+
export interface ClickNodeInfo {
|
|
57
|
+
/** rrweb 节点 ID */
|
|
58
|
+
id: number;
|
|
59
|
+
/** 标签名 */
|
|
60
|
+
tagName: string;
|
|
61
|
+
/** 文本内容(截取) */
|
|
62
|
+
textContent: string;
|
|
63
|
+
/** CSS 选择器 */
|
|
64
|
+
selector?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* ClickDetector - 点击行为检测器
|
|
68
|
+
*/
|
|
69
|
+
export declare class ClickDetector {
|
|
70
|
+
private options;
|
|
71
|
+
private isRunning;
|
|
72
|
+
private clickStartTime;
|
|
73
|
+
private clickNode;
|
|
74
|
+
private slowClickTimeoutId;
|
|
75
|
+
private mutationObserver;
|
|
76
|
+
private clickHistory;
|
|
77
|
+
private rageActiveTarget;
|
|
78
|
+
private rageLastClickTime;
|
|
79
|
+
constructor(options?: ClickDetectorOptions);
|
|
80
|
+
/**
|
|
81
|
+
* 启动检测
|
|
82
|
+
*/
|
|
83
|
+
start(): void;
|
|
84
|
+
/**
|
|
85
|
+
* 停止检测
|
|
86
|
+
*/
|
|
87
|
+
stop(): void;
|
|
88
|
+
/**
|
|
89
|
+
* 处理 pointerdown 事件(用于慢点击检测)
|
|
90
|
+
*/
|
|
91
|
+
private handlePointerDown;
|
|
92
|
+
/**
|
|
93
|
+
* 处理 click 事件(用于愤怒点击检测)
|
|
94
|
+
*/
|
|
95
|
+
private handleClick;
|
|
96
|
+
/**
|
|
97
|
+
* 启动 MutationObserver
|
|
98
|
+
*/
|
|
99
|
+
private startMutationObserver;
|
|
100
|
+
/**
|
|
101
|
+
* 检查是否有有意义的 DOM 突变
|
|
102
|
+
*/
|
|
103
|
+
private hasSignificantMutation;
|
|
104
|
+
/**
|
|
105
|
+
* 处理慢点击
|
|
106
|
+
*/
|
|
107
|
+
private handleSlowClick;
|
|
108
|
+
/**
|
|
109
|
+
* 清理慢点击检测状态
|
|
110
|
+
*/
|
|
111
|
+
private cleanupSlowClick;
|
|
112
|
+
private isSameTarget;
|
|
113
|
+
/**
|
|
114
|
+
* 检查是否为可点击元素
|
|
115
|
+
*/
|
|
116
|
+
private isClickableElement;
|
|
117
|
+
/**
|
|
118
|
+
* 获取节点信息
|
|
119
|
+
*/
|
|
120
|
+
private getNodeInfo;
|
|
121
|
+
/**
|
|
122
|
+
* 获取元素的 CSS 选择器
|
|
123
|
+
*/
|
|
124
|
+
private getSelector;
|
|
125
|
+
/**
|
|
126
|
+
* 获取运行状态
|
|
127
|
+
*/
|
|
128
|
+
isActive(): boolean;
|
|
129
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CompressionWorker - Web Worker 压缩模块
|
|
3
|
+
*
|
|
4
|
+
* 将事件压缩逻辑卸载到 Worker 线程,避免阻塞主线程。
|
|
5
|
+
* 使用 inline Blob URL 方式创建 Worker(兼容 rollup UMD 构建)。
|
|
6
|
+
*
|
|
7
|
+
* 通信协议:
|
|
8
|
+
* - 主线程 → Worker: { id, method: 'addEvent'|'finish'|'clear', arg? }
|
|
9
|
+
* - Worker → 主线程: { id, method, success, response }
|
|
10
|
+
* - Worker 就绪信号: { method: 'init', success: true }
|
|
11
|
+
*
|
|
12
|
+
* 降级策略:
|
|
13
|
+
* - Worker 不可用时(CSP 限制、浏览器不支持等)返回 null,调用方降级为同步缓冲
|
|
14
|
+
*/
|
|
15
|
+
/** Worker 请求 */
|
|
16
|
+
interface WorkerRequest {
|
|
17
|
+
id: number;
|
|
18
|
+
method: 'addEvent' | 'finish' | 'clear';
|
|
19
|
+
arg?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* WorkerHandler - Worker 通信封装
|
|
23
|
+
*
|
|
24
|
+
* 将 postMessage/onmessage 的回调模式封装为 Promise,支持并发消息(通过 id 匹配)。
|
|
25
|
+
*/
|
|
26
|
+
export declare class WorkerHandler {
|
|
27
|
+
private worker;
|
|
28
|
+
private nextId;
|
|
29
|
+
private pendingRequests;
|
|
30
|
+
private ready;
|
|
31
|
+
constructor(worker: Worker);
|
|
32
|
+
/**
|
|
33
|
+
* 等待 Worker 就绪
|
|
34
|
+
*/
|
|
35
|
+
ensureReady(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 发送消息并等待响应
|
|
38
|
+
*/
|
|
39
|
+
postMessage(method: WorkerRequest['method'], arg?: string): Promise<any>;
|
|
40
|
+
/**
|
|
41
|
+
* 销毁 Worker
|
|
42
|
+
*/
|
|
43
|
+
destroy(): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 创建 Compression Worker
|
|
47
|
+
*
|
|
48
|
+
* 使用 Blob URL 内联 Worker 代码,兼容 rollup UMD 构建。
|
|
49
|
+
* 如果浏览器不支持 Worker 或 Blob URL(如 CSP 限制),返回 null。
|
|
50
|
+
*
|
|
51
|
+
* @returns WorkerHandler 实例,或 null 表示不可用需降级
|
|
52
|
+
*/
|
|
53
|
+
export declare function createCompressionWorker(): WorkerHandler | null;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话回放常量定义
|
|
3
|
+
*/
|
|
4
|
+
/** 会话空闲暂停时间 (5分钟) */
|
|
5
|
+
export declare const SESSION_IDLE_PAUSE_DURATION: number;
|
|
6
|
+
/** 会话空闲过期时间 (15分钟) */
|
|
7
|
+
export declare const SESSION_IDLE_EXPIRE_DURATION: number;
|
|
8
|
+
/** 会话最大时长 (60分钟) */
|
|
9
|
+
export declare const MAX_SESSION_DURATION: number;
|
|
10
|
+
/** 录制最大时长 (60分钟) */
|
|
11
|
+
export declare const MAX_REPLAY_DURATION: number;
|
|
12
|
+
/** 录制最小时长 (5秒) */
|
|
13
|
+
export declare const MIN_REPLAY_DURATION: number;
|
|
14
|
+
/** 事件缓冲区最大大小 (5MB) */
|
|
15
|
+
export declare const MAX_BUFFER_SIZE: number;
|
|
16
|
+
/** 单个 Segment 上报最大大小 (3MB),需小于后端 maxEventsSizeBytes(5MB) */
|
|
17
|
+
export declare const MAX_SEGMENT_SIZE: number;
|
|
18
|
+
/** 默认 flush 间隔 (20秒) */
|
|
19
|
+
export declare const DEFAULT_FLUSH_INTERVAL: number;
|
|
20
|
+
/** 最小 flush 事件数量 (至少10个事件才上报) */
|
|
21
|
+
export declare const MIN_FLUSH_EVENT_COUNT = 10;
|
|
22
|
+
/** session 模式 checkout 间隔 (5分钟) */
|
|
23
|
+
export declare const SESSION_CHECKOUT_EVERY_NMS: number;
|
|
24
|
+
/** buffer 模式 checkout 间隔 (2分钟) */
|
|
25
|
+
export declare const BUFFER_CHECKOUT_EVERY_NMS: number;
|
|
26
|
+
/** 默认会话采样率 (10%) */
|
|
27
|
+
export declare const DEFAULT_SESSION_SAMPLE_RATE = 0.1;
|
|
28
|
+
/** 默认错误采样率 (100%) */
|
|
29
|
+
export declare const DEFAULT_ERROR_SAMPLE_RATE = 1;
|
|
30
|
+
/** Session 存储 key */
|
|
31
|
+
export declare const SESSION_STORAGE_KEY = "tdem_session";
|
|
32
|
+
/** 上报 API 路径 */
|
|
33
|
+
export declare const REPLAY_UPLOAD_PATH = "/api/v1/collect/replay";
|
|
34
|
+
/** 最大重试次数 */
|
|
35
|
+
export declare const MAX_UPLOAD_RETRIES = 3;
|
|
36
|
+
/** 滚动采样间隔 (ms) */
|
|
37
|
+
export declare const SCROLL_SAMPLING_INTERVAL = 150;
|
|
38
|
+
/** 鼠标移动采样间隔 (ms) */
|
|
39
|
+
export declare const MOUSE_MOVE_SAMPLING_INTERVAL = 50;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { eventWithTime } from '@rrweb/types';
|
|
2
|
+
import { EventBufferConfig, BufferFinishResult } from './types';
|
|
3
|
+
export declare class EventBuffer {
|
|
4
|
+
private events;
|
|
5
|
+
private currentSize;
|
|
6
|
+
private config;
|
|
7
|
+
private workerHandler;
|
|
8
|
+
private useWorker;
|
|
9
|
+
private workerReady;
|
|
10
|
+
private workerEventCount;
|
|
11
|
+
private workerSize;
|
|
12
|
+
constructor(config?: EventBufferConfig, useCompression?: boolean);
|
|
13
|
+
/**
|
|
14
|
+
* 初始化 Worker(异步)
|
|
15
|
+
* Worker 加载期间事件先写入同步数组,就绪后迁移
|
|
16
|
+
*/
|
|
17
|
+
private initWorker;
|
|
18
|
+
/**
|
|
19
|
+
* 将同步数组中已有的事件迁移到 Worker
|
|
20
|
+
*/
|
|
21
|
+
private migrateEventsToWorker;
|
|
22
|
+
/**
|
|
23
|
+
* 将事件发送到 Worker
|
|
24
|
+
*/
|
|
25
|
+
private addEventToWorker;
|
|
26
|
+
/**
|
|
27
|
+
* 添加事件到缓冲区
|
|
28
|
+
*/
|
|
29
|
+
addEvent(event: eventWithTime): void;
|
|
30
|
+
/**
|
|
31
|
+
* 获取所有事件
|
|
32
|
+
*/
|
|
33
|
+
getEvents(): eventWithTime[];
|
|
34
|
+
/**
|
|
35
|
+
* 获取事件数量
|
|
36
|
+
*/
|
|
37
|
+
getEventCount(): number;
|
|
38
|
+
/**
|
|
39
|
+
* 获取当前缓冲区大小(字节)
|
|
40
|
+
*/
|
|
41
|
+
getSize(): number;
|
|
42
|
+
/**
|
|
43
|
+
* 检查缓冲区是否为空
|
|
44
|
+
*/
|
|
45
|
+
isEmpty(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 完成缓冲并返回结果
|
|
48
|
+
*
|
|
49
|
+
* Worker 模式下返回的 events 为空数组,eventsJson 包含已拼接好的 JSON 字符串。
|
|
50
|
+
* 调用方应优先使用 eventsJson(如果存在),否则使用 events。
|
|
51
|
+
*/
|
|
52
|
+
finishAsync(): Promise<BufferFinishResult & {
|
|
53
|
+
eventsJson?: string;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* 完成缓冲并返回结果(同步接口,兼容旧逻辑)
|
|
57
|
+
*/
|
|
58
|
+
finish(): BufferFinishResult;
|
|
59
|
+
/**
|
|
60
|
+
* 清空缓冲区
|
|
61
|
+
*/
|
|
62
|
+
clear(): void;
|
|
63
|
+
/**
|
|
64
|
+
* 销毁(释放 Worker)
|
|
65
|
+
*/
|
|
66
|
+
destroy(): void;
|
|
67
|
+
/**
|
|
68
|
+
* 估算事件大小
|
|
69
|
+
*/
|
|
70
|
+
private estimateEventSize;
|
|
71
|
+
/**
|
|
72
|
+
* 移除旧事件以腾出空间
|
|
73
|
+
* 保护最近一组 Meta(4) + FullSnapshot(2) 不被移除,
|
|
74
|
+
* 确保缓冲区始终能生成可播放的 segment。
|
|
75
|
+
*/
|
|
76
|
+
private trimOldEvents;
|
|
77
|
+
/**
|
|
78
|
+
* 检查是否有全量快照
|
|
79
|
+
*/
|
|
80
|
+
hasCheckout(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* 获取最新的快照时间
|
|
83
|
+
*/
|
|
84
|
+
getLastCheckoutTime(): number | null;
|
|
85
|
+
/**
|
|
86
|
+
* 是否正在使用 Worker 压缩
|
|
87
|
+
*/
|
|
88
|
+
isUsingWorker(): boolean;
|
|
89
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionReplay Plugin - 会话回放插件
|
|
3
|
+
*
|
|
4
|
+
* 提供网页会话录制和回放功能:
|
|
5
|
+
* - 基于 rrweb 实现 DOM 录制
|
|
6
|
+
* - 支持会话采样
|
|
7
|
+
* - 支持错误关联
|
|
8
|
+
* - 支持隐私保护
|
|
9
|
+
* - 支持慢点击/愤怒点击检测
|
|
10
|
+
*/
|
|
11
|
+
import Core, { Plugin } from "../../../../core/src";
|
|
12
|
+
export { SessionManager } from './session-manager';
|
|
13
|
+
export { EventBuffer } from './event-buffer';
|
|
14
|
+
export { RecorderManager } from './recorder-manager';
|
|
15
|
+
export { SamplerManager } from './sampler-manager';
|
|
16
|
+
export { Uploader } from './uploader';
|
|
17
|
+
export { ClickDetector } from './click-detector';
|
|
18
|
+
export * from './types';
|
|
19
|
+
export * from './constants';
|
|
20
|
+
export * from './privacy';
|
|
21
|
+
declare let plugin: Plugin<Core>;
|
|
22
|
+
export default plugin;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionReplay Logger - 统一日志管理
|
|
3
|
+
*
|
|
4
|
+
* 所有 session-replay 模块的日志统一通过此模块输出:
|
|
5
|
+
* - 支持 debug 开关,默认关闭,生产环境不输出任何日志
|
|
6
|
+
* - 避免 console.warn/error 被日志监控误杀
|
|
7
|
+
* - 统一前缀格式 [SessionReplay:模块名]
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* 设置 debug 模式
|
|
11
|
+
* @param enabled true 时输出所有级别日志,false 时静默
|
|
12
|
+
*/
|
|
13
|
+
export declare function setDebugMode(enabled: boolean): void;
|
|
14
|
+
/**
|
|
15
|
+
* 获取 debug 模式状态
|
|
16
|
+
*/
|
|
17
|
+
export declare function isDebugMode(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 普通信息日志(debug 模式下输出)
|
|
20
|
+
*/
|
|
21
|
+
export declare function logInfo(module: string, ...args: any[]): void;
|
|
22
|
+
/**
|
|
23
|
+
* 调试日志(debug 模式下输出)
|
|
24
|
+
*/
|
|
25
|
+
export declare function logDebug(module: string, ...args: any[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* 警告日志(debug 模式下输出)
|
|
28
|
+
* 不使用 console.warn,避免被日志监控捕获
|
|
29
|
+
*/
|
|
30
|
+
export declare function logWarn(module: string, ...args: any[]): void;
|
|
31
|
+
/**
|
|
32
|
+
* 错误日志(始终输出,因为错误通常需要被感知)
|
|
33
|
+
* 使用 console.log 而非 console.error,避免被日志监控误杀
|
|
34
|
+
*/
|
|
35
|
+
export declare function logError(module: string, ...args: any[]): void;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MutationMerger - Mutation 事件合并层
|
|
3
|
+
*
|
|
4
|
+
* 在 rrweb emit 和 EventBuffer 之间插入,将短时间内的多个 Mutation 合并为一个。
|
|
5
|
+
* 核心策略:
|
|
6
|
+
* 1. 200ms 合并窗口:窗口内的 Mutation 合并后一次性输出
|
|
7
|
+
* 2. 同一父节点的 adds 去重:重复结构只保留最新
|
|
8
|
+
* 3. adds/removes 抵消:先加后删 = 不录
|
|
9
|
+
* 4. attributes/texts 覆盖:同一节点的多次变更只保留最后一次
|
|
10
|
+
* 5. 重复模式检测:连续相同结构的 Mutation 只保留最后一帧
|
|
11
|
+
*/
|
|
12
|
+
/** Mutation 数据结构(简化版,兼容 rrweb) */
|
|
13
|
+
interface MutationAdd {
|
|
14
|
+
parentId: number;
|
|
15
|
+
nextId?: number | null;
|
|
16
|
+
node: {
|
|
17
|
+
id?: number;
|
|
18
|
+
tagName?: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
interface MutationRemove {
|
|
24
|
+
parentId: number;
|
|
25
|
+
id: number;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface MutationAttribute {
|
|
29
|
+
id: number;
|
|
30
|
+
attributes: Record<string, unknown>;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface MutationText {
|
|
34
|
+
id: number;
|
|
35
|
+
value: string | null;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
interface MutationData {
|
|
39
|
+
source: number;
|
|
40
|
+
adds?: MutationAdd[];
|
|
41
|
+
removes?: MutationRemove[];
|
|
42
|
+
attributes?: MutationAttribute[];
|
|
43
|
+
texts?: MutationText[];
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
interface RRWebEvent {
|
|
47
|
+
type: number;
|
|
48
|
+
timestamp: number;
|
|
49
|
+
data?: MutationData | Record<string, unknown>;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
export interface MutationMergerOptions {
|
|
53
|
+
/** 合并窗口时长(毫秒),默认 200 */
|
|
54
|
+
windowMs?: number;
|
|
55
|
+
/** 单次合并最大 adds 数量,超过立即 flush,默认 500 */
|
|
56
|
+
maxAddsPerMerge?: number;
|
|
57
|
+
/** 启用重复模式检测,默认 true */
|
|
58
|
+
enableRepeatDetection?: boolean;
|
|
59
|
+
}
|
|
60
|
+
declare type EmitFn = (event: RRWebEvent) => void;
|
|
61
|
+
export declare class MutationMerger {
|
|
62
|
+
private buffer;
|
|
63
|
+
private flushTimer;
|
|
64
|
+
private repeatCount;
|
|
65
|
+
private emitFn;
|
|
66
|
+
private windowMs;
|
|
67
|
+
private maxAddsPerMerge;
|
|
68
|
+
private enableRepeatDetection;
|
|
69
|
+
private mergedCount;
|
|
70
|
+
private droppedByRepeat;
|
|
71
|
+
private cancelledByOffset;
|
|
72
|
+
constructor(options?: MutationMergerOptions);
|
|
73
|
+
/**
|
|
74
|
+
* 推入一个 rrweb 事件
|
|
75
|
+
* - 非 Mutation 事件直接透传
|
|
76
|
+
* - Mutation 事件进入合并窗口
|
|
77
|
+
*/
|
|
78
|
+
push(event: RRWebEvent, emit: EmitFn): void;
|
|
79
|
+
/**
|
|
80
|
+
* 立即输出缓冲区中的事件
|
|
81
|
+
*/
|
|
82
|
+
flush(): void;
|
|
83
|
+
/**
|
|
84
|
+
* 销毁(停止录制时调用)
|
|
85
|
+
*/
|
|
86
|
+
destroy(): void;
|
|
87
|
+
/**
|
|
88
|
+
* 获取统计信息
|
|
89
|
+
*/
|
|
90
|
+
getStats(): {
|
|
91
|
+
mergedCount: number;
|
|
92
|
+
droppedByRepeat: number;
|
|
93
|
+
cancelledByOffset: number;
|
|
94
|
+
};
|
|
95
|
+
private isMutationEvent;
|
|
96
|
+
/**
|
|
97
|
+
* 重复模式检测(O(1) 快速判断)
|
|
98
|
+
* 连续 Mutation 的 adds 数量相同 + 首个 parentId 相同 → 认为是重复模式
|
|
99
|
+
*/
|
|
100
|
+
private isRepeatPattern;
|
|
101
|
+
/**
|
|
102
|
+
* 合并 incoming Mutation 到 buffer
|
|
103
|
+
*/
|
|
104
|
+
private mergeInto;
|
|
105
|
+
/**
|
|
106
|
+
* 深拷贝 Mutation 事件(只拷贝需要合并的字段)
|
|
107
|
+
*/
|
|
108
|
+
private cloneEvent;
|
|
109
|
+
private scheduleFlush;
|
|
110
|
+
private clearTimer;
|
|
111
|
+
}
|
|
112
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Privacy - 隐私保护模块
|
|
3
|
+
*
|
|
4
|
+
* 实现敏感数据检测和脱敏功能:
|
|
5
|
+
* - 自动检测手机号、身份证、邮箱等
|
|
6
|
+
* - 提供默认隐私配置
|
|
7
|
+
* - 支持自定义脱敏函数
|
|
8
|
+
*/
|
|
9
|
+
import { PrivacyConfig } from './types';
|
|
10
|
+
/** 完整隐私配置选项 */
|
|
11
|
+
export interface PrivacyOptions extends PrivacyConfig {
|
|
12
|
+
/** 遮罩 CSS 选择器列表 */
|
|
13
|
+
mask?: string[];
|
|
14
|
+
/** 阻止录制 CSS 选择器列表 */
|
|
15
|
+
block?: string[];
|
|
16
|
+
/** 忽略 CSS 选择器列表 */
|
|
17
|
+
ignore?: string[];
|
|
18
|
+
/** 自定义文本脱敏函数 */
|
|
19
|
+
maskTextFn?: (text: string, element?: HTMLElement | null) => string;
|
|
20
|
+
/** 是否屏蔽所有媒体 */
|
|
21
|
+
blockAllMedia?: boolean;
|
|
22
|
+
/** 是否启用自动敏感数据检测 */
|
|
23
|
+
autoDetectSensitiveData?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** 默认遮罩 CSS 选择器 */
|
|
26
|
+
export declare const DEFAULT_MASK_SELECTORS: string[];
|
|
27
|
+
/** 默认阻止 CSS 选择器 */
|
|
28
|
+
export declare const DEFAULT_BLOCK_SELECTORS: string[];
|
|
29
|
+
/** 默认忽略 CSS 选择器 */
|
|
30
|
+
export declare const DEFAULT_IGNORE_SELECTORS: string[];
|
|
31
|
+
/** 媒体元素 CSS 选择器(blockAllMedia 使用) */
|
|
32
|
+
export declare const MEDIA_SELECTORS = "img,image,svg,video,object,picture,embed,map,audio,link[rel=\"icon\"],link[rel=\"apple-touch-icon\"]";
|
|
33
|
+
/** 默认隐私配置 */
|
|
34
|
+
export declare const DEFAULT_PRIVACY_CONFIG: PrivacyOptions;
|
|
35
|
+
/**
|
|
36
|
+
* SensitiveDataDetector - 敏感数据检测器
|
|
37
|
+
*
|
|
38
|
+
* 自动检测和脱敏常见的敏感信息
|
|
39
|
+
*/
|
|
40
|
+
export declare class SensitiveDataDetector {
|
|
41
|
+
private static phoneRegex;
|
|
42
|
+
private static idCardRegex;
|
|
43
|
+
private static emailRegex;
|
|
44
|
+
private static bankCardRegex;
|
|
45
|
+
private static ipv4Regex;
|
|
46
|
+
/**
|
|
47
|
+
* 检测并脱敏手机号
|
|
48
|
+
*/
|
|
49
|
+
static maskPhone(text: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* 检测并脱敏身份证
|
|
52
|
+
*/
|
|
53
|
+
static maskIdCard(text: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* 检测并脱敏邮箱
|
|
56
|
+
*/
|
|
57
|
+
static maskEmail(text: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* 检测并脱敏银行卡号
|
|
60
|
+
*/
|
|
61
|
+
static maskBankCard(text: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* 检测并脱敏 IP 地址
|
|
64
|
+
*/
|
|
65
|
+
static maskIP(text: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* 自动检测并脱敏所有敏感信息
|
|
68
|
+
*/
|
|
69
|
+
static autoMask(text: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* 检查文本是否包含敏感信息
|
|
72
|
+
*/
|
|
73
|
+
static hasSensitiveData(text: string): boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 合并隐私配置
|
|
77
|
+
*/
|
|
78
|
+
export declare function mergePrivacyConfig(userConfig?: Partial<PrivacyOptions>, defaultConfig?: PrivacyOptions): PrivacyOptions;
|
|
79
|
+
/**
|
|
80
|
+
* 创建增强的脱敏函数
|
|
81
|
+
* 自动检测敏感数据并应用用户自定义脱敏
|
|
82
|
+
*/
|
|
83
|
+
export declare function createEnhancedMaskTextFn(userFn?: (text: string, element?: HTMLElement | null) => string, autoDetect?: boolean): (text: string, element?: HTMLElement | null) => string;
|
|
84
|
+
/**
|
|
85
|
+
* 将隐私选项转换为 rrweb 配置
|
|
86
|
+
*/
|
|
87
|
+
export declare function toRrwebPrivacyConfig(privacy: PrivacyOptions): Record<string, any>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { RecorderOptions, RecordingConfig, RecordingState, SessionReplayConfig } from './types';
|
|
2
|
+
export declare class RecorderManager {
|
|
3
|
+
private stopRecordingFn;
|
|
4
|
+
private state;
|
|
5
|
+
private options;
|
|
6
|
+
private lastCheckoutTime;
|
|
7
|
+
private checkpointTimer;
|
|
8
|
+
private mutationLimitReached;
|
|
9
|
+
private mutationMerger;
|
|
10
|
+
private mutationBreadcrumbLimit;
|
|
11
|
+
private mutationLimit;
|
|
12
|
+
private restoreMutationObserver;
|
|
13
|
+
private throttleCount;
|
|
14
|
+
private throttleWindowStart;
|
|
15
|
+
private throttleNotified;
|
|
16
|
+
private mutationAddsInWindow;
|
|
17
|
+
constructor(options: RecorderOptions, replayConfig?: Partial<SessionReplayConfig>);
|
|
18
|
+
/**
|
|
19
|
+
* 开始录制
|
|
20
|
+
*/
|
|
21
|
+
startRecording(config?: RecordingConfig): void;
|
|
22
|
+
/**
|
|
23
|
+
* 停止录制
|
|
24
|
+
*/
|
|
25
|
+
stopRecording(): void;
|
|
26
|
+
/**
|
|
27
|
+
* 暂停录制
|
|
28
|
+
*/
|
|
29
|
+
pauseRecording(): void;
|
|
30
|
+
/**
|
|
31
|
+
* 恢复录制
|
|
32
|
+
*/
|
|
33
|
+
resumeRecording(config?: RecordingConfig): void;
|
|
34
|
+
/**
|
|
35
|
+
* Hook MutationObserver:录制全程生效
|
|
36
|
+
*
|
|
37
|
+
* 原理:替换全局 MutationObserver 构造函数,包裹原始 callback。
|
|
38
|
+
* rrweb 在 record() 以及后续 checkout 时都会 new MutationObserver(cb),
|
|
39
|
+
* 因此必须在整个录制期间保持 hook,直到 stopRecording 时恢复。
|
|
40
|
+
*
|
|
41
|
+
* 副作用:录制期间页面其他代码 new MutationObserver() 也会经过 hook,
|
|
42
|
+
* 但 onMutationHandler 只做数量级判断,对正常 mutation 直接放行,不影响功能。
|
|
43
|
+
*/
|
|
44
|
+
private hookMutationObserver;
|
|
45
|
+
/**
|
|
46
|
+
* 恢复原始 MutationObserver
|
|
47
|
+
*/
|
|
48
|
+
private unhookMutationObserver;
|
|
49
|
+
/**
|
|
50
|
+
* MutationObserver 回调拦截(序列化前熔断)
|
|
51
|
+
* 逻辑与 Sentry _onMutationHandler 对齐。
|
|
52
|
+
*/
|
|
53
|
+
private onMutationHandler;
|
|
54
|
+
/**
|
|
55
|
+
* emit 层 Mutation 熔断检查
|
|
56
|
+
* 基于已序列化事件的 adds 数量判断,作为 MutationObserver hook 的补充。
|
|
57
|
+
*/
|
|
58
|
+
private checkMutationLimit;
|
|
59
|
+
/**
|
|
60
|
+
* 发送 mutation 警告/熔断的自定义事件
|
|
61
|
+
*/
|
|
62
|
+
private emitMutationBreadcrumb;
|
|
63
|
+
/**
|
|
64
|
+
* 处理录制事件
|
|
65
|
+
*
|
|
66
|
+
* 当 isCheckout=true 时,说明 rrweb 生成了新的 FullSnapshot。
|
|
67
|
+
* 此时先触发 onCheckout 回调(让插件层 flush 旧数据),
|
|
68
|
+
* 然后再将 FullSnapshot 事件传递给缓冲区,
|
|
69
|
+
* 确保 FullSnapshot 始终出现在新 segment 的开头。
|
|
70
|
+
*/
|
|
71
|
+
private handleEvent;
|
|
72
|
+
/**
|
|
73
|
+
* 事件节流检查
|
|
74
|
+
*/
|
|
75
|
+
private checkEventThrottle;
|
|
76
|
+
private startCheckpointTimer;
|
|
77
|
+
private stopCheckpointTimer;
|
|
78
|
+
getState(): RecordingState;
|
|
79
|
+
isRecording(): boolean;
|
|
80
|
+
getLastCheckoutTime(): number;
|
|
81
|
+
takeFullSnapshot(): void;
|
|
82
|
+
isMutationLimitReached(): boolean;
|
|
83
|
+
}
|