diff --git a/packages/cli/src/capture/faviconRanker.test.ts b/packages/cli/src/capture/faviconRanker.test.ts index 669bc015f..ecfd01538 100644 --- a/packages/cli/src/capture/faviconRanker.test.ts +++ b/packages/cli/src/capture/faviconRanker.test.ts @@ -108,6 +108,24 @@ describe("rankIconCandidates", () => { expect(hrefs([{ rel: "icon", href: "" }, ...NOTION])).toHaveLength(2); }); + it("scores apple-touch-icon-precomposed at the same 180px default as apple-touch-icon", () => { + // Precomposed is one token longer, not a different rel: it must win against a small + // sized png the same way a plain apple-touch-icon would. + const precomposed: IconCandidate[] = [ + { + rel: "apple-touch-icon-precomposed", + href: "https://x.test/apple-touch-icon-precomposed.png", + sizes: null, + type: null, + }, + { rel: "icon", href: "https://x.test/favicon-32.png", sizes: "32x32", type: "image/png" }, + ]; + expect(hrefs(precomposed)).toEqual([ + "https://x.test/apple-touch-icon-precomposed.png", + "https://x.test/favicon-32.png", + ]); + }); + it("keeps DOM order between candidates of equal rank", () => { const same: IconCandidate[] = [ { rel: "icon", href: "https://x.test/a.png", sizes: "32x32" }, diff --git a/packages/cli/src/capture/faviconRanker.ts b/packages/cli/src/capture/faviconRanker.ts index 424189783..c97460909 100644 --- a/packages/cli/src/capture/faviconRanker.ts +++ b/packages/cli/src/capture/faviconRanker.ts @@ -68,7 +68,15 @@ function isIco(c: IconCandidate): boolean { function declaredSize(c: IconCandidate): number { const parsed = parseSizes(c.sizes); if (parsed > 0) return parsed; - return c.rel.toLowerCase().split(/\s+/).includes("apple-touch-icon") ? APPLE_TOUCH_DEFAULT_PX : 0; + // `startsWith`, not an exact-token match: `apple-touch-icon-precomposed` is the same + // 180px default, one spelling later. Exact match is right for `mask-icon` (isMaskIcon), + // where a longer rel really would be a different asset. + return c.rel + .toLowerCase() + .split(/\s+/) + .some((t) => t.startsWith("apple-touch-icon")) + ? APPLE_TOUCH_DEFAULT_PX + : 0; } function tierOf(c: IconCandidate): number {