random

package
v1.0.28 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBrowserTypeNotSupported indicates unsupported browser type
	ErrBrowserTypeNotSupported = fmt.Errorf("%w: random generator", errs.ErrUnsupportedBrowser)

	// ErrNoRandomProfileFound indicates no random fingerprint profile found
	ErrNoRandomProfileFound = fmt.Errorf("%w: random profiles", errs.ErrNoProfilesAvailable)

	// ErrRandomProfileInvalid indicates invalid random fingerprint profile
	ErrRandomProfileInvalid = fmt.Errorf("%w: random profile is invalid", generator.ErrFailedToGenerateFingerprint)
)

Functions

func GetRandomFingerprint

func GetRandomFingerprint() (*types.FingerprintResult, error)

GetRandomFingerprint selects a full fingerprint from all available profiles.

The function picks a profile from profiles.MappedTLSClients and generates the matching User-Agent and HTTP headers. OS is selected randomly.

Returns:

  • *types.FingerprintResult: complete profile, User-Agent, and headers
  • error: returned when profile set is empty or profile is invalid

Example:

result, err := GetRandomFingerprint()
if err != nil {
    log.Fatal(err)
}
println(result.UserAgent)
println(result.ClientProfile.GetClientHelloStr())

Thread safety: yes. Performance: avg ~7.4us and ~1.8KB allocations.

func GetRandomFingerprintByBrowser

func GetRandomFingerprintByBrowser(browserType string) (*types.FingerprintResult, error)

GetRandomFingerprintByBrowser selects a random fingerprint by browser type. browserType: "chrome", "firefox", "safari", "opera", etc.

func GetRandomFingerprintByBrowserWithOS

func GetRandomFingerprintByBrowserWithOS(browserType string, os types.OperatingSystem) (*types.FingerprintResult, error)

GetRandomFingerprintByBrowserWithOS selects by browser type with optional OS.

func GetRandomFingerprintWithOS

func GetRandomFingerprintWithOS(os types.OperatingSystem) (*types.FingerprintResult, error)

GetRandomFingerprintWithOS selects a random fingerprint with optional OS.

Similar to GetRandomFingerprint, but allows a target OS. If os is empty, OS is chosen randomly.

Args:

  • os: target OS, e.g. "Windows NT 10.0; Win64; x64"; empty means random

Returns:

  • *types.FingerprintResult: full fingerprint result
  • error: returned for invalid OS or empty profile set

Example:

// Use explicit Windows OS
result, err := GetRandomFingerprintWithOS("Windows NT 10.0; Win64; x64")
// Choose OS randomly
result, err := GetRandomFingerprintWithOS("")

Thread safety: yes.

func IsBrowserTypeNotSupported

func IsBrowserTypeNotSupported(err error) bool

IsBrowserTypeNotSupported checks whether the error indicates unsupported browser type

func IsNoRandomProfileFound

func IsNoRandomProfileFound(err error) bool

IsNoRandomProfileFound checks whether the error indicates no random fingerprint profile

func IsRandomProfileInvalid

func IsRandomProfileInvalid(err error) bool

IsRandomProfileInvalid checks whether the error indicates invalid random fingerprint profile

Types

type ErrBrowserNotFound

type ErrBrowserNotFound struct {
	Browser string
}

ErrBrowserNotFound indicates unknown browser type.

func (*ErrBrowserNotFound) Error

func (e *ErrBrowserNotFound) Error() string

Jump to

Keyboard shortcuts

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