MCPcopy Create free account
hub / github.com/continuedev/continue / findFaviconPath

Function findFaviconPath

core/util/fetchFavicon.ts:3–31  ·  view source on GitHub ↗
(url: URL)

Source from the content-addressed store, hash-verified

1import { JSDOM } from "jsdom";
2
3export async function findFaviconPath(url: URL): Promise<string | undefined> {
4 const baseUrl = `${url.protocol}//${url.hostname}`;
5
6 try {
7 const response = await fetch(baseUrl);
8 if (!response.ok) {
9 throw new Error(`HTTP error! status: ${response.status}`);
10 }
11
12 const html = await response.text();
13 const dom = new JSDOM(html);
14 const document = dom.window.document;
15
16 // Look for favicon in <link> tags
17 const linkTags = document.querySelectorAll('link[rel*="icon"]');
18
19 for (const link of linkTags) {
20 const href = link.getAttribute("href");
21 if (href) {
22 return new URL(href, baseUrl).toString();
23 }
24 }
25 } catch (error) {
26 console.debug(`Failed to fetch favicon for ${baseUrl}: ${error}`);
27 }
28
29 console.debug(`Failed to find favicon for ${baseUrl}`);
30 return undefined;
31}
32
33export async function getFaviconBase64(
34 faviconUrl: string,

Callers 2

fetchFaviconFunction · 0.85

Calls 3

textMethod · 0.80
fetchFunction · 0.50
debugMethod · 0.45

Tested by

no test coverage detected