Skip to content

Instantly share code, notes, and snippets.

@arnoclr
Created May 18, 2022 12:58
Show Gist options
  • Save arnoclr/715cb08f6f37be98ddb69e46fbe0aaff to your computer and use it in GitHub Desktop.
Save arnoclr/715cb08f6f37be98ddb69e46fbe0aaff to your computer and use it in GitHub Desktop.
Get browser name based on user agent JS (cloudflare workers)
const agent = request.headers.get('User-Agent') || ''
const browser =
agent.includes('Firefox/') ? 'firefox'
: agent.includes('Edg/') ? 'edge'
: agent.includes('Vivaldi/') ? 'vivaldi'
: agent.includes('Brave') ? 'brave'
: agent.includes('Chrome/') ? 'chrome'
: agent.includes('Safari/') ? 'safari'
: agent.includes('OPR/') ? 'opera'
: 'other';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment