@iocium/favicon-fetcher
Version:
Favicon and BIMI logo fetcher for Cloudflare Workers and browser-compatible environments
45 lines (44 loc) • 1.94 kB
TypeScript
export type Service = 'google' | 'duckduckgo' | 'bitwarden' | 'yandex' | 'fastmail' | 'nextdns' | 'iconHorse' | 'bimi' | 'iocium' | 'faviconis' | 'faviconim';
/**
* Result returned by fetchFavicon including content and metadata.
*/
export interface FaviconResult {
/** Source URL used to fetch the favicon/logo */
url: string;
/** Content-Type of the returned image */
contentType: string | null;
/** Raw image data as an ArrayBuffer */
content: ArrayBuffer;
/** HTTP response status */
status: number;
}
/**
* FaviconFetcher allows downloading favicons or BIMI logos from a hostname using known services.
*/
export declare class FaviconFetcher {
private hostname;
private options?;
/**
* @param hostname The domain name to fetch the favicon/logo for.
* @param options Optional configuration including headers, iconHorse API key, and BIMI DNS settings.
*/
constructor(hostname: string, options?: {
/** API key for icon.horse Pro access (used only when service is 'iconHorse') */
iconHorseApiKey?: string;
/** Optional DNS-over-HTTPS server URL for BIMI lookups (defaults to Cloudflare) */
dohServerUrl?: string;
/** Optional custom headers to send with fetch (except protected headers like X-API-Key) */
headers?: Record<string, string>;
/** Optional enable or provide a CORS proxy prefix for browser fetch compatibility */
useCorsProxy?: boolean | string;
} | undefined);
private static serviceUrls;
/**
* Fetches the favicon or BIMI logo for the configured hostname using the specified service.
*
* @param service The provider to use (default is 'google').
* @returns A FaviconResult containing the image, status, and metadata.
* @throws If the fetch fails or BIMI DNS record is missing/invalid.
*/
fetchFavicon(service?: Service): Promise<FaviconResult>;
}