Files
testing-tool/utils/useRecorder.tsx
T
雨霖铃 50034331bc refactor: 统一扩展消息机制并优化组件结构
1、统一消息系统:将 background、content 和 popup 的通信方式从原生的 chrome.runtime 迁移至 @webext-core/messaging,修复了消息回调返回 undefined 的问题。
2、优化组件结构:将通用组件从 entrypoints/popup/components 迁移至根目录 components,并使用 MUI 重构了 Navbar。
3、同步更新:调整了录制工具 (useRecorder) 和各页面组件(RecordeReplayPage, TestPage等),以适配新的消息协议和组件路径。
2026-02-13 20:38:15 +08:00

39 lines
933 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-tracke-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 };
};