Open History to see the last commit
1"use client";
2
3import { scopedThreadKey } from "@t3tools/client-runtime/environment";
4import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
5import {
6 FILL_PREVIEW_VIEWPORT,
7 type PreviewViewportSetting,
8 type ScopedThreadRef,
9} from "@t3tools/contracts";
10import { normalizePreviewUrl } from "@t3tools/shared/preview";
11import { useCallback, useEffect, useRef, useState } from "react";
12
13import { useComposerDraftStore } from "~/composerDraftStore";
14import { previewAnnotationScreenshotFile } from "~/lib/previewAnnotation";
15import { ensureLocalApi } from "~/localApi";
16import {
17 rememberPreviewUrl,
18 updatePreviewServerSnapshot,
19 useThreadPreviewState,
20} from "~/previewStateStore";
21import { resolveDiscoveredServerUrl } from "~/browser/browserTargetResolver";
22import { useEnvironment, useEnvironmentHttpBaseUrl } from "~/state/environments";
23import { previewEnvironment } from "~/state/preview";
24import { useAtomCommand } from "~/state/use-atom-command";
25import { selectThreadPreviewMiniPlayer, usePreviewMiniPlayerStore } from "~/previewMiniPlayerStore";
26import { useRightPanelStore } from "~/rightPanelStore";
27
28import { previewBridge } from "./previewBridge";
29import { subscribePreviewAction } from "./previewActionBus";
30import { openPreviewSession } from "./openPreviewSession";
31import { PreviewChromeRow } from "./PreviewChromeRow";
32import { formatPreviewUrl } from "./previewUrlPresentation";
33import { PreviewEmptyState } from "./PreviewEmptyState";
34import { PreviewMoreMenu } from "./PreviewMoreMenu";
35import {
36 commitBrowserViewportChange,
37 subscribeBrowserViewportChange,
38} from "~/browser/browserViewportActions";
39import { resolveResponsiveBrowserViewportSize } from "~/browser/browserViewportLayout";
40import { previewRuntimeTabId } from "~/browser/previewRuntimeTabId";
41import { PreviewUnreachable } from "./PreviewUnreachable";
42import { revealInFileExplorerLabel } from "./fileExplorerLabel";
43import { shouldShowPreviewEmptyState } from "./previewEmptyStateLogic";
44import { BrowserSurfaceSlot } from "~/browser/BrowserSurfaceSlot";
45import { useBrowserSurfaceStore } from "~/browser/browserSurfaceStore";
46import { useLoadingProgress } from "./useLoadingProgress";
47import { usePreviewSession } from "./usePreviewSession";
48import { ZoomIndicator } from "./ZoomIndicator";
49import { AgentBrowserCursor } from "./AgentBrowserCursor";
50import {
51 findActiveBrowserRecordingRuntimeTabId,
52 startBrowserRecording,
53 stopBrowserRecording,
54 useActiveBrowserRecordingTabIds,
55} from "~/browser/browserRecording";
56import { stackedThreadToast, toastManager } from "~/components/ui/toast";
57
58interface Props {
59 threadRef: ScopedThreadRef;
60 tabId?: string | null;
61 configuredUrls?: ReadonlyArray<string> | undefined;
62 visible: boolean;
63}
64
65const localApi = typeof window === "undefined" ? null : ensureLocalApi();
66
67/**
68 * Single-tab preview surface: chrome row on top, one webview below, empty
69 * state when no session exists for the thread.
70 */
71export function PreviewView({ threadRef, tabId: requestedTabId, configuredUrls, visible }: Props) {
72 const [focusUrlNonce, setFocusUrlNonce] = useState<number | undefined>(undefined);
73 const [pickActive, setPickActive] = useState(false);
74 const activeRecordingTabIds = useActiveBrowserRecordingTabIds();
75 const pickActiveRef = useRef(false);
76 const isMountedRef = useRef(true);
77 const previewState = useThreadPreviewState(threadRef);
78 const miniPlayer = usePreviewMiniPlayerStore((state) =>
79 selectThreadPreviewMiniPlayer(state.byThreadKey, threadRef),
80 );
81 const addPreviewAnnotation = useComposerDraftStore((store) => store.addPreviewAnnotation);
82 const addImage = useComposerDraftStore((store) => store.addImage);
83 const environment = useEnvironment(threadRef.environmentId);
84 const environmentHttpBaseUrl = useEnvironmentHttpBaseUrl(threadRef.environmentId);
85 const open = useAtomCommand(previewEnvironment.open);
86 const resize = useAtomCommand(previewEnvironment.resize, "preview viewport resize");
87
88 usePreviewSession(threadRef);
89
90 useEffect(() => {
91 isMountedRef.current = true;
92 return () => {
93 isMountedRef.current = false;
94 };
95 }, []);
96
97 const tabId = requestedTabId ?? previewState.activeTabId;
98 const runtimeTabId = tabId
99 ? previewRuntimeTabId(threadRef, previewState.serverEpoch, tabId)
100 : null;
101 const recordingRuntimeTabId =
102 tabId && runtimeTabId
103 ? activeRecordingTabIds.has(runtimeTabId)
104 ? runtimeTabId
105 : findActiveBrowserRecordingRuntimeTabId(threadRef, tabId)
106 : null;
107 const snapshot = tabId ? (previewState.sessions[tabId] ?? null) : null;
108 const desktopOverlay = tabId ? (previewState.desktopByTabId[tabId] ?? null) : null;
109 const navStatus = snapshot?.navStatus ?? { _tag: "Idle" as const };
110 const url = navStatus._tag === "Idle" ? "" : navStatus.url;
111 const loading = desktopOverlay?.loading ?? navStatus._tag === "Loading";
112 const canGoBack = desktopOverlay?.canGoBack ?? snapshot?.canGoBack ?? false;
113 const canGoForward = desktopOverlay?.canGoForward ?? snapshot?.canGoForward ?? false;
114 const refreshDisabled = navStatus._tag === "Idle";
115 const isUnreachable = navStatus._tag === "LoadFailed";
116 const showEmptyState = shouldShowPreviewEmptyState(snapshot);
117 const controller = desktopOverlay?.controller ?? "none";
118 const loadProgress = useLoadingProgress(loading);
119 const displayUrl =
120 url && environment && environmentHttpBaseUrl
121 ? (formatPreviewUrl({
122 url,
123 environmentLabel: environment.label,
124 environmentHttpBaseUrl,
125 }) ?? undefined)
126 : undefined;
127 const viewport = snapshot?.viewport ?? FILL_PREVIEW_VIEWPORT;
128 const panelRect = useBrowserSurfaceStore((state) =>
129 runtimeTabId ? (state.byTabId[runtimeTabId]?.rect ?? null) : null,
130 );
131
132 const navigateToResolvedUrl = useCallback(
133 async (resolvedUrl: string) => {
134 if (runtimeTabId && previewBridge) {
135 // Drive the webview imperatively; `usePreviewBridge` mirrors the
136 // resolved URL back to the server so other clients stay in sync.
137 await previewBridge.navigate(runtimeTabId, resolvedUrl);
138 rememberPreviewUrl(threadRef, resolvedUrl);
139 } else {
140 await openPreviewSession({
141 openPreview: open,
142 threadRef,
143 url: resolvedUrl,
144 });
145 }
146 },
147 [open, runtimeTabId, threadRef],
148 );
149
150 const handleSubmitUrl = useCallback(
151 async (next: string) => {
152 try {
153 await navigateToResolvedUrl(normalizePreviewUrl(next));
154 } catch {
155 // Server-side `failed` event renders the unreachable view.
156 }
157 },
158 [navigateToResolvedUrl],
159 );
160
161 const handleOpenServerUrl = useCallback(
162 async (next: string) => {
163 try {
164 await navigateToResolvedUrl(resolveDiscoveredServerUrl(threadRef.environmentId, next));
165 } catch {
166 // Server-side `failed` event renders the unreachable view.
167 }
168 },
169 [navigateToResolvedUrl, threadRef.environmentId],
170 );
171
172 const handleRefresh = useCallback(() => {
173 if (previewBridge && runtimeTabId) void previewBridge.refresh(runtimeTabId);
174 }, [runtimeTabId]);
175
176 const handleZoomIn = useCallback(() => {
177 if (previewBridge && runtimeTabId) void previewBridge.zoomIn(runtimeTabId);
178 }, [runtimeTabId]);
179
180 const handleZoomOut = useCallback(() => {
181 if (previewBridge && runtimeTabId) void previewBridge.zoomOut(runtimeTabId);
182 }, [runtimeTabId]);
183
184 const handleResetZoom = useCallback(() => {
185 if (previewBridge && runtimeTabId) void previewBridge.resetZoom(runtimeTabId);
186 }, [runtimeTabId]);
187
188 const handleViewportChange = useCallback(
189 async (nextViewport: PreviewViewportSetting) => {
190 if (!tabId) return;
191 const result = await resize({
192 environmentId: threadRef.environmentId,
193 input: {
194 threadId: threadRef.threadId,
195 tabId,
196 viewport: nextViewport,
197 },
198 });
199 if (result._tag === "Failure") {
200 const error = squashAtomCommandFailure(result);
201 toastManager.add({
202 type: "error",
203 title: "Unable to resize browser viewport",
204 description: error instanceof Error ? error.message : "An error occurred.",
205 });
206 throw error;
207 }
208 updatePreviewServerSnapshot(threadRef, result.value);
209 },
210 [resize, tabId, threadRef],
211 );
212
213 const handleToggleDeviceToolbar = () => {
214 if (!runtimeTabId) return;
215 if (viewport._tag !== "fill") {
216 void commitBrowserViewportChange(runtimeTabId, FILL_PREVIEW_VIEWPORT).catch(() => undefined);
217 return;
218 }
219
220 const responsiveSize = panelRect
221 ? resolveResponsiveBrowserViewportSize(panelRect, desktopOverlay?.zoomFactor)
222 : { width: 1024, height: 768 };
223 void commitBrowserViewportChange(runtimeTabId, { _tag: "freeform", ...responsiveSize }).catch(
224 () => undefined,
225 );
226 };
227
228 useEffect(() => {
229 if (!runtimeTabId) return;
230 return subscribeBrowserViewportChange(runtimeTabId, handleViewportChange);
231 }, [handleViewportChange, runtimeTabId]);
232
233 const handleBack = useCallback(() => {
234 if (previewBridge && runtimeTabId) void previewBridge.goBack(runtimeTabId);
235 }, [runtimeTabId]);
236
237 const handleForward = useCallback(() => {
238 if (previewBridge && runtimeTabId) void previewBridge.goForward(runtimeTabId);
239 }, [runtimeTabId]);
240
241 const handleOpenInBrowser = useCallback(() => {
242 if (!localApi || !url) return;
243 void localApi.shell.openExternal(url).catch(() => undefined);
244 }, [url]);
245
246 const handlePictureInPicture = useCallback(() => {
247 if (!tabId) return;
248 if (miniPlayer?.tabId === tabId) {
249 usePreviewMiniPlayerStore.getState().close(threadRef);
250 return;
251 }
252 usePreviewMiniPlayerStore.getState().open(threadRef, tabId);
253 useRightPanelStore.getState().close(threadRef);
254 }, [miniPlayer?.tabId, tabId, threadRef]);
255
256 const handleNativePictureInPicture = useCallback(() => {
257 if (!previewBridge || !runtimeTabId) return;
258 const operation = desktopOverlay?.pictureInPicture
259 ? previewBridge.pictureInPicture.close
260 : previewBridge.pictureInPicture.open;
261 void operation(runtimeTabId).catch((error) => {
262 toastManager.add({
263 type: "error",
264 title: "Unable to update popped-out preview",
265 description: error instanceof Error ? error.message : "An error occurred.",
266 });
267 });
268 }, [desktopOverlay?.pictureInPicture, runtimeTabId]);
269
270 const handleCapture = useCallback(
271 (record: boolean) => {
272 if (!previewBridge || !runtimeTabId || !tabId) return;
273 const bridge = previewBridge;
274 if (recordingRuntimeTabId) {
275 void stopBrowserRecording(recordingRuntimeTabId).then(
276 (artifact) => {
277 if (!artifact) return;
278 let pathCopied = false;
279 let toastId: ReturnType<typeof toastManager.add>;
280
281 const copyPath = () => {
282 if (!navigator.clipboard?.writeText) {
283 toastManager.update(
284 toastId,
285 stackedThreadToast({
286 type: "error",
287 title: "Unable to copy recording path",
288 description: "Clipboard API unavailable.",
289 actionProps: revealAction,
290 }),
291 );
292 return;
293 }
294
295 void navigator.clipboard.writeText(artifact.path).then(
296 () => {
297 pathCopied = true;
298 updateRecordingToast();
299 window.setTimeout(() => {
300 pathCopied = false;
301 updateRecordingToast();
302 }, 2_000);
303 },
304 (error) => {
305 toastManager.update(
306 toastId,
307 stackedThreadToast({
308 type: "error",
309 title: "Unable to copy recording path",
310 description: error instanceof Error ? error.message : "An error occurred.",
311 actionProps: revealAction,
312 }),
313 );
314 },
315 );
316 };
317
318 const revealAction = {
319 children: revealInFileExplorerLabel(navigator.platform),
320 onClick: () => void bridge.revealArtifact(artifact.path),
321 };
322 const updateRecordingToast = () => {
323 toastManager.update(
324 toastId,
325 stackedThreadToast({
326 type: "success",
327 title: "Recording saved",
328 actionProps: revealAction,
329 data: {
330 secondaryActionProps: {
331 children: pathCopied ? "Copied!" : "Copy path",
332 disabled: pathCopied,
333 onClick: copyPath,
334 },
335 secondaryActionVariant: "outline",
336 },
337 }),
338 );
339 };
340
341 toastId = toastManager.add(
342 stackedThreadToast({
343 type: "success",
344 title: "Recording saved",
345 actionProps: revealAction,
346 data: {
347 secondaryActionProps: {
348 children: "Copy path",
349 onClick: copyPath,
350 },
351 secondaryActionVariant: "outline",
352 },
353 }),
354 );
355 },
356 (error) => {
357 toastManager.add({
358 type: "error",
359 title: "Unable to stop recording",
360 description: error instanceof Error ? error.message : "An error occurred.",
361 });
362 },
363 );
364 return;
365 }
366 if (record) {
367 void startBrowserRecording(runtimeTabId, threadRef, tabId).catch((error) => {
368 toastManager.add({
369 type: "error",
370 title: "Unable to start recording",
371 description: error instanceof Error ? error.message : "An error occurred.",
372 });
373 });
374 return;
375 }
376 void bridge.captureScreenshot(runtimeTabId).then(
377 (artifact) => {
378 const revealAction = {
379 children: revealInFileExplorerLabel(navigator.platform),
380 onClick: () => void bridge.revealArtifact(artifact.path),
381 };
382 let pathCopied = false;
383 let imageCopied = false;
384 let toastId: ReturnType<typeof toastManager.add>;
385
386 const updateScreenshotToast = (
387 type: "success" | "error" = "success",
388 title = "Screenshot saved",
389 description?: string,
390 ) => {
391 toastManager.update(
392 toastId,
393 stackedThreadToast({
394 type,
395 title,
396 description,
397 actionProps: {
398 children: imageCopied ? "Copied!" : "Copy image",
399 disabled: imageCopied,
400 onClick: copyImage,
401 },
402 data: {
403 additionalActions: [
404 {
405 id: "copy-path",
406 props: {
407 children: pathCopied ? "Copied!" : "Copy path",
408 disabled: pathCopied,
409 onClick: copyPath,
410 },
411 },
412 ],
413 secondaryActionProps: {
414 ...revealAction,
415 },
416 secondaryActionVariant: "outline",
417 },
418 }),
419 );
420 };
421
422 const copyPath = () => {
423 if (!navigator.clipboard?.writeText) {
424 updateScreenshotToast(
425 "error",
426 "Unable to copy screenshot path",
427 "Clipboard API unavailable.",
428 );
429 return;
430 }
431
432 void navigator.clipboard.writeText(artifact.path).then(
433 () => {
434 pathCopied = true;
435 updateScreenshotToast();
436 window.setTimeout(() => {
437 pathCopied = false;
438 updateScreenshotToast();
439 }, 2_000);
440 },
441 (error) => {
442 updateScreenshotToast(
443 "error",
444 "Unable to copy screenshot path",
445 error instanceof Error ? error.message : "An error occurred.",
446 );
447 },
448 );
449 };
450
451 const copyImage = () => {
452 void bridge.copyArtifactToClipboard(artifact.path).then(
453 () => {
454 imageCopied = true;
455 updateScreenshotToast();
456 window.setTimeout(() => {
457 imageCopied = false;
458 updateScreenshotToast();
459 }, 2_000);
460 },
461 (error) => {
462 updateScreenshotToast(
463 "error",
464 "Unable to copy screenshot",
465 error instanceof Error ? error.message : "An error occurred.",
466 );
467 },
468 );
469 };
470
471 toastId = toastManager.add(
472 stackedThreadToast({
473 type: "success",
474 title: "Screenshot saved",
475 actionProps: {
476 children: "Copy image",
477 onClick: copyImage,
478 },
479 data: {
480 additionalActions: [
481 {
482 id: "copy-path",
483 props: {
484 children: "Copy path",
485 onClick: copyPath,
486 },
487 },
488 ],
489 secondaryActionProps: {
490 ...revealAction,
491 },
492 secondaryActionVariant: "outline",
493 },
494 }),
495 );
496 },
497 (error) => {
498 toastManager.add({
499 type: "error",
500 title: "Unable to capture screenshot",
501 description: error instanceof Error ? error.message : "An error occurred.",
502 });
503 },
504 );
505 },
506 [recordingRuntimeTabId, runtimeTabId, tabId, threadRef],
507 );
508
509 const handlePickElement = useCallback(() => {
510 if (!previewBridge || !runtimeTabId) return;
511 if (pickActiveRef.current) {
512 void previewBridge.cancelPickElement(runtimeTabId).catch(() => undefined);
513 return;
514 }
515 // Snapshot whatever the user was focused on (typically the chat
516 // composer textarea or the chrome-row pick button) BEFORE main steals
517 // focus into the guest webContents. We restore it when the pick
518 // resolves so the user's typing context isn't lost — otherwise after
519 // every pick they'd have to click back into the textarea.
520 const previouslyFocused =
521 typeof document !== "undefined" ? (document.activeElement as HTMLElement | null) : null;
522 pickActiveRef.current = true;
523 setPickActive(true);
524 void (async () => {
525 try {
526 const annotation = await previewBridge.pickElement(runtimeTabId);
527 if (!annotation) return;
528 addPreviewAnnotation(threadRef, annotation);
529 const screenshotFile = await previewAnnotationScreenshotFile(annotation);
530 if (screenshotFile && annotation.screenshot) {
531 addImage(threadRef, {
532 type: "image",
533 id: annotation.id,
534 name: screenshotFile.name,
535 mimeType: screenshotFile.type,
536 sizeBytes: screenshotFile.size,
537 previewUrl: annotation.screenshot.dataUrl,
538 file: screenshotFile,
539 });
540 }
541 } catch {
542 // Picker failed (e.g. webview navigated). Treat as silent cancel.
543 } finally {
544 pickActiveRef.current = false;
545 // Avoid `setState on unmounted component` if the panel/thread closed
546 // while the pick was in flight.
547 if (isMountedRef.current) setPickActive(false);
548 // Best-effort: restore focus to whatever the user had before the
549 // pick stole it into the guest webContents. Skip if the previously-
550 // focused element was unmounted or is no longer focusable.
551 if (
552 previouslyFocused &&
553 previouslyFocused.isConnected &&
554 typeof previouslyFocused.focus === "function"
555 ) {
556 try {
557 previouslyFocused.focus({ preventScroll: true });
558 } catch {
559 // Some elements throw on .focus() (detached iframes, etc.).
560 }
561 }
562 }
563 })();
564 }, [addImage, addPreviewAnnotation, runtimeTabId, threadRef]);
565
566 // If the active tab changes mid-pick (close, thread switch, hot restart),
567 // tell main to tear down the in-flight session AND reset our local toggle
568 // state so the button doesn't get stuck pressed against a stale tab id.
569 useEffect(() => {
570 return () => {
571 if (!pickActiveRef.current) return;
572 pickActiveRef.current = false;
573 if (previewBridge && runtimeTabId) {
574 void previewBridge.cancelPickElement(runtimeTabId).catch(() => undefined);
575 }
576 if (isMountedRef.current) setPickActive(false);
577 };
578 }, [runtimeTabId]);
579
580 // Subscribe only while visible; `toggle-panel` is owned by ChatView's
581 // URL-aware handler regardless of whether the panel is currently mounted.
582 useEffect(() => {
583 if (!visible) return;
584 return subscribePreviewAction((action) => {
585 switch (action) {
586 case "refresh":
587 handleRefresh();
588 return;
589 case "focus-url":
590 setFocusUrlNonce((value) => (value ?? 0) + 1);
591 return;
592 case "zoom-in":
593 handleZoomIn();
594 return;
595 case "zoom-out":
596 handleZoomOut();
597 return;
598 case "reset-zoom":
599 handleResetZoom();
600 return;
601 case "toggle-panel":
602 return;
603 }
604 });
605 }, [handleRefresh, handleResetZoom, handleZoomIn, handleZoomOut, visible]);
606
607 return (
608 <div
609 className="flex min-h-0 flex-1 flex-col bg-background"
610 data-thread-key={scopedThreadKey(threadRef)}
611 >
612 <PreviewChromeRow
613 url={url}
614 displayUrl={displayUrl}
615 loading={loading}
616 loadProgress={loadProgress}
617 canGoBack={canGoBack}
618 canGoForward={canGoForward}
619 refreshDisabled={refreshDisabled}
620 focusUrlNonce={focusUrlNonce}
621 onBack={handleBack}
622 onForward={handleForward}
623 onRefresh={handleRefresh}
624 onSubmit={(next) => void handleSubmitUrl(next)}
625 onOpenInBrowser={tabId ? handleOpenInBrowser : undefined}
626 onCapture={previewBridge && tabId ? handleCapture : undefined}
627 captureDisabled={!desktopOverlay || isUnreachable}
628 recording={recordingRuntimeTabId !== null}
629 onPictureInPicture={previewBridge && tabId ? handlePictureInPicture : undefined}
630 pictureInPicture={miniPlayer?.tabId === tabId}
631 pictureInPictureDisabled={!desktopOverlay?.hasWebContents || isUnreachable}
632 onPickElement={previewBridge && tabId ? handlePickElement : undefined}
633 pickActive={pickActive}
634 // Disable when there's no tab (nothing to pick on) OR the page
635 // failed to load (a React overlay covers the webview, so the
636 // user wouldn't be able to actually click anything underneath).
637 pickDisabled={!tabId || isUnreachable}
638 pickDisabledReason={
639 isUnreachable ? "Page didn't load — pick unavailable until the page renders" : undefined
640 }
641 trailingActions={
642 previewBridge ? (
643 <PreviewMoreMenu
644 tabId={runtimeTabId}
645 hasWebContents={desktopOverlay?.hasWebContents ?? false}
646 zoomFactor={desktopOverlay?.zoomFactor ?? 1}
647 colorScheme={desktopOverlay?.colorScheme ?? "system"}
648 deviceToolbarVisible={viewport._tag !== "fill"}
649 onToggleDeviceToolbar={handleToggleDeviceToolbar}
650 nativePictureInPicture={desktopOverlay?.pictureInPicture ?? false}
651 onNativePictureInPicture={handleNativePictureInPicture}
652 />
653 ) : null
654 }
655 />
656
657 <div className="relative min-h-0 flex-1 overflow-hidden">
658 {runtimeTabId && snapshot && !showEmptyState ? (
659 <BrowserSurfaceSlot
660 key={runtimeTabId}
661 tabId={runtimeTabId}
662 visible={visible && !isUnreachable}
663 className="absolute inset-0 h-full w-full"
664 />
665 ) : null}
666 {showEmptyState ? (
667 <PreviewEmptyState
668 environmentId={threadRef.environmentId}
669 configuredUrls={configuredUrls}
670 recentlySeenUrls={previewState.recentlySeenUrls}
671 onOpenUrl={(next) => void handleOpenServerUrl(next)}
672 />
673 ) : null}
674 {snapshot && desktopOverlay ? (
675 <ZoomIndicator zoomFactor={desktopOverlay.zoomFactor} />
676 ) : null}
677 {runtimeTabId && desktopOverlay && !showEmptyState && !isUnreachable ? (
678 <AgentBrowserCursor
679 tabId={runtimeTabId}
680 zoomFactor={desktopOverlay.zoomFactor}
681 controller={controller}
682 />
683 ) : null}
684 {controller !== "none" ? (
685 <div className="pointer-events-none absolute left-3 top-3 z-40 rounded-full border border-border/70 bg-background/90 px-2.5 py-1 text-[11px] font-medium shadow-sm backdrop-blur">
686 {controller === "agent" ? "Agent controlling browser" : "Human control"}
687 </div>
688 ) : null}
689 {navStatus._tag === "LoadFailed" ? (
690 <div className="absolute inset-0 z-10 bg-background">
691 <PreviewUnreachable
692 url={navStatus.url}
693 code={navStatus.code}
694 description={navStatus.description}
695 onReload={handleRefresh}
696 />
697 </div>
698 ) : null}
699 </div>
700 </div>
701 );
702}