Skip to content

Commit adf84cb

Browse files
committed
fix: simulate real user agent
Otherwise websites might refuse the connection.
1 parent 8614aa1 commit adf84cb

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

services/metadata.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { lookup } from 'node:dns/promises'
1010

1111
const FETCH_TIMEOUT = 10000
1212
const MAX_BODY_SIZE = 2 * 1024 * 1024 // 2MB limit for HTML
13-
const USER_AGENT = 'Mozilla/5.0 (compatible; Hypermark/1.0; +https://hypermark.app)'
13+
const USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
1414

1515
// Cache: domain -> { result, expiresAt }
1616
const metadataCache = new Map()
@@ -169,7 +169,14 @@ async function fetchPage(url) {
169169
signal: controller.signal,
170170
headers: {
171171
'User-Agent': USER_AGENT,
172-
'Accept': 'text/html,application/xhtml+xml',
172+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
173+
'Accept-Language': 'en-US,en;q=0.9',
174+
'Accept-Encoding': 'gzip, deflate, br',
175+
'Cache-Control': 'no-cache',
176+
'Sec-Fetch-Dest': 'document',
177+
'Sec-Fetch-Mode': 'navigate',
178+
'Sec-Fetch-Site': 'none',
179+
'Sec-Fetch-User': '?1',
173180
},
174181
redirect: 'follow',
175182
})

0 commit comments

Comments
 (0)