YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: make URLs in screenshots clickable
Louis Beaumont50ef52d1496a
diff --git a/apps/screenpipe-app-tauri/components/__tests__/text-overlay.test.tsx b/apps/screenpipe-app-tauri/components/__tests__/text-overlay.test.tsxindex aaa0a09da..e897682c6 100644--- a/apps/screenpipe-app-tauri/components/__tests__/text-overlay.test.tsx+++ b/apps/screenpipe-app-tauri/components/__tests__/text-overlay.test.tsx@@ -4,6 +4,11 @@ import { render, screen, fireEvent } from "@testing-library/react";import { TextOverlay, isUrl, normalizeUrl } from "../text-overlay";import type { TextPosition } from "@/lib/hooks/use-frame-ocr-data";+// Mock @tauri-apps/plugin-shell+vi.mock("@tauri-apps/plugin-shell", () => ({+ open: vi.fn().mockResolvedValue(undefined),+}));+describe("TextOverlay", () => {const createTextPosition = (text: string,@@ -32,14 +37,13 @@ describe("TextOverlay", () => {expect(container.firstChild).toBeNull();});- it("should render text positions with correct scaling", () => {- // Using normalized coordinates (0-1 range)+ it("should render nothing when no URLs in text positions (only URLs rendered)", () => {const positions = [createTextPosition("Hello", 0.1, 0.05, 0.08, 0.02),createTextPosition("World", 0.2, 0.05, 0.1, 0.02),];- const { getByText } = render(+ const { container } = render(<TextOverlaytextPositions={positions}originalWidth={1920}@@ -49,56 +53,34 @@ describe("TextOverlay", () => {/>);- expect(getByText("Hello")).toBeInTheDocument();- expect(getByText("World")).toBeInTheDocument();- });-- it("should scale normalized coordinates correctly", () => {- // Normalized coordinates: left=0.1 (10%), top=0.2 (20%), width=0.08, height=0.04- const positions = [createTextPosition("Test", 0.1, 0.2, 0.08, 0.04)];-- const { container } = render(- <TextOverlay- textPositions={positions}- originalWidth={1000}- originalHeight={1000}- displayedWidth={500}- displayedHeight={500}- />- );-- const textElement = container.querySelector("span");- expect(textElement).toHaveStyle({- left: "50px", // 0.1 * 500- top: "100px", // 0.2 * 500- width: "40px", // 0.08 * 500- height: "20px", // 0.04 * 500- });+ // Only URLs are rendered, so non-URL text produces null+ expect(container.firstChild).toBeNull();});- it("should filter out text below minimum confidence", () => {+ it("should render URLs as clickable links", () => {const positions = [- createTextPosition("HighConf", 0.1, 0.05, 0.08, 0.02, 0.9),- createTextPosition("LowConf", 0.2, 0.05, 0.08, 0.02, 0.3),+ createTextPosition("https://example.com", 0.1, 0.05, 0.2, 0.02),+ createTextPosition("Regular text", 0.1, 0.1, 0.15, 0.02),];- const { getByText, queryByText } = render(+ const { container } = render(<TextOverlaytextPositions={positions}originalWidth={1920}originalHeight={1080}displayedWidth={960}displayedHeight={540}- minConfidence={0.5}+ clickableUrls={true}/>);- expect(getByText("HighConf")).toBeInTheDocument();- expect(queryByText("LowConf")).not.toBeInTheDocument();+ const link = container.querySelector("a");+ expect(link).toBeInTheDocument();+ expect(link).toHaveAttribute("href", "https://example.com");});it("should render nothing when displayed dimensions are invalid", () => {- const positions = [createTextPosition("Test", 0.1, 0.05, 0.08, 0.02)];+ const positions = [createTextPosition("https://example.com", 0.1, 0.05, 0.2, 0.02)];const { container } = render(<TextOverlay@@ -113,51 +95,12 @@ describe("TextOverlay", () => {expect(container.firstChild).toBeNull();});- it("should filter out positions with invalid scaled dimensions", () => {- const positions = [- createTextPosition("Valid", 0.1, 0.05, 0.08, 0.02),- createTextPosition("ZeroWidth", 0.2, 0.05, 0, 0.02),- createTextPosition("ZeroHeight", 0.3, 0.05, 0.08, 0),- ];-- const { getByText, queryByText } = render(- <TextOverlay- textPositions={positions}- originalWidth={1920}- originalHeight={1080}- displayedWidth={960}- displayedHeight={540}- />- );-- expect(getByText("Valid")).toBeInTheDocument();- expect(queryByText("ZeroWidth")).not.toBeInTheDocument();- expect(queryByText("ZeroHeight")).not.toBeInTheDocument();- });-it("should filter out positions outside the display bounds", () => {const positions = [- createTextPosition("Inside", 0.1, 0.05, 0.08, 0.02),- createTextPosition("Outside", 1.5, 0.05, 0.08, 0.02), // Beyond normalized 1.0+ createTextPosition("https://inside.com", 0.1, 0.05, 0.2, 0.02),+ createTextPosition("https://outside.com", 1.5, 0.05, 0.2, 0.02),];- const { getByText, queryByText } = render(- <TextOverlay- textPositions={positions}- originalWidth={1920}- originalHeight={1080}- displayedWidth={960}- displayedHeight={540}- />- );-- expect(getByText("Inside")).toBeInTheDocument();- expect(queryByText("Outside")).not.toBeInTheDocument();- });-- it("should apply debug styles when debug prop is true", () => {- const positions = [createTextPosition("Debug", 0.1, 0.05, 0.08, 0.02)];-const { container } = render(<TextOverlaytextPositions={positions}@@ -165,35 +108,19 @@ describe("TextOverlay", () => {originalHeight={1080}displayedWidth={960}displayedHeight={540}- debug={true}+ clickableUrls={true}/>);- const textElement = container.querySelector("span");- expect(textElement).toHaveClass("border");- expect(textElement).toHaveClass("border-red-500/50");+ const links = container.querySelectorAll("a");+ expect(links.length).toBe(1);+ expect(links[0]).toHaveAttribute("href", "https://inside.com");});- it("should have transparent text when debug is false", () => {- const positions = [createTextPosition("Hidden", 0.1, 0.05, 0.08, 0.02)];-- const { container } = render(- <TextOverlay- textPositions={positions}- originalWidth={1920}- originalHeight={1080}- displayedWidth={960}- displayedHeight={540}- debug={false}- />- );-- const textElement = container.querySelector("span");- expect(textElement).toHaveClass("text-transparent");- });+ it("should use shell.open on click via Tauri plugin", async () => {+ const { open: mockShellOpen } = await import("@tauri-apps/plugin-shell");- it("should enable text selection with user-select CSS", () => {- const positions = [createTextPosition("Selectable", 0.1, 0.05, 0.08, 0.02)];+ const positions = [createTextPosition("https://test.com/page", 0.1, 0.05, 0.2, 0.02)];const { container } = render(<TextOverlay@@ -202,67 +129,20 @@ describe("TextOverlay", () => {originalHeight={1080}displayedWidth={960}displayedHeight={540}+ clickableUrls={true}/>);- const textElement = container.querySelector("span");- expect(textElement).toHaveStyle({ userSelect: "text" });- });-- it("should set container dimensions to match displayed image", () => {- const positions = [createTextPosition("Test", 0.1, 0.05, 0.08, 0.02)];-- const { container } = render(- <TextOverlay- textPositions={positions}- originalWidth={1920}- originalHeight={1080}- displayedWidth={800}- displayedHeight={450}- />- );-- const overlayContainer = container.firstChild as HTMLElement;- expect(overlayContainer).toHaveStyle({- width: "800px",- height: "450px",- });- });-- it("should handle many text positions efficiently", () => {- // Create 1000 text positions to test performance (using normalized coordinates)- const positions = Array.from({ length: 1000 }, (_, i) =>- createTextPosition(`Word${i}`, (i % 100) * 0.01, Math.floor(i / 100) * 0.1, 0.05, 0.015)- );-- const startTime = performance.now();-- const { container } = render(- <TextOverlay- textPositions={positions}- originalWidth={10000}- originalHeight={2000}- displayedWidth={1000}- displayedHeight={200}- />- );-- const endTime = performance.now();- const renderTime = endTime - startTime;+ const link = container.querySelector("a");+ expect(link).toBeInTheDocument();- // Rendering 1000 elements should take less than 100ms- expect(renderTime).toBeLessThan(100);+ fireEvent.click(link!);- // Verify some elements rendered- const spans = container.querySelectorAll("span");- expect(spans.length).toBeGreaterThan(0);+ expect(mockShellOpen).toHaveBeenCalledWith("https://test.com/page");});- it("should render URLs as clickable links when clickableUrls is true", () => {- const positions = [- createTextPosition("https://example.com", 0.1, 0.05, 0.2, 0.02),- createTextPosition("Regular text", 0.1, 0.1, 0.15, 0.02),- ];+ it("should show visible underline on URL links (not invisible)", () => {+ const positions = [createTextPosition("https://example.com", 0.1, 0.3, 0.2, 0.02)];const { container } = render(<TextOverlay@@ -275,40 +155,40 @@ describe("TextOverlay", () => {/>);- const link = container.querySelector("a");- const span = container.querySelector("span");-+ const link = container.querySelector("a") as HTMLElement;expect(link).toBeInTheDocument();- expect(link).toHaveAttribute("href", "https://example.com");- expect(span).toBeInTheDocument();- expect(span?.textContent).toBe("Regular text");+ // Should have a visible border-bottom (underline)+ expect(link.style.borderBottom).toContain("solid");+ expect(link.style.cursor).toBe("pointer");});- it("should not render URLs as links when clickableUrls is false", () => {- const positions = [createTextPosition("https://example.com", 0.1, 0.05, 0.2, 0.02)];+ it("should expand small click targets to minimum height", () => {+ // OCR box is only 10px tall at display size (0.02 * 500 = 10px)+ const positions = [createTextPosition("https://tiny.com", 0.1, 0.3, 0.2, 0.02)];const { container } = render(<TextOverlaytextPositions={positions}- originalWidth={1920}- originalHeight={1080}- displayedWidth={960}- displayedHeight={540}- clickableUrls={false}+ originalWidth={1000}+ originalHeight={1000}+ displayedWidth={500}+ displayedHeight={500}/>);- const link = container.querySelector("a");- const span = container.querySelector("span");-- expect(link).not.toBeInTheDocument();- expect(span).toBeInTheDocument();+ const link = container.querySelector("a") as HTMLElement;+ expect(link).toBeInTheDocument();+ // Height should be expanded to at least 24px (MIN_LINK_HEIGHT)+ const height = parseFloat(link.style.height);+ expect(height).toBeGreaterThanOrEqual(24);});- it("should open URL in new tab when clicked", () => {- const mockOpen = vi.spyOn(window, "open").mockImplementation(() => null);-- const positions = [createTextPosition("https://test.com/page", 0.1, 0.05, 0.2, 0.02)];+ it("should detect domain-like URLs with various TLDs", () => {+ const positions = [+ createTextPosition("app.crisp.chat", 0.1, 0.1, 0.15, 0.02),+ createTextPosition("screenpi.pe", 0.1, 0.2, 0.1, 0.02),+ createTextPosition("youtube.com", 0.1, 0.3, 0.1, 0.02),+ ];const { container } = render(<TextOverlay@@ -321,18 +201,8 @@ describe("TextOverlay", () => {/>);- const link = container.querySelector("a");- expect(link).toBeInTheDocument();-- fireEvent.click(link!);-- expect(mockOpen).toHaveBeenCalledWith(- "https://test.com/page",- "_blank",- "noopener,noreferrer"- );-- mockOpen.mockRestore();+ const links = container.querySelectorAll("a");+ expect(links.length).toBe(3);});});@@ -352,16 +222,33 @@ describe("isUrl", () => {expect(isUrl("www.example.com/path")).toBe(true);});- it("should detect domain-like strings", () => {+ it("should detect domain-like strings with common TLDs", () => {expect(isUrl("example.com")).toBe(true);expect(isUrl("example.io")).toBe(true);expect(isUrl("app.example.dev")).toBe(true);});+ it("should detect domain-like strings with less common TLDs", () => {+ expect(isUrl("app.crisp.chat")).toBe(true);+ expect(isUrl("screenpi.pe")).toBe(true);+ expect(isUrl("example.cafe")).toBe(true);+ expect(isUrl("my.site.agency")).toBe(true);+ });+it("should not detect regular text as URLs", () => {expect(isUrl("hello")).toBe(false);expect(isUrl("hello world")).toBe(false);expect(isUrl("email@example")).toBe(false);+ expect(isUrl("just some text")).toBe(false);+ });++ it("should not match text with spaces", () => {+ expect(isUrl("reddit .com")).toBe(false);+ expect(isUrl("hello .world")).toBe(false);+ });++ it("should not match single-char TLDs", () => {+ expect(isUrl("test.a")).toBe(false);});});@@ -383,6 +270,8 @@ describe("normalizeUrl", () => {});it("should trim whitespace", () => {- expect(normalizeUrl(" https://example.com ")).toBe("https://example.com");+ expect(normalizeUrl(" https://example.com ")).toBe(+ "https://example.com"+ );});});diff --git a/apps/screenpipe-app-tauri/components/text-overlay.tsx b/apps/screenpipe-app-tauri/components/text-overlay.tsxindex 97c88c51f..51a697e22 100644--- a/apps/screenpipe-app-tauri/components/text-overlay.tsx+++ b/apps/screenpipe-app-tauri/components/text-overlay.tsx@@ -1,16 +1,25 @@"use client";-import { useCallback, useMemo, memo } from "react";+import { useCallback, useMemo, memo, useState } from "react";import { cn } from "@/lib/utils";+import { open as shellOpen } from "@tauri-apps/plugin-shell";import type { TextPosition } from "@/lib/hooks/use-frame-ocr-data";/*** Check if a string looks like a URL.- * Matches http(s)://, www., and common domain patterns.+ * Matches http(s)://, www., and domain-like patterns.+ * Uses a permissive TLD check: any 2-13 char alphabetic TLD is accepted+ * because OCR text won't produce false positives like "hello.world"+ * in a screenshot context — the text is already rendered UI.*/export function isUrl(text: string): boolean {const trimmed = text.trim();+ // Reject if contains spaces (URLs don't have spaces)+ if (/\s/.test(trimmed)) {+ return false;+ }+// Check for explicit protocolif (/^https?:\/\//i.test(trimmed)) {return true;@@ -21,11 +30,12 @@ export function isUrl(text: string): boolean {return true;}- // Check for domain-like patterns (word.tld or word.word.tld)- // Common TLDs- const tldPattern = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\.(com|org|net|io|dev|app|co|ai|edu|gov|info|biz|me|tv|uk|de|fr|jp|au|ca|nl|ru|br|es|it|ch|se|no|at|be|dk|fi|nz|za|mx|kr|tw|hk|sg|id|tr|xyz|online|site|tech|store|blog|cloud|page|link|click|space|fun|live|news|world|email|today|top|pro|club|shop|website)(\/.*)?$/i;+ // Check for domain-like patterns: word.tld or sub.word.tld+ // Accept any alphabetic TLD with 2-13 chars (covers .com, .chat, .pe, .website, etc.)+ const domainPattern =+ /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\.[a-zA-Z]{2,13}(\/[^\s]*)?$/;- return tldPattern.test(trimmed);+ return domainPattern.test(trimmed);}/**@@ -78,13 +88,15 @@ interface ScaledTextPositionWithUrl extends ScaledTextPosition {normalizedUrl?: string;}+// Minimum click target height in pixels — OCR boxes can be tiny (8-13px)+const MIN_LINK_HEIGHT = 24;+// Extra horizontal padding on each side for easier clicking+const LINK_PADDING_X = 4;+/**- * TextOverlay renders transparent, selectable text positioned over a screenshot.- * This enables native text selection (Cmd+C / Ctrl+C) on OCR-extracted text.- * URLs are automatically detected and made clickable.- *- * NOTE: Currently disabled due to buggy text selection experience.- * TODO: Re-enable once text selection UX is improved.+ * TextOverlay renders clickable URL links positioned over a screenshot.+ * URLs are detected from OCR text and rendered as visible, hoverable links.+ * Clicking opens the URL in the system default browser via Tauri shell.*/export const TextOverlay = memo(function TextOverlay({textPositions,@@ -97,8 +109,7 @@ export const TextOverlay = memo(function TextOverlay({debug = false,clickableUrls = true,}: TextOverlayProps) {- // Text selection is disabled due to buggy UX, but URLs remain clickable- const textSelectionDisabled = true;+ const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);// Scale and filter text positions, detect URLs// Note: OCR bounds are normalized (0-1 range), so we multiply directly by displayed dimensions@@ -129,32 +140,33 @@ export const TextOverlay = memo(function TextOverlay({pos.scaledBounds.height > 0 &&pos.scaledBounds.left >= 0 &&pos.scaledBounds.top >= 0 &&- pos.scaledBounds.left + pos.scaledBounds.width <= displayedWidth + 1 &&- pos.scaledBounds.top + pos.scaledBounds.height <= displayedHeight + 1+ // Allow small overflow (1px tolerance) for rounding+ pos.scaledBounds.left + pos.scaledBounds.width <=+ displayedWidth + 1 &&+ pos.scaledBounds.top + pos.scaledBounds.height <=+ displayedHeight + 1);- }, [- textPositions,- displayedWidth,- displayedHeight,- minConfidence,- ]);+ }, [textPositions, displayedWidth, displayedHeight, minConfidence]);- // Calculate font size based on scaled height- const getFontSize = useCallback((height: number): number => {- // Use 90% of the height as font size for better alignment- return Math.max(8, height * 0.9);- }, []);-- const handleUrlClick = useCallback((url: string, e: React.MouseEvent) => {- e.preventDefault();- e.stopPropagation();- window.open(url, "_blank", "noopener,noreferrer");- }, []);+ const handleUrlClick = useCallback(+ async (url: string, e: React.MouseEvent) => {+ e.preventDefault();+ e.stopPropagation();+ try {+ await shellOpen(url);+ } catch (err) {+ console.error("failed to open URL:", url, err);+ // Fallback: try window.open+ window.open(url, "_blank", "noopener,noreferrer");+ }+ },+ []+ );- // Filter to only URLs if text selection is disabled- const positionsToRender = textSelectionDisabled- ? scaledPositions.filter((pos) => pos.isUrl && pos.normalizedUrl)- : scaledPositions;+ // Only render URLs (text selection is disabled for now)+ const positionsToRender = scaledPositions.filter(+ (pos) => pos.isUrl && pos.normalizedUrl+ );if (positionsToRender.length === 0) {return null;@@ -162,73 +174,80 @@ export const TextOverlay = memo(function TextOverlay({return (<div- className={cn(- "absolute inset-0 pointer-events-auto select-text overflow-hidden",- className- )}+ className={cn("absolute inset-0 overflow-hidden", className)}style={{width: displayedWidth,height: displayedHeight,+ pointerEvents: "none",}}>{positionsToRender.map((pos, index) => {- const isClickableUrl = clickableUrls && pos.isUrl && pos.normalizedUrl;+ if (!clickableUrls || !pos.normalizedUrl) return null;++ const isHovered = hoveredIndex === index;- if (isClickableUrl) {- return (- <a- key={`${index}-${pos.text.slice(0, 10)}`}- href={pos.normalizedUrl}- onClick={(e) => handleUrlClick(pos.normalizedUrl!, e)}- className={cn(- "absolute whitespace-pre leading-none",- debug- ? "border border-blue-500/50 bg-blue-500/20 text-blue-600"- : "text-transparent hover:text-blue-500/70 hover:underline"- )}- style={{- left: pos.scaledBounds.left,- top: pos.scaledBounds.top,- width: pos.scaledBounds.width,- height: pos.scaledBounds.height,- fontSize: getFontSize(pos.scaledBounds.height),- lineHeight: `${pos.scaledBounds.height}px`,- cursor: "pointer",- textDecoration: "none",- }}- title={debug ? `URL: ${pos.normalizedUrl}` : `Open ${pos.normalizedUrl}`}- target="_blank"- rel="noopener noreferrer"- >- {pos.text}- </a>- );- }+ // Enlarge the click target for small OCR boxes+ const rawH = pos.scaledBounds.height;+ const targetH = Math.max(rawH, MIN_LINK_HEIGHT);+ const extraY = (targetH - rawH) / 2;+ const targetW = pos.scaledBounds.width + LINK_PADDING_X * 2;return (- <span- key={`${index}-${pos.text.slice(0, 10)}`}- className={cn(- "absolute whitespace-pre leading-none",- debug- ? "border border-red-500/50 bg-red-500/10"- : "text-transparent"- )}+ <a+ key={`${index}-${pos.text.slice(0, 20)}`}+ href={pos.normalizedUrl}+ onClick={(e) => handleUrlClick(pos.normalizedUrl!, e)}+ onMouseEnter={() => setHoveredIndex(index)}+ onMouseLeave={() => setHoveredIndex(null)}+ className="absolute block"style={{- left: pos.scaledBounds.left,- top: pos.scaledBounds.top,- width: pos.scaledBounds.width,- height: pos.scaledBounds.height,- fontSize: getFontSize(pos.scaledBounds.height),- lineHeight: `${pos.scaledBounds.height}px`,- userSelect: "text",- WebkitUserSelect: "text",- cursor: "text",+ left: pos.scaledBounds.left - LINK_PADDING_X,+ top: pos.scaledBounds.top - extraY,+ width: targetW,+ height: targetH,+ cursor: "pointer",+ pointerEvents: "auto",+ // Visible underline always, highlight on hover+ borderBottom: isHovered+ ? "2px solid rgba(96, 165, 250, 0.9)"+ : "2px solid rgba(96, 165, 250, 0.45)",+ backgroundColor: isHovered+ ? "rgba(96, 165, 250, 0.15)"+ : "transparent",+ borderRadius: "2px",+ transition:+ "background-color 0.15s, border-color 0.15s",+ // Debug mode+ ...(debug+ ? {+ border: "1px solid rgba(59, 130, 246, 0.7)",+ backgroundColor:+ "rgba(59, 130, 246, 0.2)",+ }+ : {}),}}- title={debug ? `Confidence: ${(pos.confidence * 100).toFixed(1)}%` : undefined}+ title={`Open ${pos.normalizedUrl}`}+ target="_blank"+ rel="noopener noreferrer">- {pos.text}- </span>+ {/* Tooltip on hover showing the URL */}+ {isHovered && (+ <span+ className="absolute left-0 whitespace-nowrap text-xs px-2 py-1 rounded shadow-lg border z-50"+ style={{+ bottom: targetH + 4,+ backgroundColor: "rgba(0, 0, 0, 0.85)",+ color: "rgba(96, 165, 250, 1)",+ borderColor: "rgba(96, 165, 250, 0.3)",+ maxWidth: "400px",+ overflow: "hidden",+ textOverflow: "ellipsis",+ }}+ >+ {pos.normalizedUrl}+ </span>+ )}+ </a>);})}</div>