Created
July 22, 2022 07:59
-
-
Save davidmaxwaterman/aa0368be171249ebe14e59e75468e04b to your computer and use it in GitHub Desktop.
fetch favicons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```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