(normalizedUrl: string)
| 333 | } |
| 334 | |
| 335 | async function fetchHtmlTitle(normalizedUrl: string): Promise<string> { |
| 336 | const controller = new AbortController() |
| 337 | const timeout = setTimeout(() => controller.abort(), TITLE_TIMEOUT_MS) |
| 338 | |
| 339 | try { |
| 340 | const response = await fetch(normalizedUrl, { |
| 341 | headers: { |
| 342 | Accept: 'text/html,application/xhtml+xml;q=0.9,*/*;q=0.5', |
| 343 | 'Accept-Language': 'en-US,en;q=0.7', |
| 344 | 'User-Agent': TITLE_USER_AGENT |
| 345 | }, |
| 346 | redirect: 'follow', |
| 347 | signal: controller.signal |
| 348 | }) |
| 349 | |
| 350 | if (!response.ok) { |
| 351 | return '' |
| 352 | } |
| 353 | |
| 354 | const contentType = response.headers.get('content-type') |
| 355 | |
| 356 | if (contentType && !/(?:html|xml|text\/html)/i.test(contentType)) { |
| 357 | return '' |
| 358 | } |
| 359 | |
| 360 | const html = await readResponseSnippet(response) |
| 361 | |
| 362 | return parseHtmlTitle(html).slice(0, TITLE_MAX_LENGTH) |
| 363 | } catch { |
| 364 | return '' |
| 365 | } finally { |
| 366 | clearTimeout(timeout) |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | export function fetchLinkTitle(url: string): Promise<string> { |
| 371 | const normalizedUrl = normalizeExternalUrl(url) |
no test coverage detected