Skip to content

Instantly share code, notes, and snippets.

@davidmaxwaterman
Created July 22, 2022 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidmaxwaterman/aa0368be171249ebe14e59e75468e04b to your computer and use it in GitHub Desktop.
Save davidmaxwaterman/aa0368be171249ebe14e59e75468e04b to your computer and use it in GitHub Desktop.
fetch favicons
```javascript
async function fetchIconUrls(url) {
console.info(`fetching icon for ${url} manually`);
const response = await fetch(url);
const text = await response.text();
const parser = new DOMParser();
const doc = parser.parseFromString(text, "text/html");
const iconLinks = doc.querySelectorAll("link[rel~=icon]");
const retVal = [...iconLinks].map(iconLink => {
const iconUrlString = iconLink.getAttribute("href");
const iconUrl = new URL(iconUrlString, url);
const iconHref = iconUrl.href;
return iconHref;
});
return retVal;
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment