diff --git a/ts/linkPreviews/linkPreviewFetch.ts b/ts/linkPreviews/linkPreviewFetch.ts
index 13c71cc84..785522094 100644
--- a/ts/linkPreviews/linkPreviewFetch.ts
+++ b/ts/linkPreviews/linkPreviewFetch.ts
@@ -354,9 +354,10 @@ const parseMetadata = (
const rawImageHref =
getOpenGraphContent(document, ['og:image', 'og:image:url']) ||
getLinkHrefAttribute(document, [
+ 'apple-touch-icon',
+ 'apple-touch-icon-precomposed',
'shortcut icon',
'icon',
- 'apple-touch-icon',
]);
const imageUrl = rawImageHref ? maybeParseUrl(rawImageHref, href) : null;
const imageHref = imageUrl ? imageUrl.href : null;
diff --git a/ts/test-electron/linkPreviews/linkPreviewFetch_test.ts b/ts/test-electron/linkPreviews/linkPreviewFetch_test.ts
index 55d375932..f266f29da 100644
--- a/ts/test-electron/linkPreviews/linkPreviewFetch_test.ts
+++ b/ts/test-electron/linkPreviews/linkPreviewFetch_test.ts
@@ -122,6 +122,68 @@ describe('link preview fetching', () => {
);
});
+ it('handles image href sources in the correct order', async () => {
+ const orderedImageHrefSources = [
+ {
+ tag:
+ '',
+ expectedHref: 'https://example.com/og-image.jpg',
+ },
+ {
+ tag:
+ '',
+ expectedHref: 'https://example.com/og-image-url.jpg',
+ },
+ {
+ tag:
+ '',
+ expectedHref: 'https://example.com/apple-touch-icon.jpg',
+ },
+ {
+ tag:
+ '',
+ expectedHref: 'https://example.com/apple-touch-icon-precomposed.jpg',
+ },
+ {
+ tag:
+ '',
+ expectedHref: 'https://example.com/shortcut-icon.jpg',
+ },
+ {
+ tag: '',
+ expectedHref: 'https://example.com/icon.jpg',
+ },
+ ];
+ for (let i = orderedImageHrefSources.length - 1; i >= 0; i -= 1) {
+ const imageTags = orderedImageHrefSources
+ .slice(i)
+ .map(({ tag }) => tag)
+ // Reverse the array to make sure that we're prioritizing properly,
+ // instead of just using whichever comes first.
+ .reverse();
+ const fakeFetch = stub().resolves(
+ makeResponse({
+ body: makeHtml([
+ '',
+ ...imageTags,
+ ]),
+ })
+ );
+
+ // eslint-disable-next-line no-await-in-loop
+ const val = await fetchLinkPreviewMetadata(
+ fakeFetch,
+ 'https://example.com',
+ new AbortController().signal
+ );
+ assert.propertyVal(
+ val,
+ 'imageHref',
+ orderedImageHrefSources[i].expectedHref
+ );
+ }
+ });
+
it('logs no warnings if everything goes smoothly', async () => {
const fakeFetch = stub().resolves(
makeResponse({