favicon.ts
1/**2 * Resolves a favicon URL for a given domain.3 *4 * On Chrome MV3 with the `favicon` permission, returns a URL backed by the5 * browser's own favicon cache (no network, no third party). On Firefox and6 * other browsers where the API is unavailable, returns null so callers can7 * render a generic fallback icon.8 *9 * Never fetches from any external URL. No domain name leaves the browser.10 */11export function faviconUrl(domain: string): string | null {12 if (!domain) return null;13 if (typeof chrome === "undefined" || !chrome.runtime?.getURL) return null;1415 try {16 const url = new URL(chrome.runtime.getURL("/_favicon/"));17 url.searchParams.set("pageUrl", `https://${domain}`);18 url.searchParams.set("size", "32");19 return url.toString();20 } catch {21 return null;22 }23}