Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

favicon-thief

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

favicon-thief

Find the best favicon for a given URL.

latest
Source
npmnpm
Version
2.1.0
Version published
Maintainers
2
Created
Source

favicon-thief

Find the best favicon for a given URL.

Powers https://websktop.com.

Version License Node version Vulnerabilities Build Test Prettier

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));
// [
//   {
//     "sizes": [
//       {
//         "width": 144,
//         "height": 144
//       }
//     ],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon_144x144.png"
//   },
//   {
//     "sizes": [
//       {
//         "width": 96,
//         "height": 96
//       }
//     ],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon_96x96.png"
//   },
//   {
//     "sizes": [
//       {
//         "width": 48,
//         "height": 48
//       }
//     ],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon_48x48.png"
//   },
//   {
//     "sizes": [
//       {
//         "width": 32,
//         "height": 32
//       }
//     ],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon_32x32.png"
//   },
//   {
//     "sizes": [],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon.ico"
//   },
//   {
//     "sizes": [],
//     "source": "guess",
//     "url": "https://www.youtube.com/favicon.ico"
//   },
//   {
//     "sizes": [],
//     "source": "guess",
//     "url": "https://youtube.com/favicon.ico"
//   }
// ]

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 => {
  // bring your own fetching implementation - turn `url` into html here
  return {
    data: '<html><head><link rel="icon" href="icon.png" sizes="160x160"></head></html>',
    url, // return different url if there was a redirect
  };
};

const favicons = await findFavicons('http://example.com', myFetch);

console.log(JSON.stringify(favicons, null, 2));
// [
//   {
//     "sizes": [
//       {
//         "width": 160,
//         "height": 160
//       }
//     ],
//     "source": "html",
//     "url": "http://example.com/icon.png"
//   },
//   {
//     "sizes": [],
//     "source": "guess",
//     "url": "http://example.com/favicon.ico"
//   }
// ]

Keywords

favicon

FAQs

Package last updated on 25 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts