unibrows

package module
v0.0.0-...-f096b25 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 9 Imported by: 0

README

Unibrows

A lightweight Go package for extracting cookies and bookmarks from Chromium-based browsers across Windows, macOS, and Linux.

Features

  • Cross-platform support: Works on Windows, macOS, and Linux
  • Multiple browsers: Chrome, Edge, Brave, Opera, Vivaldi, and more
  • Simple API: Extract all data or just what you need
  • Secure decryption: Handles browser-specific encryption (DPAPI on Windows, Keychain on macOS)
  • Helper methods: Filter cookies by domain, organize bookmarks by folder

Supported Browsers

Browser Windows macOS Linux
Chrome
Edge
Brave
Opera -
Vivaldi -
Chromium - -

Installation

go get github.com/limpdev/unibrows

Quick Start

Extract Everything from Chrome
package main

import (
    "fmt"
    "log"

    "github.com/limpdev/unibrows"
)

func main() {
    data, err := unibrows.Chrome()
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Browser: %s\n", data.Browser)
    fmt.Printf("Profile: %s\n", data.Profile)
    fmt.Printf("Cookies: %d\n", len(data.Cookies))
    fmt.Printf("Bookmarks: %d\n", len(data.Bookmarks))
}
Extract Only Cookies
cookies, err := unibrows.ChromeCookies()
if err != nil {
    log.Fatal(err)
}

for _, cookie := range cookies {
    fmt.Printf("%s = %s\n", cookie.Name, cookie.Value)
}
Extract Only Bookmarks
bookmarks, err := unibrows.ChromeBookmarks()
if err != nil {
    log.Fatal(err)
}

for _, bookmark := range bookmarks {
    fmt.Printf("[%s] %s - %s\n", bookmark.Folder, bookmark.Name, bookmark.URL)
}

Working with Cookies

Filter by Domain
cookies, _ := unibrows.ChromeCookies()

// Get cookies for a specific domain
githubCookies := cookies.ForDomain("github.com")

// Get cookies for all subdomains
googleCookies := cookies.ForDomainSuffix("google.com")
Convert to Map for Easy Lookup
cookies, _ := unibrows.ChromeCookies()
cookieMap := cookies.AsMap()

// Quick access by name
sessionID := cookieMap["session_id"]
authToken := cookieMap["auth_token"]
Using Cookies in HTTP Requests
package main

import (
    "fmt"
    "net/http"

    "github.com/limpdev/unibrows"
)

func main() {
    // Extract cookies from Chrome
    cookies, err := unibrows.ChromeCookies()
    if err != nil {
        panic(err)
    }

    // Filter for specific domain
    githubCookies := cookies.ForDomain("github.com")

    // Create HTTP client
    client := &http.Client{}
    req, _ := http.NewRequest("GET", "https://github.com/api/user", nil)

    // Add cookies to request
    for _, cookie := range githubCookies {
        req.AddCookie(&http.Cookie{
            Name:  cookie.Name,
            Value: cookie.Value,
        })
    }

    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Printf("Response status: %s\n", resp.Status)
}

Passing Cookies to Another Script

Example 1: Export to JSON
package main

import (
    "encoding/json"
    "os"

    "github.com/limpdev/unibrows"
)

func main() {
    cookies, err := unibrows.ChromeCookies()
    if err != nil {
        panic(err)
    }

    // Filter for specific domain
    targetCookies := cookies.ForDomain("example.com")

    // Export to JSON file
    file, _ := os.Create("cookies.json")
    defer file.Close()

    encoder := json.NewEncoder(file)
    encoder.SetIndent("", "  ")
    encoder.Encode(targetCookies)
}
Example 2: Pass via HTTP API
package main

import (
    "encoding/json"
    "net/http"

    "github.com/limpdev/unibrows"
)

func cookieHandler(w http.ResponseWriter, r *http.Request) {
    domain := r.URL.Query().Get("domain")

    cookies, err := unibrows.ChromeCookies()
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    // Filter by domain if specified
    if domain != "" {
        cookies = cookies.ForDomain(domain)
    }

    w.Header().Set("Content-Type", "application/json")
    json.NewEncoder(w).Encode(cookies)
}

func main() {
    http.HandleFunc("/cookies", cookieHandler)
    http.ListenAndServe(":8080", nil)
}
Example 3: Environment Variable Export
package main

import (
    "fmt"
    "os"

    "github.com/limpdev/unibrows"
)

func main() {
    cookies, _ := unibrows.ChromeCookies()
    cookieMap := cookies.ForDomain("api.example.com").AsMap()

    // Set as environment variables
    if token, ok := cookieMap["auth_token"]; ok {
        os.Setenv("API_AUTH_TOKEN", token)
    }

    if session, ok := cookieMap["session_id"]; ok {
        os.Setenv("API_SESSION_ID", session)
    }

    // Now execute another script that reads these env vars
    // cmd := exec.Command("./your-script")
    // cmd.Env = os.Environ()
    // cmd.Run()
}

Working with Multiple Browsers

package main

import (
    "fmt"

    "github.com/limpdev/unibrows"
)

func main() {
    browsers := []string{"chrome", "edge", "brave"}

    for _, browserName := range browsers {
        if !unibrows.IsSupported(browserName) {
            fmt.Printf("%s not supported on this OS\n", browserName)
            continue
        }

        data, err := unibrows.Extract(browserName)
        if err != nil {
            fmt.Printf("Failed to extract from %s: %v\n", browserName, err)
            continue
        }

        fmt.Printf("%s: %d cookies, %d bookmarks\n",
            data.Browser, len(data.Cookies), len(data.Bookmarks))
    }
}

Custom Profile Paths

// Extract from a specific profile
customPath := "/path/to/browser/profile"
data, err := unibrows.Extract("chrome", customPath)

Data Structures

type Cookie struct {
    Host       string    // Domain (e.g., ".github.com")
    Path       string    // Path (e.g., "/")
    Name       string    // Cookie name
    Value      string    // Decrypted cookie value
    IsSecure   bool      // HTTPS only
    IsHTTPOnly bool      // Not accessible via JavaScript
    SameSite   int       // SameSite attribute (0, 1, 2)
    CreateDate time.Time // When cookie was created
    ExpireDate time.Time // When cookie expires
}
Bookmark
type Bookmark struct {
    ID        string    // Unique bookmark ID
    Name      string    // Bookmark title
    URL       string    // Bookmark URL
    Folder    string    // Folder path (e.g., "bookmark_bar/Work")
    DateAdded time.Time // When bookmark was added
}

Error Handling

data, err := unibrows.Chrome()
if err != nil {
    switch e := err.(type) {
    case unibrows.ErrUnsupportedOS:
        fmt.Printf("OS not supported: %s\n", e.OS)
    case unibrows.ErrProfileNotFound:
        fmt.Printf("Profile not found: %s\n", e.Path)
    case unibrows.ErrDecryption:
        fmt.Printf("Decryption failed: %s\n", e.Reason)
    default:
        fmt.Printf("Unknown error: %v\n", err)
    }
}

Platform-Specific Notes

Windows
  • Uses DPAPI for decryption
  • Requires browser to be closed for reliable extraction
macOS
  • Uses Keychain for decryption
  • May require user permission to access Keychain
Linux
  • Uses hardcoded encryption key (v10/v11)
  • No additional permissions required

Practical Use Cases

  1. Session Management: Transfer authenticated sessions between tools
  2. Testing: Extract production cookies for integration testing
  3. Migration: Move browser data between systems
  4. Automation: Authenticate automated scripts using existing browser sessions
  5. Analysis: Audit cookies for security or privacy analysis

License

MIT

Recognition

This repo is just for funsies, and is heavily inspired by Hack Browser Data, which also declares a license of MIT. If you are a would-be contributor, go there please. This is a personal project for my own development/education.

Documentation

Overview

Package unibrows provides simple access to browser cookies and bookmarks across Chrome, Edge, and other Chromium-based browsers.

Basic usage:

import "github.com/limpdev/unibrows"

// Extract all data from Chrome
data, err := unibrows.Chrome()
if err != nil {
	log.Fatal(err)
}

// Just get cookies
cookies, err := unibrows.ChromeCookies()
if err != nil {
	log.Fatal(err)
}

// Filter cookies by domain
githubCookies := cookies.ForDomain("github.com")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSupported

func IsSupported(browserName string) bool

IsSupported returns true if the browser is supported on this OS

func SupportedBrowsers

func SupportedBrowsers() []string

SupportedBrowsers returns a list of browsers supported on this OS

Types

type Bookmark

type Bookmark struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	URL       string    `json:"url"`
	Folder    string    `json:"folder"`
	DateAdded time.Time `json:"date_added"`
}

Bookmark represents a browser bookmark

type Bookmarks

type Bookmarks []Bookmark

Bookmarks is a slice of Bookmark with helper methods

func ChromeBookmarks

func ChromeBookmarks() (Bookmarks, error)

ChromeBookmarks extracts only bookmarks from Chrome

func EdgeBookmarks

func EdgeBookmarks() (Bookmarks, error)

EdgeBookmarks extracts only bookmarks from Edge

func (Bookmarks) InFolder

func (b Bookmarks) InFolder(folder string) Bookmarks

InFolder returns all bookmarks in the specified folder

type BrowserData

type BrowserData struct {
	Browser   string
	Profile   string
	Cookies   Cookies
	Bookmarks Bookmarks
}

BrowserData contains all extracted browser data

func Chrome

func Chrome() (*BrowserData, error)

Chrome extracts all data from Google Chrome's default profile

func Edge

func Edge() (*BrowserData, error)

Edge extracts all data from Microsoft Edge's default profile

func Extract

func Extract(browserName string, profilePath ...string) (*BrowserData, error)

Extract extracts data from a specific browser and optional profile path Supported browsers: "chrome", "edge", "brave", "opera"

type Cookie struct {
	Host       string    `json:"host"`
	Path       string    `json:"path"`
	Name       string    `json:"name"`
	Value      string    `json:"value"`
	IsSecure   bool      `json:"is_secure"`
	IsHTTPOnly bool      `json:"is_http_only"`
	SameSite   int       `json:"same_site"`
	CreateDate time.Time `json:"create_date"`
	ExpireDate time.Time `json:"expire_date"`
}

Cookie represents a browser cookie with all relevant metadata

type Cookies

type Cookies []Cookie

Cookies is a slice of Cookie with helper methods

func ChromeCookies

func ChromeCookies() (Cookies, error)

ChromeCookies extracts only cookies from Chrome

func EdgeCookies

func EdgeCookies() (Cookies, error)

EdgeCookies extracts only cookies from Edge

func (Cookies) AsMap

func (c Cookies) AsMap() map[string]string

AsMap returns cookies as a map[name]value for easy lookup

func (Cookies) ForDomain

func (c Cookies) ForDomain(domain string) Cookies

ForDomain returns all cookies matching the given domain

func (Cookies) ForDomainSuffix

func (c Cookies) ForDomainSuffix(suffix string) Cookies

ForDomainSuffix returns all cookies for domains ending with the suffix

type ErrDecryption

type ErrDecryption struct {
	Browser string
	Reason  string
}

func (ErrDecryption) Error

func (e ErrDecryption) Error() string

type ErrProfileNotFound

type ErrProfileNotFound struct {
	Browser string
	Path    string
}

func (ErrProfileNotFound) Error

func (e ErrProfileNotFound) Error() string

type ErrUnsupportedBrowser

type ErrUnsupportedBrowser struct {
	Browser string
	OS      string
}

func (ErrUnsupportedBrowser) Error

func (e ErrUnsupportedBrowser) Error() string

type ErrUnsupportedOS

type ErrUnsupportedOS struct {
	OS string
}

func (ErrUnsupportedOS) Error

func (e ErrUnsupportedOS) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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