October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
CORS

How to Fetch a Website Favicon from Any URL

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To fetch a website’s favicon, first read the page’s HTML and find its declared icon links, resolve each link against the page URL, then fetch the best usable candidate. If the page declares none or its icons fail, try the conventional /favicon.ico path at the site’s origin. For arbitrary third-party URLs, do this on a server: browser JavaScript cannot read cross-origin responses unless the target permits it with CORS.

Where a website’s favicon is declared

The most reliable starting point is the page’s <head>. Look for <link> elements whose space-separated rel value includes an icon relationship. Common values include icon, shortcut icon, apple-touch-icon, and apple-touch-icon-precomposed. The standard relationship for a page icon is rel="icon"; Google’s example is <link rel="icon" href="/path/to/favicon.ico"> (Google Search Central; MDN rel reference).

Do not assume the file is named favicon.ico, sits beside the page, or is hosted on the same domain. An href can be a relative path, an absolute URL, or a CDN URL. A root-relative path such as /icons/site.png resolves from the host root; a path such as icons/site.png resolves relative to the document URL. Resolve it with URL rules before making the icon request.

Fetch from a URL: the reliable sequence

  1. Validate the input. Parse it as a URL and accept only http: or https:. Reject malformed input and other schemes.
  2. Fetch the HTML. Request the page with a timeout and a maximum response size. Prefer a server-side request when the page belongs to another origin.
  3. Parse icon links. Inspect the document’s link elements and tokenize rel on whitespace; do not compare the full attribute to one exact string.
  4. Resolve and assess candidates. Resolve each non-empty href against the final page URL. Consider the declared sizes, type, and media hints.
  5. Fetch and validate the selected icon. Follow only a bounded number of redirects. Check the HTTP status, response size, media type, and that the bytes can actually be decoded as an image.
  6. Try the conventional fallback if needed. If no declared candidate is usable, request /favicon.ico resolved against the page URL’s origin.
  7. Cache a successful result. Choose a cache duration that fits your application and document it; there is no universal duration prescribed by the standards.

The HTML Standard says a user agent may fetch the URL formed by resolving /favicon.ico against an HTTP or HTTPS document when no icon link is declared. That makes the root file a sensible fallback, not a guarantee that an icon exists (WHATWG HTML Standard; MDN link reference).

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty

Choose among multiple icon candidates

A site may declare several icons for different devices, sizes, formats, or display conditions. Browsers use media, type, and sizes as hints when choosing. For an application, use a documented ranking policy rather than assuming the first link is best.

  • Discard links with a missing, empty, or malformed href.
  • Tokenize rel and accept the icon relationships your application supports.
  • Check whether the candidate’s media condition matches the intended environment.
  • Prefer a format the consuming application supports, using the declared type as a hint rather than proof of the response format.
  • When a requested display size is known, prefer a candidate at least that large; otherwise choose an appropriate available size. Parse sizes rather than treating it as a single guaranteed dimension.
  • Fetch candidates in ranked order and fall through if a candidate returns an error or invalid image bytes.

There is no universal ranking algorithm for every consumer. A browser tab, a mobile home-screen icon, and a 16-pixel list avatar can have different needs. Treat SVG support explicitly: it preserves vector artwork, but some downstream consumers require raster images. If raster output is required, convert only after choosing and validating an appropriate source.

Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]

JavaScript implementation: discover a candidate URL

This browser-side example parses a page you are already allowed to read. It does not bypass CORS and returns a candidate URL rather than fetching and validating the image bytes. It intentionally leaves format support, media matching, size ranking, network limits, and validation policy to the application.

function findFaviconUrl(documentObject, pageUrl) {
  const page = new URL(pageUrl);
  if (page.protocol !== "http:" && page.protocol !== "https:") {
    throw new Error("Only HTTP(S) page URLs are supported");
  }

  const accepted = new Set([
    "icon",
    "shortcut",
    "apple-touch-icon",
    "apple-touch-icon-precomposed"
  ]);

  for (const link of documentObject.querySelectorAll("link[href]")) {
    const relTokens = (link.getAttribute("rel") || "")
      .toLowerCase()
      .split(/s+/)
      .filter(Boolean);

    if (!relTokens.some(token => accepted.has(token))) continue;

    const href = link.getAttribute("href");
    if (!href || !href.trim()) continue;

    try {
      return new URL(href, page).href;
    } catch {
      // Ignore malformed href values and continue to the next candidate.
    }
  }

  return new URL("/favicon.ico", page).href;
}

// For the current page only:
const candidate = findFaviconUrl(document, window.location.href);
console.log(candidate);

This simple example returns the first usable declared URL; it is not a complete selector for a production service. Add explicit candidate ranking and image-fetch validation when those properties matter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers

Why browser fetches fail across origins

A page’s JavaScript can read a cross-origin fetch() response only when the target server sends CORS headers that allow the request. Setting mode: "no-cors" does not make the response readable: it produces an opaque response that JavaScript cannot inspect. That is unsuitable when you need to parse another site’s HTML or examine its image bytes (MDN Fetch metadata).

For arbitrary URLs, fetch and parse on your own server or through a controlled same-origin proxy. This avoids relying on the target site to enable browser access, but it introduces server-side request forgery (SSRF) risk: an untrusted URL might point at internal services or sensitive network addresses. Apply network controls, revalidate destinations after redirects, cap redirects and bytes, and use timeouts. A same-origin proxy needs the same protections; it is not safe merely because the browser calls your domain.

Rank #4
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.

Server-side implementation checklist

  • Parse and normalize the input URL; permit HTTP and HTTPS only.
  • Set a request timeout and enforce HTML and icon byte limits before buffering the full response.
  • Limit redirects and re-check the final destination against your SSRF policy.
  • Parse HTML with an HTML parser, not a regular expression.
  • Resolve icon paths against the page URL after redirects, so relative links use the final document address.
  • Check status, content type, and image decodability. A successful HTTP status alone does not establish that the body is an icon.
  • Make SVG handling an explicit consumer decision.
  • Return a documented “not found” or null result when declared links and the root fallback fail. Do not silently substitute an unrelated logo.
  • Cache validated successes to reduce repeated origin requests. Set a deliberate cache lifetime; standards do not prescribe one.

HTML-declared icon or root fallback?

Method Strength Trade-off
Read a declared icon link Uses the page’s explicit choice, including a custom path, CDN, or format. Requires fetching and parsing HTML; there may be several candidates or a broken declaration.
Request /favicon.ico Simple conventional fallback when the document declares no usable icon. May not exist or may not be the icon the page uses; requires an additional request after discovery fails.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

  • The browser reports a CORS error: the target does not permit your page to read its response. Fetch from a protected server-side component instead; no-cors will not make response bytes available.
  • The result is a 404 or missing icon: the declared path may be stale, or the root fallback may not exist. Try remaining valid declared candidates before returning a documented no-icon result.
  • The URL looks relative or points to the wrong place: resolve the raw href against the page URL with a URL parser. Do not concatenate strings or assume the icon shares the page’s directory.
  • The response is HTML instead of an image: the server may have returned an error page, challenge, or redirect destination. Check status, final URL, content type, and decodability before accepting it.
  • The server request hangs or downloads too much: enforce timeouts and response-byte limits, stop reading after the limit, and cap redirects.
  • A URL fetch reaches a private or unexpected host: reject destinations outside your SSRF policy and revalidate after every redirect. Do not let user-controlled URLs reach internal network resources.
  • An SVG works in one consumer but not another: make SVG acceptance explicit. Preserve the original when supported; otherwise rasterize through a controlled image pipeline.

Or skip the browser setup

If what you need is a clean screenshot of the page rather than the favicon file itself, ScreenshotNeo is a website screenshot API and MCP server for developers. Its capture options can accept cookie banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; those steps can each be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, with verdict and billing information in response headers. AI agents can use its MCP server tools, including take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

For example, this cURL request saves a screenshot of a page as WebP:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for the request options. Sign up for 1,000 free screenshots a month, with no card required.

Best Value
Sale
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.

Does Google show every fetched favicon?

No. Successfully discovering and fetching an icon is separate from whether a search engine displays it. Google states that “A favicon isn’t guaranteed to appear in Google Search results, even if all guidelines are met” (Google Search Central).

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.