browser

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: LGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package browser implements the Browser client parser.

Index

Constants

This section is empty.

Variables

View Source
var AvailableBrowsers = map[string]string{}/* 712 elements not displayed */
View Source
var AvailableEngines = []string{
	"Arachne",
	"ArkWeb",
	"Blink",
	"Clecko",
	"Dillo",
	"Edge",
	"EkiohFlow",
	"Elektra",
	"Gecko",
	"Goanna",
	"KHTML",
	"LibWeb",
	"Maple",
	"NetFront",
	"NetSurf",
	"Presto",
	"Servo",
	"Text-based",
	"Trident",
	"WebKit",
	"iCab",
}
View Source
var BrowserFamilies = map[string][]string{
	"Amiga":              {"AV", "AW"},
	"Android Browser":    {"AN"},
	"Baidu":              {"BD", "BS", "H6"},
	"BlackBerry Browser": {"BB"},
	"Chrome":             {"CH", "2B", "7S", "A0", "AC", "A4", "AE", "AH", "AI", "AO", "AS", "BA", "BM", "BR", "C2", "C3", "C5", "C4", "C6", "CC", "CD", "CE", "CF", "CG", "1B", "CI", "CL", "CM", "CN", "CP", "CR", "CV", "CW", "DA", "DD", "DG", "DR", "EC", "EE", "EU", "EW", "FA", "FS", "GB", "GI", "H2", "HA", "HE", "HH", "HS", "I3", "IR", "JB", "KN", "KW", "LF", "LL", "LO", "M1", "MA", "MD", "MR", "MS", "MT", "MZ", "NM", "NR", "O0", "O2", "O3", "OC", "PB", "PT", "QU", "QW", "RM", "S4", "S6", "S8", "S9", "SB", "SG", "SS", "SU", "SV", "SW", "SY", "SZ", "T1", "TA", "TB", "TG", "TR", "TS", "TU", "TV", "UB", "UR", "VE", "VG", "VI", "VM", "WP", "WH", "XV", "YJ", "FH", "H8", "B1", "BO", "HB", "PC", "LA", "LT", "PD", "HR", "HU", "HP", "IO", "TP", "CJ", "HQ", "HI", "PN", "BW", "YO", "DC", "G8", "DT", "AP", "AK", "UI", "SD", "VN", "4S", "2S", "RF", "LR", "SQ", "BV", "L1", "F0", "KS", "V0", "C8", "AZ", "MM", "BT", "N0", "P0", "F3", "VS", "DU", "D0", "P1", "O4", "8S", "H3", "TE", "WB", "K1", "P2", "XO", "U0", "B0", "VA", "X0", "NX", "O5", "R1", "I1", "HO", "A5", "X1", "18", "B5", "B6", "TC", "A6", "2X", "F4", "YG", "WR", "NA", "DM", "1M", "A7", "XN", "XT", "XB", "W1", "HT", "B8", "F5", "B9", "WA", "T0", "HC", "O6", "P7", "LJ", "LC", "O7", "N2", "A8", "P8", "RB", "1W", "EV", "I9", "V4", "H4", "1T", "M5", "0S", "0C", "ZR", "D6", "F6", "RC", "WD", "P3", "FT", "A9", "X2", "N3", "GD", "O9", "Q3", "F7", "K2", "P5", "H5", "V3", "K3", "Q4", "G2", "R2", "WX", "XP", "3I", "BG", "R0", "JO", "OL", "GN", "W4", "QI", "E1", "RI", "8B", "5B", "K4", "WK", "T3", "K5", "MU", "9P", "K6", "VR", "N9", "M9", "F9", "0P", "0A", "JR", "D3", "TK", "BP", "2F", "2M", "K7", "1N", "8A", "H7", "X3", "T4", "X4", "5O", "8C", "3M", "6I", "2P", "PU", "7I", "X5", "AL", "3P", "W2", "ZB", "HN", "Q6", "Q7", "G0", "00", "R6", "D8", "PQ", "LM", "T5", "2N", "SJ", "X6", "SM", "AY", "BQ", "BC", "NQ", "VQ", "9C", "KA", "YS", "D4", "PZ", "0I", "3F", "Z1", "XC", "ZC"},
	"Firefox":            {"FF", "BI", "BF", "BH", "BN", "C0", "CU", "EI", "F1", "FB", "FE", "AX", "FM", "FR", "FY", "I4", "IF", "8P", "IW", "LH", "LY", "MB", "MN", "MO", "MY", "OA", "OS", "PI", "PX", "QA", "S5", "SX", "TF", "TO", "WF", "ZV", "FP", "AD", "2I", "P9", "KJ", "WY", "VK", "W5", "7C", "N7", "W7"},
	"Internet Explorer":  {"IE", "CZ", "BZ", "IM", "PS", "3A", "4A", "RN", "2E"},
	"Konqueror":          {"KO"},
	"NetFront":           {"NF", "3N"},
	"NetSurf":            {"NE"},
	"Nokia Browser":      {"NB", "DO", "NO", "NV"},
	"Opera":              {"OP", "OG", "OH", "OI", "OM", "ON", "OO", "O1", "OX", "Y1", "6O"},
	"Safari":             {"SF", "S7", "MF", "SO", "PV"},
	"Sailfish Browser":   {"SA"},
}
View Source
var ClientHintMapping = map[string][]string{
	"Chrome":                     {"Google Chrome"},
	"Chrome Webview":             {"Android WebView"},
	"DuckDuckGo Privacy Browser": {"DuckDuckGo"},
	"Edge WebView":               {"Microsoft Edge WebView2"},
	"Mi Browser":                 {"Miui Browser", "XiaoMiBrowser"},
	"Microsoft Edge":             {"Edge"},
	"Norton Private Browser":     {"Norton Secure Browser"},
	"Opera GX":                   {"Opera GX Android"},
	"Opera Mini":                 {"Opera Mini Android"},
	"Vewd Browser":               {"Vewd Core"},
	"Yandex Browser":             {"YaSearchBrowser"},
}
View Source
var MobileOnlyBrowsers = []string{}/* 226 elements not displayed */

Functions

func GetAvailableBrowserFamilies

func GetAvailableBrowserFamilies() map[string][]string

GetAvailableBrowserFamilies returns all available browser families.

func GetAvailableBrowsers

func GetAvailableBrowsers() map[string]string

GetAvailableBrowsers returns all available browsers.

func GetAvailableEngines

func GetAvailableEngines() []string

GetAvailableEngines returns all available browser engines.

func GetBrowserFamily

func GetBrowserFamily(browserLabel string) string

GetBrowserFamily returns the family for a browser (by short name or name).

func GetBrowserShortName

func GetBrowserShortName(name string) string

GetBrowserShortName returns the short name for a browser.

func IsMobileOnlyBrowser

func IsMobileOnlyBrowser(browser string) bool

IsMobileOnlyBrowser checks if a browser is mobile-only.

func ParseEngineVersion

func ParseEngineVersion(ua, engine string) string

ParseEngineVersion extracts the version for a given engine from the user agent. This mirrors PHP's Browser\Engine\Version::parse().

Types

type BrowserHints

type BrowserHints struct {
	// contains filtered or unexported fields
}

BrowserHints maps app IDs to browser names.

func NewBrowserHints

func NewBrowserHints() (*BrowserHints, error)

NewBrowserHints loads the browser hints from the embedded YAML DB.

func NewDefaultBrowserHints

func NewDefaultBrowserHints() (*BrowserHints, error)

NewDefaultBrowserHints is an alias for NewBrowserHints kept for compatibility.

func (*BrowserHints) GetBrowserName

func (h *BrowserHints) GetBrowserName(appID string) string

GetBrowserName returns the browser name for an app ID.

