MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / fetchHtmlTitle

Function fetchHtmlTitle

ui-tui/src/lib/externalLink.ts:335–368  ·  view source on GitHub ↗
(normalizedUrl: string)

Source from the content-addressed store, hash-verified

333}
334
335async 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
370export function fetchLinkTitle(url: string): Promise<string> {
371 const normalizedUrl = normalizeExternalUrl(url)

Callers 1

fetchLinkTitleFunction · 0.85

Calls 4

abortMethod · 0.95
readResponseSnippetFunction · 0.85
parseHtmlTitleFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected