Skip to content

Instantly share code, notes, and snippets.

@colebemis
Last active July 18, 2023 02:33
Show Gist options
  • Save colebemis/ea94c313118104d5033004ba1956df7d to your computer and use it in GitHub Desktop.
Save colebemis/ea94c313118104d5033004ba1956df7d to your computer and use it in GitHub Desktop.
source

Get a website's title

async function getTitle(url) {  
  const response = await fetch(`https://api.allorigins.win/get?url=${encodeURIComponent(url)}`)
  const { contents } = await response.json()
  const title = contents.match(/<title>(?<title>.*)<\/title>/)?.groups?.title ?? ''
  return title
}

#snippet #lumen/app #javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment