MCPcopy Index your code
hub / github.com/dineshgowda24/browser

github.com/dineshgowda24/browser @v1.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.0 ↗ · + Follow
888 symbols 3,422 edges 164 files 170 documented · 19% updated 2y agov1.1.0 · 2024-05-18★ 892 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

browser MIT Go Reference Go report card Build Status Coverage X

Why?

Why not?

You need to detect the browser, device and platform from the user agent string in many use cases. I have personally come across the following use cases:

  1. You want to render different HTML for different browsers, devices or platforms.
  2. You want to render OG tags for scraping bots and social media sites.
  3. You want to log the browser, device or platform for your analytics.
  4. You want your backend to behave differently when a Google bot crawls your site for SEO.

I wanted a relatively extensible package that I could use in all the above use cases. So, I decided to write this package.

Inspiration

The ruby gem fnando/browser inspires this package. I have used the gem in some of my previous projects and liked it. All the credit goes to the author of the ruby gem, who has done a great job.

Documentation

For detailed documentation visit browser.dineshgowda.com. It has adoption guides, usage, contributing guidelines and also the list of all the matchers and browsers supported.

Usage

go get github.com/dineshgowda24/browser

Browser Detection

b, err := browser.NewBrowser("Mozilla/5.0 (Linux; Android 10; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36")
 if err != nil {
  // handle error
 }

 // browser level information
 fmt.Println(b.Name())           // Chrome
 fmt.Println(b.Version())        // 90.0.4430.210
 fmt.Println(b.ShortVersion())   // 90
 fmt.Println(b.IsBrowserKnown()) // true
 fmt.Println(b.IsChrome())       // true

 // device level information
 fmt.Println(b.Device().Name())      // Samsung SM-A205U
 fmt.Println(b.Device().IsTablet())  // false
 fmt.Println(b.Device().IsSamsung()) // true

 // platform level information
 fmt.Println(b.Platform().Name())         // Android
 fmt.Println(b.Platform().Version())      // 10
 fmt.Println(b.Platform().IsAndroidApp()) // false

 // bot level information
 fmt.Println(b.Bot().Name())  // ""
 fmt.Println(b.Bot().IsBot()) // false

Bot Detection

b, err := browser.NewBrowser("APIs-Google (https://developers.google.com/webmasters/APIs-Google.html)")
if err != nil {
   // handle error
}

// browser level information
fmt.Println(b.Name())           // Unknown Browser
fmt.Println(b.Version())        // 0.0
fmt.Println(b.ShortVersion())   // 0
fmt.Println(b.IsBrowserKnown()) // false
fmt.Println(b.IsUnknown())      // true

// bot level information
fmt.Println(b.Bot().Name())  // "APIs-Google"
fmt.Println(b.Bot().IsBot()) // true
fmt.Println(b.Bot().Why())   // *bots.Known

Contributing

If you want to contribute to this project, please read the CONTRIBUTING.md file.

Issues

If you find any issues with this package, please raise an issue. I will fix it as soon as possible. Please read the Contributing section if you want to resolve the issue and contribute.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 466
Method 333
Struct 81
Interface 8

Languages

Go100%

Modules by API surface

browser.go52 symbols
browser_test.go46 symbols
platform.go36 symbols
device.go34 symbols
platform_test.go29 symbols
device_test.go23 symbols
bot.go10 symbols
platforms/parser.go9 symbols
matchers/parser.go9 symbols
matchers/internet_explorer.go8 symbols
devices/parser.go7 symbols
platforms/ios.go6 symbols

For agents

$ claude mcp add browser \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page