Skip to content

Commit 172598b

Browse files
Fix link previews for YouTube Music
1 parent 0a35489 commit 172598b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

ts/linkPreviews/linkPreviewFetch.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Signal Messenger, LLC
1+
// Copyright 2020-2021 Signal Messenger, LLC
22
// SPDX-License-Identifier: AGPL-3.0-only
33

44
import { RequestInit, Response } from 'node-fetch';
@@ -13,6 +13,8 @@ import {
1313
MIMEType,
1414
} from '../types/MIME';
1515

16+
const USER_AGENT = 'WhatsApp/2';
17+
1618
const MAX_REQUEST_COUNT_WITH_REDIRECTS = 20;
1719

1820
// Lifted from the `fetch` spec [here][0].
@@ -408,7 +410,7 @@ export async function fetchLinkPreviewMetadata(
408410
response = await fetchWithRedirects(fetchFn, href, {
409411
headers: {
410412
Accept: 'text/html,application/xhtml+xml',
411-
'User-Agent': 'WhatsApp',
413+
'User-Agent': USER_AGENT,
412414
},
413415
signal: abortSignal,
414416
});
@@ -504,7 +506,7 @@ export async function fetchLinkPreviewImage(
504506
try {
505507
response = await fetchWithRedirects(fetchFn, href, {
506508
headers: {
507-
'User-Agent': 'WhatsApp',
509+
'User-Agent': USER_AGENT,
508510
},
509511
size: MAX_IMAGE_CONTENT_LENGTH,
510512
signal: abortSignal,

ts/test-electron/linkPreviews/linkPreviewFetch_test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Signal Messenger, LLC
1+
// Copyright 2020-2021 Signal Messenger, LLC
22
// SPDX-License-Identifier: AGPL-3.0-only
33

44
import { assert } from 'chai';
@@ -143,7 +143,7 @@ describe('link preview fetching', () => {
143143
sinon.assert.notCalled(warn);
144144
});
145145

146-
it('sends "WhatsApp" as the User-Agent for compatibility', async () => {
146+
it('sends WhatsApp as the User-Agent for compatibility', async () => {
147147
const fakeFetch = stub().resolves(makeResponse());
148148

149149
await fetchLinkPreviewMetadata(
@@ -157,7 +157,7 @@ describe('link preview fetching', () => {
157157
'https://example.com',
158158
sinon.match({
159159
headers: {
160-
'User-Agent': 'WhatsApp',
160+
'User-Agent': 'WhatsApp/2',
161161
},
162162
})
163163
);
@@ -1273,7 +1273,7 @@ describe('link preview fetching', () => {
12731273
);
12741274
});
12751275

1276-
it('sends "WhatsApp" as the User-Agent for compatibility', async () => {
1276+
it('sends WhatsApp as the User-Agent for compatibility', async () => {
12771277
const fakeFetch = stub().resolves(new Response(null));
12781278

12791279
await fetchLinkPreviewImage(
@@ -1287,7 +1287,7 @@ describe('link preview fetching', () => {
12871287
'https://example.com/img',
12881288
sinon.match({
12891289
headers: {
1290-
'User-Agent': 'WhatsApp',
1290+
'User-Agent': 'WhatsApp/2',
12911291
},
12921292
})
12931293
);

0 commit comments

Comments
 (0)