feat: 重构录制逻辑,添加错误处理,更新消息常量,使用 terser 进行构建压缩
This commit is contained in:
@@ -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 };
|
||||
};
|
||||
Reference in New Issue
Block a user