80e510225c
- 实现录制状态存储到本地storage,包括isRecording、recordingTabId、events和startTime - 添加loadRecorderState和saveRecorderState函数用于状态管理 - 监听Tab切换事件,当切换离开录制Tab时发出警告并通知popup - 监听Tab关闭事件,自动停止录制并清理状态 - 添加录制状态同步检查,确保content script状态一致 - 在开始录制前检查是否已在录制状态,避免重复录制 - 添加错误处理返回详细错误信息 - 优化回放HTML样式和脚本加载方式 - 添加Tab切换消息通信协议支持
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { defineExtensionMessaging } from '@webext-core/messaging';
|
|
|
|
export const messages = {
|
|
popup: {
|
|
from: {
|
|
start: 'popup:start',
|
|
stop: 'popup:stop',
|
|
},
|
|
to: {
|
|
stopped: 'popup:stopped',
|
|
started: 'popup:started',
|
|
tabChanged: 'popup:tab-changed',
|
|
},
|
|
checkStatus: 'popup:check-status',
|
|
ready: 'popup:ready',
|
|
},
|
|
content: {
|
|
from: {
|
|
saveTrackeEvents: 'content:save-tracke-events',
|
|
},
|
|
to: {
|
|
startRecording: 'content:start-recording',
|
|
stopRecording: 'content:stop-recording',
|
|
},
|
|
checkStatus: 'content:check-status',
|
|
},
|
|
offscreen: {
|
|
to: {
|
|
startRecording: 'offscreen:start-recording',
|
|
stopRecording: 'offscreen:stop-recording',
|
|
},
|
|
},
|
|
};
|
|
|
|
interface ProtocolMap {
|
|
// --- Popup 相关 ---
|
|
'popup:start': () => { ok: boolean; error?: string };
|
|
'popup:stop': () => { ok: boolean; error?: string };
|
|
'popup:started': () => void;
|
|
'popup:stopped': () => void;
|
|
'popup:tab-changed': (data: { currentTabId: number; recordingTabId: number | undefined }) => void;
|
|
'popup:check-status': () => { active: boolean; startTime?: number };
|
|
'popup:ready': () => void;
|
|
|
|
// --- Content 相关 ---
|
|
'content:save-tracke-events': (event: unknown) => boolean;
|
|
'content:start-recording': () => { ok: boolean; error?: string };
|
|
'content:stop-recording': () => { ok: boolean };
|
|
'content:check-status': () => boolean;
|
|
|
|
// --- Offscreen 相关 ---
|
|
'offscreen:start-recording': (streamId: string) => void;
|
|
'offscreen:stop-recording': () => void;
|
|
}
|
|
|
|
export const { sendMessage, onMessage } = defineExtensionMessaging<ProtocolMap>();
|