feat: 重构录制逻辑,添加错误处理,更新消息常量,使用 terser 进行构建压缩

This commit is contained in:
雨霖铃
2026-02-03 23:42:28 +08:00
parent 37f8ef9c2b
commit e6f41032c8
8 changed files with 123 additions and 49 deletions
+3 -1
View File
@@ -12,7 +12,9 @@ export const messages = {
ready: 'popup:ready',
},
content: {
from: {},
from: {
saveTrackeEvents: 'content:save-tracke-events',
},
to: {
startRecording: 'content:start-recording',
stopRecording: 'content:stop-recording',
+36
View File
@@ -0,0 +1,36 @@
import * as rrweb from 'rrweb';
import { listenerHandler } from '@rrweb/types';
export const createRecorder = () => {
let stopFn: listenerHandler | null = null;
const startRecord = async (msg: string) => {
try {
// const handler = null;
const handler = rrweb.record({
emit(event) {
chrome.runtime.sendMessage({
type: msg,
payload: event,
});
},
});
stopFn = handler || null;
console.log('[content] rrweb started');
} catch (error) {
console.error('Failed to start recording:', error);
}
};
const stopRecord = () => {
if (stopFn) {
stopFn();
stopFn = null;
console.log('[content] rrweb stopped');
}
};
return { startRecord, stopRecord };
};