Files
testing-tool/utils/useRecorder.tsx
T
雨霖铃 c848003214 feat(recorder): 实现IndexedDB分块存储录制事件
- 将录制状态中的events数组替换为sessionId,避免内存溢出问题
- 集成IndexedDB工具模块实现事件分块存储功能
- 修改开始录制逻辑以生成会话ID并初始化数据库会话
- 更新停止录制逻辑从数据库流式读取事件并删除会话数据
- 修复content:save-track-events消息类型的拼写错误
- 在RoutePersistence组件中添加路由恢复和保存的成功提示
- 重构popup应用CSS样式文件,移除冗余导航样式代码
2026-02-21 15:27:30 +08:00

39 lines
932 B
TypeScript

import * as rrweb from 'rrweb';
import { listenerHandler } from '@rrweb/types';
import { getRecordConsolePlugin } from '@rrweb/rrweb-plugin-console-record';
import { sendMessage } from '@/utils/messages';
export const createRecorder = () => {
let stopFn: listenerHandler | null = null;
const startRecord = async () => {
try {
const handler = rrweb.record({
emit(event) {
sendMessage('content:save-track-events', event);
},
plugins: [getRecordConsolePlugin()],
});
stopFn = handler || null;
console.log('[content] rrweb started');
return true;
} catch (error) {
console.error('Failed to start recording:', error);
return false;
}
};
const stopRecord = () => {
if (stopFn) {
stopFn();
stopFn = null;
console.log('[content] rrweb stopped');
}
return false;
};
return { startRecord, stopRecord };
};