favicon-thief
Find the best favicon for a given URL.
Powers https://websktop.com.
Installation
npm install favicon-thief --save
API
getFavicons
Uses findFavicons
to get all favicons that represent given URL. Uses node-fetch & puppeteer to crawl webpages.
- Results are sorted - best first.
- Favors vector images, square images, and large images (in that order).
It's a wrapper for findFavicons
that provides fetch
implementations.
import { getFavicons } from 'favicon-thief';
const favicons = await getFavicons('https://websktop.com');
console.log(JSON.stringify(favicons, null, 2));
findFavicons
Finds all favicons that represent given URL.
- Pass your own fetching function.
- Results are sorted - best first.
- Favors vector images, square images, and large images (in that order).
- It never throws.
import { findFavicons } from 'favicon-thief';
const myFetch = async (url: string): string => {
return {
data: '<html><head><link rel="icon" href="icon.png" sizes="160x160"></head></html>',
url,
};
};
const favicons = await findFavicons('http://example.com', myFetch);
console.log(JSON.stringify(favicons, null, 2));