GoLang Library for Browser Capabilities Project

Overview

Browser Capabilities GoLang Project

PHP has get_browser() function which tells what the user's browser is capable of. You can check original documentation here. This is GoLang analog of get_browser() function.

Build Status

Introduction

The browscap.ini file is a database which provides a lot of details about browsers and their capabilities, such as name, versions, Javascript support and so on.

Quick start

First of all you need initialize library with browscap.ini file. And then you can get Browser information as Browser structure.

import (
	"fmt"
	bgo "github.com/digitalcrab/browscap_go"
)

func main() {
	if err := bgo.InitBrowsCap("browscap.ini", false); err != nil {
		panic(err)
	}
	
	browser, ok := bgo.GetBrowser("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36")
	if !ok || browser == nil {
    	panic("Browser not found")
	} else {
    	fmt.Printf("Browser = %s [%s] v%s\n", browser.Browser, browser.BrowserType, browser.BrowserVersion)
    	fmt.Printf("Platform = %s v%s\n", browser.Platform, browser.PlatformVersion)
    	fmt.Printf("Device = %s [%s] %s\n", browser.DeviceName, browser.DeviceType, browser.DeviceBrand)
    	fmt.Printf("IsCrawler = %t\n", browser.IsCrawler())
    	fmt.Printf("IsMobile = %t\n", browser.IsMobile())
	}
}

License

The MIT License (MIT)

