Get favicons from any website

Did you know that Google has a hidden API to get favicons from any domain?

Icon for: wikipedia.org Served dynamically from: https://www.google.com/s2/favicons?domain=wikipedia.org&sz=128

This is the Svelte code to simply display the image above:

<script>
	let domain = 'wikipedia.org';
	let size = 128;
	let src = `https://www.google.com/s2/favicons?domain=${domain}&sz=${size}`;
</script>

<img {src} alt="" />

If you want to play with how the API retrieves the favicons, I made a small playground:

No image to show yet
Icon for: Served dynamically from: https://www.google.com/s2/favicons?domain=&sz=128

Other similar services are Icon Horse (really good) and Favicon Grabber.

References