browsercookie

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 12 Imported by: 0

README

browsercookie

Go Reference test lint browser

browsercookie is a Go library that reads cookies from browser stores on the local machine.

It can auto-discover supported browsers, load cookies from one browser directly, filter by domain, and turn the result into a net/http/cookiejar.Jar. If you just want browser cookies in normal Go types, that is the whole job.

Inspiration

This package was inspired by these projects:

They solve the same kind of problem in other ecosystems. This repository does it as a Go library with a Go-shaped API.

What it does

  • Read cookies from local browser stores
  • Load from every supported browser with Load()
  • Load from a specific browser with functions such as Chrome(), Firefox(), or Safari()
  • Filter cookies with WithDomains(...)
  • Override auto-discovered cookie store paths with WithCookieFiles(...)
  • Convert []*http.Cookie into a *cookiejar.Jar with Jar(...)

Supported browsers and operating systems

The package currently knows these browser and OS combinations:

Browser Linux macOS Windows
Arc yes yes yes
Brave yes yes yes
Chrome yes yes yes
Chromium yes yes yes
Edge yes yes yes
Edge Dev yes yes yes
Firefox yes yes yes
LibreWolf yes yes yes
Opera yes yes yes
Opera GX - yes yes
Safari - yes -
Vivaldi yes yes yes
Zen yes yes yes

Support still depends on the browser and the operating system. When the current platform is not implemented, the package returns ErrUnsupported.

Install

go get github.com/Code-Hex/browsercookie

Synopsis

Load cookies from any supported browser, filter them to one domain, then use them with http.Client:

package main

import (
	"log"
	"net/http"

	"github.com/Code-Hex/browsercookie"
)

func main() {
	cookies, err := browsercookie.Load(
		browsercookie.WithDomains("example.com"),
	)
	if err != nil {
		log.Fatal(err)
	}

	jar, err := browsercookie.Jar(cookies)
	if err != nil {
		log.Fatal(err)
	}

	client := &http.Client{Jar: jar}
	resp, err := client.Get("https://example.com")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
}

If you want a specific browser instead of auto-discovery, call it directly:

cookies, err := browsercookie.Chrome()
if err != nil {
	// handle error
}

cookies, err = browsercookie.Firefox(
	browsercookie.WithDomains("example.com"),
)
if err != nil {
	// handle error
}

If you already know the cookie file path, you can override discovery:

cookies, err := browsercookie.Chrome(
	browsercookie.WithCookieFiles("/path/to/Cookies"),
)
if err != nil {
	// handle error
}

Errors

The package returns a small set of public errors:

  • ErrNotFound when no readable cookie store was found
  • ErrUnsupported when the browser or platform is not implemented
  • ErrInvalidStore when a cookie store exists but cannot be parsed
  • ErrDecrypt when an encrypted cookie value could not be decrypted

Documentation

Overview

Package browsercookie loads cookies from local browser stores.

Supported browser families include Chromium-based browsers such as Chrome, Brave, Chromium, Vivaldi, Edge, Arc, Opera, and Opera GX, Mozilla-based browsers such as Firefox, LibreWolf, and Zen, plus Safari on macOS.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound reports that no readable cookie store was found.
	ErrNotFound = errdefs.ErrNotFound
	// ErrUnsupported reports that the current OS is not implemented yet.
	ErrUnsupported = errdefs.ErrUnsupported
	// ErrInvalidStore reports that a cookie store exists but cannot be parsed.
	ErrInvalidStore = errdefs.ErrInvalidStore
	// ErrDecrypt reports that an encrypted cookie value could not be decrypted.
	ErrDecrypt = errdefs.ErrDecrypt
)

Functions

func Arc

func Arc(opts ...Option) ([]*http.Cookie, error)

Arc loads cookies from Arc.

func Brave

func Brave(opts ...Option) ([]*http.Cookie, error)

Brave loads cookies from Brave.

func Chrome

func Chrome(opts ...Option) ([]*http.Cookie, error)

Chrome loads cookies from Google Chrome.

func Chromium

func Chromium(opts ...Option) ([]*http.Cookie, error)

Chromium loads cookies from Chromium.

func Edge

func Edge(opts ...Option) ([]*http.Cookie, error)

Edge loads cookies from Microsoft Edge.

func EdgeDev

func EdgeDev(opts ...Option) ([]*http.Cookie, error)

EdgeDev loads cookies from Microsoft Edge Dev.

func Firefox

func Firefox(opts ...Option) ([]*http.Cookie, error)

Firefox loads cookies from Firefox.

func Jar

func Jar(cookies []*http.Cookie) (*cookiejar.Jar, error)

Jar converts cookies into a net/http cookie jar.

func LibreWolf

func LibreWolf(opts ...Option) ([]*http.Cookie, error)

LibreWolf loads cookies from LibreWolf.

func Load

func Load(opts ...Option) ([]*http.Cookie, error)

Load tries every supported browser in a fixed order and returns merged cookies.

func Opera

func Opera(opts ...Option) ([]*http.Cookie, error)

Opera loads cookies from Opera.

func OperaGX

func OperaGX(opts ...Option) ([]*http.Cookie, error)

OperaGX loads cookies from Opera GX.

func Safari

func Safari(opts ...Option) ([]*http.Cookie, error)

Safari loads cookies from Safari.

func Vivaldi

func Vivaldi(opts ...Option) ([]*http.Cookie, error)

Vivaldi loads cookies from Vivaldi.

func Zen

func Zen(opts ...Option) ([]*http.Cookie, error)

Zen loads cookies from Zen.

Types

type Option

type Option func(*options)

Option mutates loader configuration.

func WithCookieFiles

func WithCookieFiles(paths ...string) Option

WithCookieFiles overrides the auto-discovered cookie store paths.

func WithDomains

func WithDomains(domains ...string) Option

WithDomains filters cookies to domains that match exactly or by subdomain suffix.

Directories

Path Synopsis
internal
browsercfg
Package browsercfg defines browser discovery metadata shared by the loaders.
Package browsercfg defines browser discovery metadata shared by the loaders.
chromium
Package chromium loads cookies from Chromium-based browser stores.
Package chromium loads cookies from Chromium-based browser stores.
cookieutil
Package cookieutil provides small helpers for working with HTTP cookies.
Package cookieutil provides small helpers for working with HTTP cookies.
errdefs
Package errdefs defines shared sentinel errors for cookie loaders.
Package errdefs defines shared sentinel errors for cookie loaders.
firefox
Package firefox loads cookies from Firefox profile data.
Package firefox loads cookies from Firefox profile data.
pathutil
Package pathutil expands browser profile path patterns.
Package pathutil expands browser profile path patterns.
safari
Package safari loads cookies from Safari binary cookie stores.
Package safari loads cookies from Safari binary cookie stores.
secrets
Package secrets resolves browser decryption secrets from the operating system.
Package secrets resolves browser decryption secrets from the operating system.
sqlitecopy
Package sqlitecopy opens SQLite-backed cookie stores through temporary copies.
Package sqlitecopy opens SQLite-backed cookie stores through temporary copies.

Jump to

Keyboard shortcuts

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