diff --git a/src/applinks.js b/src/applinks.js index 0c4ba2c01..53098b34f 100644 --- a/src/applinks.js +++ b/src/applinks.js @@ -107,16 +107,23 @@ async function detectMetaInfo(applink) { if (!favicon.endsWith('.png') && dom.window.document.querySelector('meta[itemprop="image"]')) favicon = dom.window.document.querySelector('meta[itemprop="image"]').content; if (favicon) { - if (favicon.startsWith('/')) favicon = (redirectUri || applink.upstreamUri) + favicon; + favicon = new URL(favicon, redirectUri || applink.upstreamUri).toString(); debug(`detectMetaInfo: found icon: ${favicon}`); const [error, response] = await safe(superagent.get(favicon)); if (error) debug(`Failed to fetch icon ${favicon}: `, error); - else if (response.ok && response.headers['content-type'] === 'image/png') applink.icon = response.body; + else if (response.ok) applink.icon = response.body; + else debug(`Failed to fetch icon ${favicon}: statusCode=${response.status}`); + } + + if (!favicon) { + debug(`Unable to find a suitable icon for ${applink.upstreamUri}, try fallback favicon.ico`); + + const [error, response] = await safe(superagent.get(applink.upstreamUri + '/favicon.ico')); + if (error) debug(`Failed to fetch icon ${favicon}: `, error); + else if (response.ok) applink.icon = response.body; else debug(`Failed to fetch icon ${favicon}: statusCode=${response.status}`); - } else { - debug(`Unable to find a suitable icon for ${applink.upstreamUri}`); } }