50034331bc
1、统一消息系统:将 background、content 和 popup 的通信方式从原生的 chrome.runtime 迁移至 @webext-core/messaging,修复了消息回调返回 undefined 的问题。 2、优化组件结构:将通用组件从 entrypoints/popup/components 迁移至根目录 components,并使用 MUI 重构了 Navbar。 3、同步更新:调整了录制工具 (useRecorder) 和各页面组件(RecordeReplayPage, TestPage等),以适配新的消息协议和组件路径。
55 lines
1.4 KiB
TypeScript
55 lines
1.4 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',
|
|
},
|
|
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 };
|
|
'popup:stop': () => { ok: boolean };
|
|
'popup:started': () => void;
|
|
'popup:stopped': () => void;
|
|
'popup:check-status': () => { active: boolean; startTime?: number };
|
|
'popup:ready': () => void;
|
|
|
|
// --- Content 相关 ---
|
|
'content:save-tracke-events': (event) => 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>();
|