Skip to content

discoverFavicons ​

Discovers favicon URLs from a webpage or feed.

Signature ​

typescript
function discoverFavicons(
  input: DiscoverInput,
  options?: DiscoverOptions<FaviconResult>,
): Promise<Array<DiscoverResult<FaviconResult>>>

Parameters ​

input ​

The URL to discover favicons from. Can be a string or an object:

typescript
// String - URL to fetch and scan
discoverFavicons('https://example.com', options)

// Object - provide existing content/headers
discoverFavicons({
  url: 'https://example.com',
  content: htmlContent,
  headers: responseHeaders,
}, options)

options ​

All options are optional. When not provided, sensible defaults are used.

PropertyTypeDefaultDescription
methodsDiscoverMethodsConfig['platform', 'feed', 'html', 'headers', 'guess']Which methods to use
fetchFnFetchFnnative fetchCustom fetch function
enrichFnDiscoverEnrichFn | falsebuilt-in enrichersFinds icons that take an extra request to reach. See Enriching Platform Icons
extractFnDiscoverExtractFnimage checkCustom extraction function
resolveUrlFnDiscoverResolveUrlFnresolve relativeCustom URL resolution function
resolveSiteUrlFnDiscoverResolveSiteUrlFnsite link from feedResolves the site URL to scan when the input is a feed
stopOnFirstMethodbooleanfalseStop after the first method that finds a valid result
stopOnFirstResultbooleanfalseStop after first valid favicon
concurrencynumber3Max parallel validations
maxUrisnumber50Max total candidate URIs to fetch across all methods
includeInvalidbooleanfalseInclude invalid results
onProgressDiscoverOnProgressFnProgress callback
onStepDiscoverOnStepFnCalled when each stage of discovery starts and ends
onErrorDiscoverOnErrorFnCalled when fetching the input or the site URL fails. DiscoverOnErrorFn lists everything it reports

Return Value ​

Returns a promise that resolves to an array of results:

typescript
// Valid result
{
  url: 'https://example.com/favicon.ico',
  isValid: true,
  method: 'html',
}

// Invalid result (when includeInvalid: true)
{
  url: 'https://example.com/missing.png',
  isValid: false,
  error: Error, // Only set when the request or the extractor threw
  method: 'guess',
}

Each favicon URL appears once. When several candidates lead to the same favicon, for example /favicon.ico and /favicon.png both redirecting to one image, only the first is kept. The same applies to invalid results with includeInvalid.

Examples ​

Basic Usage ​

typescript
import { discoverFavicons } from 'feedscout'

// Simple usage - all methods enabled by default
const favicons = await discoverFavicons('https://example.com')

// Or specify which methods to use
const favicons = await discoverFavicons('https://example.com', {
  methods: ['html', 'headers', 'guess'],
})

With Custom Options ​

typescript
const favicons = await discoverFavicons('https://example.com', {
  methods: {
    guess: {
      uris: ['/favicon.ico', '/icon.svg'],
    },
  },
  stopOnFirstResult: true,
})