Copyright (c) 2015 Maksim Naumov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Issues
  • Add an InitBrowsCapFromBuffer() function.

    Add an InitBrowsCapFromBuffer() function.

    Sometimes you might want to give browscap a file that doesn't live on the filesystem (say, for tests, or because you want to give it a compressed file). This commit lets you do that by passing in any buffered-file object, rather than requiring a filename.

    opened by csilvers 1
  • Wrong result with latest browscap.ini

    Wrong result with latest browscap.ini

    Hello, here is the sample code that gives wrong result on a latest ini file

    package main
    import (
        "fmt"
        bgo "github.com/digitalcrab/browscap_go"
    )
    func main() {
        if err := bgo.InitBrowsCap("browscap_min.ini", false); err != nil {
            panic(err)
        }
        browser, ok := bgo.GetBrowser("Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3")
        if !ok || browser == nil {
            panic("Browser not found")
        } else {
            fmt.Printf("Browser = %s [%s] v%s\n", browser.Browser, browser.BrowserType, browser.BrowserVersion)
            fmt.Printf("Platform = %s v%s\n", browser.Platform, browser.PlatformVersion)
            fmt.Printf("Device_Type = [%s]\n", browser.DeviceType)
            fmt.Printf("IsCrawler = %t\n", browser.IsCrawler())
            fmt.Printf("IsMobile = %t\n", browser.IsMobile())
        }
    }
    

    Device_Type = [Mobile Device] This is wrong The right is from - http://browscap.org/ua-lookup gives device_type - Tablet

    bug 
    opened by vadyus 1
  • Fast browser search with browser object cache

    Fast browser search with browser object cache

    We're using browscap in a real time application so the original application was too slow. In this pull request I rewrote a part of re0, added tree search for expressions, added browser object caching and added a couple of new attributes to the browser object.

    I also added two benchmark tests to compare performance. Initialization is around 30% slower because it has to build the search tree, but the GetBrowser function is 140 times faster.

    Speed and memory usage comparison:

    HEAD: BenchmarkInit-4 2 758992121 ns/op 165539440 B/op 2681838 allocs/op BenchmarkGetBrowser-4 200 8535325 ns/op 3250 B/op 15 allocs/op

    New version: BenchmarkInit-4 1 1163491977 ns/op 136829088 B/op 3190900 allocs/op BenchmarkGetBrowser-4 20000 62218 ns/op 32 B/op 1 allocs/op

    opened by hamaxx 1
  • use DeviceCodeName for code name and DeviceName for name

    use DeviceCodeName for code name and DeviceName for name

    they are actually pretty different in some cases and both have useful information.

    typical example: Device_Name="Galaxy S5 LTE" Device_Code_Name="SM-G900F"

    opened by tony2001 0
  • Fix in tree search rule prioritization

    Fix in tree search rule prioritization

    Fixes https://github.com/digitalcrab/browscap_go/issues/4

    I also updated test-data with the newest version of rules so I was able to write a test for the reported issue.

    Sorry I didn't see the issue earlier.

    opened by hamaxx 0
  • Properly implement the browscap matching algorithm.

    Properly implement the browscap matching algorithm.

    https://github.com/browscap/browscap/wiki/Specification:-Lookup-Algorithm says:

    If there are multiple matching patterns the longest pattern should be used to identify the browser. If there are multiple patterns of the longest length then the pattern that is earliest in the list of patterns should be used to identify the browser.

    The old code, as far as I can tell -- which isn't very far, to be fair -- always picked the earliest in the list of patterns, regardless of length. I did the minimal changes to implement the algorithm as specified. This possibly saved some space in the bargain, as I lowered the space required for scores from 64 bits to 32.

    I added a test-case that failed with the old code but passes with the new. It requires an up-to-date browscap.ini file, so I updated the one in test-data as part of this diff.

    opened by csilvers 0
  • Prefer `Device_Name` to `Device_Code_Name` for browser.DeviceName.

    Prefer `Device_Name` to `Device_Code_Name` for browser.DeviceName.

    Before, it was only looking at Device_Code_Name. But Device_Name is a separate field that sometimes has a different value than Device_Code_Name. This change makes it so we prefer the former to the latter.

    This is an API-breaking change, but I think it's the right thing to do based on my (admittedly scant) understanding of these ini fields.

    opened by csilvers 1
  • Firefox version incorrect detection

    Firefox version incorrect detection

    UA: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0

    ini version

    [GJK_Browscap_Version]
    Version=6000031
    Released=Thu, 29 Nov 2018 08:50:14 +0000
    Format=php
    Type=FULL
    

    result

    Browser = Firefox [Browser] v0.0
    Platform = Win8.1 v6.3
    Device = Windows Desktop [Desktop] unknown
    IsCrawler = false
    IsMobile = false
    

    browscap result

    browser_name_regex | /^mozilla\/5\.0 \(.*windows nt 6\.3.*win64. x64.*\) gecko.* firefox\/56\.0.*$/
    browser_name_pattern | mozilla/5.0 (*windows nt 6.3*win64? x64*) gecko* firefox/56.0*
    parent | Firefox 56.0
    comment | Firefox 56.0
    browser | Firefox
    browser_type | Browser
    browser_bits | 64
    browser_maker | Mozilla Foundation
    browser_modus | unknown
    version | 56.0
    majorver | 56
    
    opened by kvspb 0
  • Fix for the issue with scoring and some minor optimizations and fixes

    Fix for the issue with scoring and some minor optimizations and fixes

    This pull request fixes https://github.com/digitalcrab/browscap_go/issues/6 and fixes https://github.com/digitalcrab/browscap_go/issues/8

    Unfortunately I didn't notice the issues earlier because it wasn't an issue with older versions of browscap data. I used to score lines by length but switched to line number because some crawlers weren't detected correctly in old versions of data if I did it with the rule length so I just assumed that the order of lines is the correct logic.

    Plus some minor optimizations and fixes.

    opened by hamaxx 0
  • Allow library to be initialized with a reader

    Allow library to be initialized with a reader

    • Add an option to initialize the browscap library with a Reader, instead of strictly from an .ini file. (We needed this option as we used an embedded asset for browscap.ini via go-bindata.)
    • Add test for initializing from Reader.
    • Improve current tests, which rely on a particular order of execution in order to pass; namely, they assume that the library has been initialized first. This change ensures that the tests still pass when run individually.
    opened by elynnyap 0
Owner
Maksim N.
Engineer. Kart Racer. Digital Settler.
Maksim N.
Host yo' self from your browser, your phone, your toaster.

A hosting service from the browser, because why not. Try it at hostyoself.com. See it in action Here's an example where I use hostyoself.com to host i

Zack 1.7k Jun 28, 2022
Shows your recent browser history in tree style. 树状展示浏览器历史 (For Edge / Chromium / Chrome)

