From a8757d603a734c44da6a28e19508663f16700839 Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Wed, 25 Mar 2026 13:18:09 +0000 Subject: [PATCH] fix(site): use lightbox for computer tool screenshots in PWA mode (#23529) --- .../components/ai-elements/tool.stories.tsx | 6 +-- .../ai-elements/tool/ComputerTool.tsx | 41 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/site/src/components/ai-elements/tool.stories.tsx b/site/src/components/ai-elements/tool.stories.tsx index 35971f20f1..fba611d89f 100644 --- a/site/src/components/ai-elements/tool.stories.tsx +++ b/site/src/components/ai-elements/tool.stories.tsx @@ -849,9 +849,9 @@ export const ComputerScreenshot: Story = { }); expect(img).toBeInTheDocument(); expect(img.getAttribute("src")).toContain("data:image/jpeg;base64,"); - // Image should be wrapped in a link that opens in a new tab. - const link = img.closest("a"); - expect(link).toHaveAttribute("target", "_blank"); + // Image should be wrapped in a button that opens the lightbox. + const button = img.closest("button"); + expect(button).toBeInTheDocument(); }, }; diff --git a/site/src/components/ai-elements/tool/ComputerTool.tsx b/site/src/components/ai-elements/tool/ComputerTool.tsx index 93a531bd39..112539fb95 100644 --- a/site/src/components/ai-elements/tool/ComputerTool.tsx +++ b/site/src/components/ai-elements/tool/ComputerTool.tsx @@ -1,19 +1,22 @@ import { CircleAlertIcon, LoaderIcon } from "lucide-react"; import type React from "react"; +import { useState } from "react"; import { cn } from "utils/cn"; import { Tooltip, TooltipContent, TooltipTrigger, } from "#/components/Tooltip/Tooltip"; +import { ImageLightbox } from "#/pages/AgentsPage/components/ImageLightbox"; import { ToolCollapsible } from "./ToolCollapsible"; import type { ToolStatus } from "./utils"; /** * Renders screenshots returned by Anthropic's computer use tool. * When the result contains base64 image data, the actual image is - * displayed instead of raw JSON. The image is clickable and opens - * in a new tab at full resolution. + * displayed instead of raw JSON. Clicking the image opens it in an + * in-app lightbox overlay rather than a new tab so that it works + * correctly in PWA / standalone mode on iOS. */ export const ComputerTool: React.FC<{ imageData: string; @@ -23,10 +26,12 @@ export const ComputerTool: React.FC<{ isError: boolean; errorMessage?: string; }> = ({ imageData, mimeType, text, status, isError, errorMessage }) => { + const [showLightbox, setShowLightbox] = useState(false); const isRunning = status === "running"; const hasImage = imageData.length > 0; const hasText = text.length > 0; const hasContent = hasImage || hasText; + const imageSrc = hasImage ? `data:${mimeType};base64,${imageData}` : ""; return ( {hasImage ? ( -
- - Screenshot from computer tool +
+ +
+ {showLightbox && ( + setShowLightbox(false)} /> -
-
+ )} + ) : hasText ? (