/** * Resolves a favicon URL for a given domain. * * On Chrome MV3 with the `favicon` permission, returns a URL backed by the * browser's own favicon cache (no network, no third party). On Firefox and * other browsers where the API is unavailable, returns null so callers can * render a generic fallback icon. * * Never fetches from any external URL. No domain name leaves the browser. */ export function faviconUrl(domain: string): string | null { if (!domain) return null; if (typeof chrome === "undefined" || !chrome.runtime?.getURL) return null; try { const url = new URL(chrome.runtime.getURL("/_favicon/")); url.searchParams.set("pageUrl", `https://${domain}`); url.searchParams.set("size", "32"); return url.toString(); } catch { return null; } }