Get favicons list from a website
scrap-favicon
Get favicon urls without downloading it along with its meta information using
scrap-favicon
Introduction
The main aim of this package is to greedily fetch/scrap all the favicons and their dimensions without downloading it completely. (a few chunks can give correct dimensions).
- This package scraps/fetch the favicon from the website in two steps:
- Check the meta information declared.
- Add default favicon url (
/favicon.ico
&/apple-touch-icon.png
) and check if resource present.
- Download each url in chunks just to obtain favicon dimensions information using
image-size
package.
Install
$ npm install scrap-favicon
Usage
const scrapFavicon = ; // Fetching all meta information of favicon; // Fetching only urls of favicon; // Setting timeout(ms) and number of redirects for website url;
You can check examples here.
API
scrapFavicon(url, config?)
url
Type: string
A url of the website whose favicon details needs to be scrapped
config
Type: object
urlsOnly
Type: Boolean
Default: false
Returns only the list of the urls without meta information of favicon
timeout
Type: Number
Default: 100000
Number of milliseconds before waiting for website url to be fetched PS: In case of redirect, each redirected url will have its own timeout
maxRedirects
Type: Number
Default: 10
Max number of redirects allowed before reaching to website url due to 301 or 302 redirects
Example
const scrapFavicon = ; // Fetching all meta information of favicon;/*Result -> { redirects: [{ url: 'https://www.akansh.com/', timeTaken: 1140.6958409547806 // ms taken to redirect }], images: [ { url: 'https://www.akansh.com/icons/icon-48x48.png', scrapped: true, // true means it has been scrapped from the website width: 48, // width of the favicon image height: 48, // height of the favicon image type: 'png', // type of the favicon e.g. jpg, png, ico chunkSize: 1447, // the size downloaded to find the meta information of the image success: true }, { url: 'https://www.akansh.com/favicon.ico', scrapped: false, // false means it was not declared on website but still available width: 439, height: 439, type: 'svg', chunkSize: 81676, success: true }, { url: 'https://www.akansh.com/apple-touch-icon.png', scrapped: false, width: 439, height: 439, type: 'svg', chunkSize: 81676, success: true } ], timeTaken: 2341.6667330265045 } */