Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

favicon.ts

23 lines838 Bytes

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