type EngineEntry

type EngineEntry struct {
	Regex string `yaml:"regex"`
	Name  string `yaml:"name"`
	// contains filtered or unexported fields
}

EngineEntry represents a single engine definition from browser_engine.yml.

func (*EngineEntry) GetRegex

func (e *EngineEntry) GetRegex() string

GetRegex is used for keyword extraction / indexing.

func (*EngineEntry) Order

func (e *EngineEntry) Order() int

Order preserves YAML order for deterministic "first match wins" selection.

type EngineParser

type EngineParser struct {
	// contains filtered or unexported fields
}

EngineParser handles browser engine detection.

func NewDefaultEngineParser

func NewDefaultEngineParser() (*EngineParser, error)

NewDefaultEngineParser is an alias for NewEngineParser kept for compatibility.

func NewEngineParser

func NewEngineParser(opts ...common.FactoryOption) (*EngineParser, error)

NewEngineParser creates an engine parser from the embedded YAML DB.

func (*EngineParser) Parse

func (p *EngineParser) Parse(ua string) string

Parse detects the browser engine from the user agent.

type EngineSpec

type EngineSpec struct {
	Default  string            `yaml:"default,omitempty"`
	Versions map[string]string `yaml:"versions,omitempty"`
}

EngineSpec represents the engine specification in a browser entry.

type Entry

type Entry struct {
	Regex   string      `yaml:"regex"`
	Name    string      `yaml:"name"`
	Version string      `yaml:"version"`
	Engine  *EngineSpec `yaml:"engine,omitempty"`
	// contains filtered or unexported fields
}

Entry represents a single browser definition from the YAML regex file.

func (*Entry) GetRegex

func (e *Entry) GetRegex() string

GetRegex is used for keyword extraction / indexing.

func (*Entry) Order

func (e *Entry) Order() int

Order preserves YAML order for deterministic "first match wins" selection.

type Match

type Match struct {
	Type          string `json:"type" yaml:"type"`
	Name          string `json:"name" yaml:"name"`
	ShortName     string `json:"short_name" yaml:"short_name"`
	Version       string `json:"version" yaml:"version"`
	Engine        string `json:"engine" yaml:"engine"`
	EngineVersion string `json:"engine_version" yaml:"engine_version"`
	Family        string `json:"family" yaml:"family"`
}

Match represents the result of a successful browser detection. This matches the PHP return structure.

type Option

type Option func(*Parser)

Option is a functional option for configuring Parser behavior.

func WithClientHints

func WithClientHints(ch *clienthints.ClientHints) Option

WithClientHints sets client hints for the parser.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses a single user agent for browser client information. Created via ParserFactory.NewParser() - do not instantiate directly.

func (*Parser) Parse

func (p *Parser) Parse() *Match

Parse detects browsers and returns a Match, or nil if not detected. Mirrors PHP: DeviceDetector\Parser\Client\Browser::parse(): ?array

type ParserFactory

type ParserFactory struct {
	// contains filtered or unexported fields
}

ParserFactory holds pre-compiled regexes and creates Parser instances. Thread-safe for concurrent use - create once, use from multiple goroutines.

func NewDefaultParserFactory

func NewDefaultParserFactory(opts ...common.FactoryOption) (*ParserFactory, error)

NewDefaultParserFactory is an alias for NewParserFactory kept for compatibility.

func NewParserFactory

func NewParserFactory(opts ...common.FactoryOption) (*ParserFactory, error)

NewParserFactory creates a factory by loading and compiling regexes from the embedded YAML DB.

func (*ParserFactory) NewParser

func (f *ParserFactory) NewParser(ua string, opts ...Option) *Parser

NewParser creates a new Parser instance for parsing a single user agent.

func (*ParserFactory) Parse

func (f *ParserFactory) Parse(ua string, opts ...Option) *Match

Parse is a convenience method that creates a parser and immediately parses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL