Skip to content

refactor(recorder): replace localStorage with IndexedDB for recording data storage and optimize navigation record #831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/chrome-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@rsbuild/plugin-less": "^1.2.4",
"@rsbuild/plugin-node-polyfill": "1.3.0",
"@rsbuild/plugin-react": "^1.3.1",
"@rsbuild/plugin-type-check": "1.2.3",
"@types/chrome": "0.0.279",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.1",
Expand Down
11 changes: 10 additions & 1 deletion apps/chrome-extension/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from '@rsbuild/core';
import { pluginLess } from '@rsbuild/plugin-less';
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
import { version } from '../../packages/visualizer/package.json';

export default defineConfig({
Expand Down Expand Up @@ -78,5 +79,13 @@ export default defineConfig({
'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
},
},
plugins: [pluginReact(), pluginNodePolyfill(), pluginLess()],
plugins: [
pluginReact(),
pluginNodePolyfill(),
pluginLess(),
pluginTypeCheck({
// Enable type checking for both development and production builds
enable: true,
}),
],
});
1 change: 0 additions & 1 deletion apps/chrome-extension/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import './App.less';
import { PlaygroundPopup } from './extension/popup';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import {
} from '@ant-design/icons';
import type { ChromeRecordedEvent } from '@midscene/recorder';
import { RecordTimeline } from '@midscene/recorder';
import { Alert, Button, Card, Divider, Empty, Space, Typography } from 'antd';
import {
Alert,
Button,
Card,
Divider,
Empty,
Space,
Tooltip,
Typography,
} from 'antd';
import type React from 'react';
import {
type RecordingSession,
Expand All @@ -23,7 +32,7 @@ interface RecordDetailProps {
isRecording: boolean;
currentTab: chrome.tabs.Tab | null;
onBack: () => void;
onStartRecording: () => void;
onStartRecording: (id?: string) => void;
onStopRecording: () => void;
onClearEvents: () => void;
isExtensionMode: boolean;
Expand Down Expand Up @@ -78,15 +87,8 @@ export const RecordDetail: React.FC<RecordDetailProps> = ({
/>
)}

{/* Header with back button and session info */}
<div
className="detail-header"
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
{/* Header with back button */}
<div className="detail-header">
<Button
type="text"
icon={<ArrowLeftOutlined />}
Expand All @@ -95,10 +97,15 @@ export const RecordDetail: React.FC<RecordDetailProps> = ({
>
Back to Sessions
</Button>
<div className="session-title" style={{ textAlign: 'center', flex: 1 }}>
<Title level={4}>{session.name}</Title>
</div>
<div style={{ width: '120px' }} /> {/* Spacer to balance the layout */}
</div>

{/* Session title */}
<div className="session-title-section">
<Tooltip title={session.name} placement="topLeft">
<Title level={4} className="session-title-text">
{session.name}
</Title>
</Tooltip>
</div>

{/* Recording Controls */}
Expand Down Expand Up @@ -150,7 +157,7 @@ export const RecordDetail: React.FC<RecordDetailProps> = ({
<Button
type="primary"
icon={<PlayCircleOutlined />}
onClick={onStartRecording}
onClick={()=> onStartRecording(sessionId)}
disabled={!currentTab || !isExtensionMode}
>
Start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { recordLogger } from '../logger';
export const useLifecycleCleanup = (
isRecording: boolean,
stopRecording: () => Promise<void>,
setIsRecording: (recording: boolean) => void,
setIsRecording: (recording: boolean) => Promise<void>,
currentSessionId: string | null,
getCurrentSession: () => RecordingSession | null,
updateSession: (
sessionId: string,
updates: Partial<RecordingSession>,
) => void,
events: ChromeRecordedEvent[], // Add events parameter to save current events
emergencySaveEvents: (events?: ChromeRecordedEvent[]) => Promise<void>, // Add emergency save function
) => {
// Monitor visibility changes for the extension popup
useEffect(() => {
Expand All @@ -36,10 +37,14 @@ export const useLifecycleCleanup = (
const handleBeforeUnload = () => {
if (isRecording) {
recordLogger.info(
'Extension popup closing, stopping recording synchronously',
'Extension popup closing, stopping recording synchronously and saving events',
);
// For unload events, we need to stop synchronously
setIsRecording(false);
// For unload events, we need to stop synchronously and save immediately
setIsRecording(false).catch(console.error);

// Emergency save current events
emergencySaveEvents(events).catch(console.error);

if (currentSessionId) {
const session = getCurrentSession();
if (session) {
Expand Down Expand Up @@ -74,8 +79,12 @@ export const useLifecycleCleanup = (
return () => {
// Clean up any ongoing recording when component unmounts
if (isRecording) {
recordLogger.info('Component unmounting, cleaning up recording');
setIsRecording(false);
recordLogger.info('Component unmounting, cleaning up recording and saving events');
setIsRecording(false).catch(console.error);

// Emergency save current events
emergencySaveEvents(events).catch(console.error);

if (currentSessionId) {
const session = getCurrentSession();
if (session) {
Expand Down
Loading
Loading