Open History to see the last commit
1/**
2 * Favicon helpers for the preview tab strip.
3 *
4 * Uses Google's s2 favicon endpoint (same approach as ami's tab strip).
5 * Callers should always render a `<Globe />` fallback when the returned URL
6 * fails to load via an `onError` handler.
7 */
8const FAVICON_PROVIDER = "https://www.google.com/s2/favicons";
9
10export function faviconUrlForOrigin(rawUrl: string | null | undefined, size = 32): string | null {
11 if (!rawUrl) return null;
12 try {
13 const url = new URL(rawUrl);
14 if (!url.host) return null;
15 if (url.protocol !== "http:" && url.protocol !== "https:") return null;
16 return `${FAVICON_PROVIDER}?domain=${encodeURIComponent(url.host)}&sz=${size}`;
17 } catch {
18 return null;
19 }
20}