From a9f5f64f9d6a8fd03754abec7d41a14e13098525 Mon Sep 17 00:00:00 2001 From: Soumyadas15 Date: Tue, 27 May 2025 10:47:15 +0530 Subject: [PATCH] chore(dev): image loading state in browser tool --- .../thread/tool-views/BrowserToolView.tsx | 75 ++++++++++++++++++- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/thread/tool-views/BrowserToolView.tsx b/frontend/src/components/thread/tool-views/BrowserToolView.tsx index 8bb1a6b5..25fe4a4b 100644 --- a/frontend/src/components/thread/tool-views/BrowserToolView.tsx +++ b/frontend/src/components/thread/tool-views/BrowserToolView.tsx @@ -124,6 +124,15 @@ export function BrowserToolView({ const isRunning = isStreaming || agentStatus === 'running'; const isLastToolCall = currentIndex === totalCalls - 1; + const [isIframeLoading, setIsIframeLoading] = React.useState(true); + + // Reset loading state when VNC URL changes + React.useEffect(() => { + if (vncPreviewUrl) { + setIsIframeLoading(true); + } + }, [vncPreviewUrl]); + const vncIframe = useMemo(() => { if (!vncPreviewUrl) return null; @@ -133,6 +142,7 @@ export function BrowserToolView({ title="Browser preview" className="w-full h-full border-0 min-h-[600px]" style={{ width: '100%', height: '100%', minHeight: '600px' }} + onLoad={() => setIsIframeLoading(false)} /> ); }, [vncPreviewUrl]); @@ -157,24 +167,53 @@ export function BrowserToolView({ } }, [isRunning]); + const [isScreenshotLoading, setIsScreenshotLoading] = React.useState(true); + + // Reset screenshot loading state when screenshot data changes + React.useEffect(() => { + if (screenshotUrl || screenshotBase64) { + setIsScreenshotLoading(true); + } + }, [screenshotUrl, screenshotBase64]); + const renderScreenshot = () => { if (screenshotUrl) { return ( -
+
+ {isScreenshotLoading && ( +
+
+ +

Loading screenshot...

+
+
+ )} Browser Screenshot setIsScreenshotLoading(false)} + onError={() => setIsScreenshotLoading(false)} />
); } else if (screenshotBase64) { return ( -
+
+ {isScreenshotLoading && ( +
+
+ +

Loading screenshot...

+
+
+ )} Browser Screenshot setIsScreenshotLoading(false)} + onError={() => setIsScreenshotLoading(false)} />
); @@ -230,6 +269,14 @@ export function BrowserToolView({ isRunning && vncIframe ? (
+ {isIframeLoading && ( +
+
+ +

Loading browser preview...

+
+
+ )} {vncIframe}
@@ -243,7 +290,15 @@ export function BrowserToolView({ renderScreenshot() ) : vncIframe ? ( // Use the memoized iframe -
+
+ {isIframeLoading && ( +
+
+ +

Loading browser preview...

+
+
+ )} {vncIframe}
) : ( @@ -273,18 +328,30 @@ export function BrowserToolView({ ) ) : // For non-last tool calls, only show screenshot if available, otherwise show "No Browser State" (screenshotUrl || screenshotBase64) ? ( -
+
+ {isScreenshotLoading && ( +
+
+ +

Loading screenshot...

+
+
+ )} {screenshotUrl ? ( Browser Screenshot setIsScreenshotLoading(false)} + onError={() => setIsScreenshotLoading(false)} /> ) : ( Browser Screenshot setIsScreenshotLoading(false)} + onError={() => setIsScreenshotLoading(false)} /> )}