Skip to content

Commit 1f99295

Browse files
committed
feat: rm canvas logic, add in-browser loader
1 parent b032de4 commit 1f99295

File tree

3 files changed

+46
-147
lines changed

3 files changed

+46
-147
lines changed

src/components/browser/BrowserContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
export const BrowserContent = () => {
1414
const { socket } = useSocketStore();
1515

16-
const [tabs, setTabs] = useState<string[]>(["current"]);
16+
const [tabs, setTabs] = useState<string[]>(["Loading..."]);
1717
const [tabIndex, setTabIndex] = React.useState(0);
1818
const [showOutputData, setShowOutputData] = useState(false);
1919
const { browserWidth } = useBrowserDimensionsStore();
@@ -125,7 +125,7 @@ export const BrowserContent = () => {
125125
useEffect(() => {
126126
getCurrentTabs()
127127
.then((response) => {
128-
if (response) {
128+
if (response && response.length > 0) {
129129
setTabs(response);
130130
}
131131
})

src/components/browser/BrowserWindow.tsx

Lines changed: 23 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
22
import { useSocketStore } from '../../context/socket';
33
import { Button } from '@mui/material';
4-
import Canvas from "../recorder/Canvas";
5-
import { Highlighter } from "../recorder/Highlighter";
64
import { GenericModal } from '../ui/GenericModal';
75
import { useActionContext } from '../../context/browserActions';
86
import { useBrowserSteps, TextStep, ListStep } from '../../context/browserSteps';
@@ -38,12 +36,6 @@ interface AttributeOption {
3836
value: string;
3937
}
4038

41-
interface ScreencastData {
42-
image: string;
43-
userId: string;
44-
viewport?: ViewportInfo | null;
45-
}
46-
4739
interface ViewportInfo {
4840
width: number;
4941
height: number;
@@ -146,8 +138,6 @@ const getAttributeOptions = (tagName: string, elementInfo: ElementInfo | null):
146138
export const BrowserWindow = () => {
147139
const { t } = useTranslation();
148140
const { browserWidth, browserHeight } = useBrowserDimensionsStore();
149-
const [canvasRef, setCanvasReference] = useState<React.RefObject<HTMLCanvasElement> | undefined>(undefined);
150-
const [screenShot, setScreenShot] = useState<string>("");
151141
const [highlighterData, setHighlighterData] = useState<{
152142
rect: DOMRect;
153143
selector: string;
@@ -1303,17 +1293,6 @@ export const BrowserWindow = () => {
13031293
}, []);
13041294

13051295
const onMouseMove = (e: MouseEvent) => {
1306-
if (canvasRef && canvasRef.current && highlighterData) {
1307-
const canvasRect = canvasRef.current.getBoundingClientRect();
1308-
if (
1309-
e.pageX < canvasRect.left
1310-
|| e.pageX > canvasRect.right
1311-
|| e.pageY < canvasRect.top
1312-
|| e.pageY > canvasRect.bottom
1313-
) {
1314-
setHighlighterData(null);
1315-
}
1316-
}
13171296
};
13181297

13191298
const resetListState = useCallback(() => {
@@ -1331,46 +1310,22 @@ export const BrowserWindow = () => {
13311310
}
13321311
}, [getList, resetListState]);
13331312

1334-
const screencastHandler = useCallback((data: string | ScreencastData) => {
1335-
if (typeof data === 'string') {
1336-
setScreenShot(data);
1337-
} else if (data && typeof data === 'object' && 'image' in data) {
1338-
if (!data.userId || data.userId === user?.id) {
1339-
setScreenShot(data.image);
1340-
1341-
if (data.viewport) {
1342-
setViewportInfo(data.viewport);
1343-
}
1344-
}
1345-
}
1346-
}, [user?.id]);
1347-
13481313
useEffect(() => {
13491314
if (socket) {
1350-
socket.on("screencast", screencastHandler);
13511315
socket.on("domcast", rrwebSnapshotHandler);
13521316
socket.on("dom-mode-enabled", domModeHandler);
13531317
socket.on("dom-mode-error", domModeErrorHandler);
13541318
}
13551319

1356-
if (canvasRef?.current && !isDOMMode && screenShot) {
1357-
drawImage(screenShot, canvasRef.current);
1358-
}
1359-
13601320
return () => {
13611321
if (socket) {
1362-
socket.off("screencast", screencastHandler);
13631322
socket.off("domcast", rrwebSnapshotHandler);
13641323
socket.off("dom-mode-enabled", domModeHandler);
13651324
socket.off("dom-mode-error", domModeErrorHandler);
13661325
}
13671326
};
13681327
}, [
13691328
socket,
1370-
screenShot,
1371-
canvasRef,
1372-
isDOMMode,
1373-
screencastHandler,
13741329
rrwebSnapshotHandler,
13751330
domModeHandler,
13761331
domModeErrorHandler,
@@ -1847,24 +1802,7 @@ export const BrowserWindow = () => {
18471802

18481803
const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
18491804
if (highlighterData) {
1850-
let shouldProcessClick = false;
1851-
1852-
if (!isDOMMode && canvasRef?.current) {
1853-
const canvasRect = canvasRef.current.getBoundingClientRect();
1854-
const clickX = e.clientX - canvasRect.left;
1855-
const clickY = e.clientY - canvasRect.top;
1856-
const highlightRect = highlighterData.rect;
1857-
const mappedRect =
1858-
coordinateMapper.mapBrowserRectToCanvas(highlightRect);
1859-
1860-
shouldProcessClick =
1861-
clickX >= mappedRect.left &&
1862-
clickX <= mappedRect.right &&
1863-
clickY >= mappedRect.top &&
1864-
clickY <= mappedRect.bottom;
1865-
} else {
1866-
shouldProcessClick = true;
1867-
}
1805+
const shouldProcessClick = true;
18681806

18691807
if (shouldProcessClick) {
18701808
const options = getAttributeOptions(
@@ -2209,17 +2147,7 @@ export const BrowserWindow = () => {
22092147
!showAttributeModal &&
22102148
highlighterData?.rect != null && (
22112149
<>
2212-
{!isDOMMode && canvasRef?.current && (
2213-
<Highlighter
2214-
unmodifiedRect={highlighterData?.rect}
2215-
displayedSelector={highlighterData?.selector}
2216-
width={dimensions.width}
2217-
height={dimensions.height}
2218-
canvasRect={canvasRef.current.getBoundingClientRect()}
2219-
/>
2220-
)}
2221-
2222-
{isDOMMode && highlighterData && (
2150+
{highlighterData && (
22232151
<div
22242152
id="dom-highlight-overlay"
22252153
style={{
@@ -2355,31 +2283,27 @@ export const BrowserWindow = () => {
23552283
borderRadius: "0px 0px 5px 5px",
23562284
}}
23572285
>
2358-
{isDOMMode ? (
2286+
{currentSnapshot ? (
23592287
<>
2360-
{currentSnapshot ? (
2361-
<DOMBrowserRenderer
2362-
width={dimensions.width}
2363-
height={dimensions.height}
2364-
snapshot={currentSnapshot}
2365-
getList={getList}
2366-
getText={getText}
2367-
listSelector={listSelector}
2368-
cachedChildSelectors={cachedChildSelectors}
2369-
paginationMode={paginationMode}
2370-
paginationType={paginationType}
2371-
limitMode={limitMode}
2372-
isCachingChildSelectors={isCachingChildSelectors}
2373-
onHighlight={domHighlighterHandler}
2374-
onElementSelect={handleDOMElementSelection}
2375-
onShowDatePicker={handleShowDatePicker}
2376-
onShowDropdown={handleShowDropdown}
2377-
onShowTimePicker={handleShowTimePicker}
2378-
onShowDateTimePicker={handleShowDateTimePicker}
2379-
/>
2380-
) : (
2381-
<DOMLoadingIndicator />
2382-
)}
2288+
<DOMBrowserRenderer
2289+
width={dimensions.width}
2290+
height={dimensions.height}
2291+
snapshot={currentSnapshot}
2292+
getList={getList}
2293+
getText={getText}
2294+
listSelector={listSelector}
2295+
cachedChildSelectors={cachedChildSelectors}
2296+
paginationMode={paginationMode}
2297+
paginationType={paginationType}
2298+
limitMode={limitMode}
2299+
isCachingChildSelectors={isCachingChildSelectors}
2300+
onHighlight={domHighlighterHandler}
2301+
onElementSelect={handleDOMElementSelection}
2302+
onShowDatePicker={handleShowDatePicker}
2303+
onShowDropdown={handleShowDropdown}
2304+
onShowTimePicker={handleShowTimePicker}
2305+
onShowDateTimePicker={handleShowDateTimePicker}
2306+
/>
23832307

23842308
{/* --- Loading overlay --- */}
23852309
{isCachingChildSelectors && (
@@ -2492,11 +2416,7 @@ export const BrowserWindow = () => {
24922416
)}
24932417
</>
24942418
) : (
2495-
<Canvas
2496-
onCreateRef={setCanvasReference}
2497-
width={dimensions.width}
2498-
height={dimensions.height}
2499-
/>
2419+
<DOMLoadingIndicator />
25002420
)}
25012421
</div>
25022422
</div>
@@ -2591,26 +2511,6 @@ const DOMLoadingIndicator: React.FC = () => {
25912511
);
25922512
};
25932513

2594-
2595-
const drawImage = (image: string, canvas: HTMLCanvasElement): void => {
2596-
const ctx = canvas.getContext('2d');
2597-
if (!ctx) return;
2598-
2599-
const img = new Image();
2600-
img.onload = () => {
2601-
requestAnimationFrame(() => {
2602-
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
2603-
});
2604-
if (image.startsWith('blob:')) {
2605-
URL.revokeObjectURL(image);
2606-
}
2607-
};
2608-
img.onerror = () => {
2609-
console.warn('Failed to load image');
2610-
};
2611-
img.src = image;
2612-
};
2613-
26142514
const modalStyle = {
26152515
top: '50%',
26162516
left: '50%',

src/pages/RecordingPage.tsx

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const RecordingPage = ({ recordingName }: RecordingPageProps) => {
4343

4444
const { setId, socket } = useSocketStore();
4545
const { setWidth } = useBrowserDimensionsStore();
46-
const { browserId, setBrowserId, recordingId, recordingUrl, setRecordingUrl, setRecordingName, setRetrainRobotId } = useGlobalInfoStore();
46+
const { browserId, setBrowserId, recordingId, recordingUrl, setRecordingUrl, setRecordingName, setRetrainRobotId, setIsDOMMode } = useGlobalInfoStore();
4747

4848
const handleShowOutputData = useCallback(() => {
4949
setShowOutputData(true);
@@ -77,6 +77,8 @@ export const RecordingPage = ({ recordingName }: RecordingPageProps) => {
7777
useEffect(() => {
7878
let isCancelled = false;
7979
const handleRecording = async () => {
80+
setIsDOMMode(true);
81+
8082
const storedUrl = window.sessionStorage.getItem('recordingUrl');
8183
if (storedUrl && !recordingUrl) {
8284
setRecordingUrl(storedUrl);
@@ -137,9 +139,12 @@ export const RecordingPage = ({ recordingName }: RecordingPageProps) => {
137139
if (browserId === 'new-recording') {
138140
socket?.emit('new-recording');
139141
}
142+
if (recordingUrl && socket) {
143+
socket.emit('input:url', recordingUrl);
144+
}
140145
setIsLoaded(true);
141146
}
142-
}, [socket, browserId, recordingName, recordingId, isLoaded]);
147+
}, [socket, browserId, recordingName, recordingId, recordingUrl, isLoaded]);
143148

144149
useEffect(() => {
145150
socket?.on('loaded', handleLoaded);
@@ -153,26 +158,20 @@ export const RecordingPage = ({ recordingName }: RecordingPageProps) => {
153158
<ActionProvider>
154159
<BrowserStepsProvider>
155160
<div id="browser-recorder">
156-
{isLoaded ? (
157-
<>
158-
<Grid container direction="row" style={{ flexGrow: 1, height: '100%' }}>
159-
<Grid item xs={12} md={9} lg={9} style={{ height: '100%', overflow: 'hidden', position: 'relative' }}>
160-
<div style={{ height: '100%', overflow: 'auto' }}>
161-
<BrowserContent />
162-
<InterpretationLog isOpen={showOutputData} setIsOpen={setShowOutputData} />
163-
</div>
164-
</Grid>
165-
<Grid item xs={12} md={3} lg={3} style={{ height: '100%', overflow: 'hidden' }}>
166-
<div className="right-side-panel" style={{ height: '100%' }}>
167-
<RightSidePanel onFinishCapture={handleShowOutputData} />
168-
<BrowserRecordingSave />
169-
</div>
170-
</Grid>
171-
</Grid>
172-
</>
173-
) : (
174-
<Loader text={t('recording_page.loader.browser_startup', { url: recordingUrl })} />
175-
)}
161+
<Grid container direction="row" style={{ flexGrow: 1, height: '100%' }}>
162+
<Grid item xs={12} md={9} lg={9} style={{ height: '100%', overflow: 'hidden', position: 'relative' }}>
163+
<div style={{ height: '100%', overflow: 'auto' }}>
164+
<BrowserContent />
165+
<InterpretationLog isOpen={showOutputData} setIsOpen={setShowOutputData} />
166+
</div>
167+
</Grid>
168+
<Grid item xs={12} md={3} lg={3} style={{ height: '100%', overflow: 'hidden' }}>
169+
<div className="right-side-panel" style={{ height: '100%' }}>
170+
<RightSidePanel onFinishCapture={handleShowOutputData} />
171+
<BrowserRecordingSave />
172+
</div>
173+
</Grid>
174+
</Grid>
176175
</div>
177176
</BrowserStepsProvider>
178177
</ActionProvider>

0 commit comments

Comments
 (0)