Tree Style Histyle This extension shows your recent browser history in tree style. When you browser pages from internet, you always jump from one page

null 123 Jun 23, 2022
An OBS overlay (browser source) for mumble

Mumble UI An attempt at creating an overlay that could be used inside of OBS to show who is speaking for the DAY[0] Podcast. It is meant to be reasona

DAY[0] 1 Jan 27, 2022
Purpose: dump slack messages, users and files using browser token and cookie.

Slack Dumper Purpose: dump slack messages, users and files using browser token and cookie. Typical usecase scenarios: You want to archive your private

Rustam 130 Jun 24, 2022
Alfred 4 workflow to easily search and launch bookmarks from the Brave Browser

Alfred Brave Browser Bookmarks A simple and fast workflow for searching and launching Brave Browser bookmarks. Why this workflow? No python dependency

Josh Newman 5 Apr 17, 2022
Moby Project - a collaborative project for the container ecosystem to assemble container-based systems

The Moby Project Moby is an open-source project created by Docker to enable and accelerate software containerization. It provides a "Lego set" of tool

Moby 63.4k Jun 24, 2022
Placeholder for the future project (lets-go-chat)Placeholder for the future project (lets-go-chat)

Placeholder for the future project (lets-go-chat)Placeholder for the future project (lets-go-chat)

null 0 Jan 10, 2022
Golang-module-references - A reference for how to setup a Golang project with modules - Task Management + Math Examples

Golang Module Project The purpose of this project is to act as a reference for setting up future Golang projects using modules. This project has a mat

Bob Bass 0 Jan 2, 2022
:guardsman: A teeny tiny and somewhat opinionated generator for your next golang project

A Yeoman Golang Generator We are very sorry Gophers, but other names for the generator where taken, so we choose go-lang. But we have gocreate as an a

Axel Springer SE 24 Jun 17, 2022
A sample golang project to demonstrate the integration with rancher pipeline

pipeline-example-go This is a sample golang project to demonstrate the integration with rancher pipeline. Building go build -o ./bin/hello-server Runn

null 0 Oct 30, 2021
A simple and sussy project is an implementation of SOMMIP Lab 1 written in Golang

SOMMIP Lab 1 Isac Arthur Table of Contents About The Project Getting Started Prerequisites Installation Supported commands About The Project This very

Arthur 1 Nov 10, 2021
Golang api for a league of legends teamfinder project

League teamfinder API Golang api for a league of legends teamfinder project Table of Contents League teamfinder API Table of Contents Introduction Get

Alberto García 0 Nov 9, 2021
Cookiecutter for golang project

cookiecutter-golang Powered by Cookiecutter, Cookiecutter Golang is a framework for jumpstarting production-ready go projects quickly. Features Genero

Flip.id 0 Nov 18, 2021
The official golang implementation for Project Anatha.

Project Anatha The official golang implementation for Project Anatha. For instructions on setting up a validator on the Anatha network, view the guide

潘毅 0 Nov 25, 2021
Eh-godojo-1 - A Golang Dojo throwaway project

creates a go mod file out of git repo & provides a path to our projects like pac

Loran 1 Jan 25, 2022
In one particular project, i had to import some key/value data to Prometheus. So i have decided to create my custom-built Node Exporter in Golang.

In one particular project, i had to import some key/value data to Prometheus. So i have decided to create my custom-built Node Exporter in Golang.

Hamid Hosseinzadeh 1 May 19, 2022
Test-project - Lyrid Golang 1.x Chi Template

Lyrid Golang 1.x Chi Template Run locally with: go get go run ./main.go Open ht

pensilpatah 0 Jan 31, 2022
A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture

A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture

Nyoman Frastyawan 1 Mar 2, 2022
A small project for a simple chatroom using golang.

chatroom_go A small project for a simple chatroom using golang. 项目编码流程的设计分析 通讯逻辑示意图 客户端部分 客户端登录功能 1.接收的输入id和密码 2.接收服务端的返回结果 3.判断是成功还是失败,并显示对应的页面 客户端发送

Ripple 1 Mar 22, 2022