microlink logo

Microlink Recipe

Retrieve the favicon for any website

getFavicon.js
const mql = require('@microlink/mql')

const getFavicon = async (url, opts) => {
  const { data } = await mql(url, {
    meta: false,
    data: {
      favicon: [
        {
          selector: 'link[href*="favicon.ico"]',
          attr: 'href',
          type: 'image',
        },
        {
          selector: 'link[type="image/x-icon"]',
          attr: 'href',
          type: 'image',
        },
      ],
    },
    ...opts,
  })

  return data.favicon
}

const result = await getFavicon('https://microlink.io')
console.log(result)