Skip to content

Latest commit

 

History

History
61 lines (50 loc) · 2.45 KB

README.md

File metadata and controls

61 lines (50 loc) · 2.45 KB

browser-capabilities

A Go Module that detects Browser capabilities and Client type from a user agent string.

The following keywords are supported. See main.ts for the latest browser support matrix.

Inspired by https://www.npmjs.com/package/browser-capabilities NodeJS package.

🎯 Features

Browser Capabilities

Keyword Description
push HTTP/2 Server Push
serviceworker Service Worker API
modules JavaScript Modules (including dynamic import() and import.meta)
es2015 ECMAScript 2015 (aka ES6)
es2016 ECMAScript 2016
es2017 ECMAScript 2017
es2018 ECMAScript 2018

Client Information

type Client struct {
    Browser        string // type: "firefox" | "edge" | "chrome" | "facebook" | "google_app" | "ie" | "safari" | "safari_mobile" | "other" | "vivaldi"
    BrowserVersion float64
    IsMobile       bool
    OS             string // type: "ios" | "android" | "linux" | "mac" | "windows" | "playstation" | "other"
    OSVersion      float64
}

⚡️ Quickstart

package main

import (
    "fmt"
    "github.com/herberthobregon/go-browser-capabilities"
)

func main() {
    // CheckES5
    ua := "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
    capabilities := browser_capabilities.BrowserCapabilities(ua)
    client := browser_capabilities.GetClient(ua)
    if capabilities["es2015"] || client.Browser == "other" {
        fmt.Println("success ✅")
    } else {
        fmt.Println("Please use Google Chrome > 54 ❌")
    }
}

⚙️ Installation

Make sure you have Go installed download. Version 1.14 or higher is required.

Initialize your project by creating a folder and then running go mod init github.com/your/repo learn more inside the folder. Then install Fiber with the go get command:

go get -u github.com/herberthobregon/go-browser-capabilities