Resolve favicons through Google's s2 service
Pointing the renderer at the site's own `/favicon.ico` was producing GPUI image-cache errors on every other tab — notion.com redirected across origins, sites shipped multi-image `image/x-icon` blobs the PNG/WebP decoder couldn't read, hosts 404'd. Each one logged a noisy `ERROR gpui::asset_cache: Failed to load asset` line. Switch `UrlText::favicon_url` to `https://www.google.com/s2/favicons?domain=<host>&sz=64`. Google's endpoint normalises every response to PNG, follows redirects on its side, and serves a `_/` globe glyph for sites without a favicon at all — same URL shape every browser dev-tools panel already shows for "favicon" so the fetch is uniformly succeeding.
This commit is contained in:
@@ -72,18 +72,29 @@ impl UrlText {
|
|||||||
url.host_str().map(str::to_string).unwrap_or_else(|| self.value.clone())
|
url.host_str().map(str::to_string).unwrap_or_else(|| self.value.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve the canonical `/favicon.ico` URL for an HTTP(S) page.
|
/// Resolve a favicon URL for an HTTP(S) page. Returns `None` for
|
||||||
/// Returns `None` for non-web schemes (`ely://`, `file://`, etc.)
|
/// non-web schemes (`ely://`, `file://`, …) and for URLs missing
|
||||||
/// or URLs missing an authority — those tabs render the URL-derived
|
/// an authority — those tabs render the URL-derived glyph instead.
|
||||||
/// glyph instead of a fetched icon.
|
///
|
||||||
|
/// We deliberately do NOT point the renderer at the site's own
|
||||||
|
/// `/favicon.ico` because a) many sites only ship that icon as
|
||||||
|
/// a multi-image `image/x-icon` blob the renderer's PNG/WebP
|
||||||
|
/// decoder can't read, and b) the URL frequently 404s or
|
||||||
|
/// redirects across origins (notion.com → notion.so etc.) which
|
||||||
|
/// the GPUI image fetcher surfaces as a noisy `ERROR` log on
|
||||||
|
/// every tab. Instead we route through Google's `s2/favicons`
|
||||||
|
/// endpoint: it normalises the response to PNG, resolves
|
||||||
|
/// redirects on Google's side, and serves a `_/` globe glyph
|
||||||
|
/// when the target site has no favicon at all. Same URL shape
|
||||||
|
/// every browser dev-tools panel already shows for "favicon".
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn favicon_url(&self) -> Option<String> {
|
pub fn favicon_url(&self) -> Option<String> {
|
||||||
let url = Url::parse(&self.value).ok()?;
|
let url = Url::parse(&self.value).ok()?;
|
||||||
if !matches!(url.scheme(), "http" | "https") {
|
if !matches!(url.scheme(), "http" | "https") {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
url.host_str()?;
|
let host = url.host_str()?;
|
||||||
url.join("/favicon.ico").ok().map(|favicon| favicon.to_string())
|
Some(format!("https://www.google.com/s2/favicons?domain={host}&sz=64"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user