feat: 更新背景脚本和内容脚本,添加录制控制消息处理,优化录制状态检查逻辑,新增消息常量

This commit is contained in:
雨霖铃
2026-01-30 23:08:49 +08:00
parent 0ff33cbeb3
commit 88a612f9cf
7 changed files with 201 additions and 105 deletions
+9 -17
View File
@@ -1,28 +1,21 @@
import { useRef, useState } from 'react';
import { useRef, useState, useCallback } from 'react';
import { record } from 'rrweb';
export const useRecorder = () => {
// 存储停止录制函数
const stopFnRef = useRef();
const stopFnRef = useRef<(() => void) | null>(null);
const [isRecording, setIsRecording] = useState(false);
const startRecord = async () => {
const startRecord = useCallback(async () => {
if (isRecording) return;
await chrome.runtime.sendMessage({ type: 'CREATE_OFFSCREEN' });
setIsRecording(true);
try {
// await chrome.runtime.sendMessage({ type: 'CREATE_OFFSCREEN' });
setIsRecording(true);
// 启动录制
stopFnRef.current = record({
emit(event) {
// 存储数据
// eventRef.current.push(event);
chrome.runtime.sendMessage({ type: 'SAVE_EVENT', event });
},
});
console.log('[content] rrweb started');
};
console.log('[content] rrweb started');
} catch (error) {}
}, [isRecording]);
const stopRecord = () => {
if (!isRecording) return;
@@ -42,6 +35,5 @@ export const useRecorder = () => {
startRecord,
stopRecord,
isRecording,
getEvents: () => eventRef.current,
};
};