storage

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const CookiesJSONFilename = ".ghostchrome-cookies.json"

CookiesJSONFilename is the filename written by import-profile inside the ghostchrome profile dir. openPage() reads this on startup and replays the cookies into Chrome via CDP Network.setCookies.

Variables

This section is empty.

Functions

func DecryptCookiesInPlace

func DecryptCookiesInPlace(cookiesPath string) (total, decrypted, failed int, err error)

DecryptCookiesInPlace opens the SQLite Cookies database at path, decrypts every v10-tagged encrypted_value using the macOS Keychain Chrome key, and rewrites the row with the plaintext in `value` (encrypted_value cleared). Kept for backward compat with profiles imported before the JSON export scheme. Returns counts: total, decrypted, failed.

func InjectCookies

func InjectCookies(page *rod.Page, cookies []CookieRecord) (int, error)

InjectCookies sets the given cookies on the browser via CDP, one at a time. A bad cookie (binary garbage from a misdecoded entry, mismatched domain, etc.) doesn't poison the rest of the batch. Returns the number of successful injections.

func LoadStorageState

func LoadStorageState(browser *rod.Browser, page *rod.Page, state *StorageState) error

LoadStorageState restores cookies browser-wide and localStorage per origin. For each origin referenced, the current page is navigated there briefly so the localStorage write lands in the right context.

func SaveCookiesJSON

func SaveCookiesJSON(profileDir string, cookies []CookieRecord) error

SaveCookiesJSON writes a portable cookie snapshot inside the profile dir.

Types

type CookieRecord

type CookieRecord struct {
	Name     string  `json:"name"`
	Value    string  `json:"value"`
	Domain   string  `json:"domain"`
	Path     string  `json:"path"`
	Expires  float64 `json:"expires"` // CDP unix seconds, 0 = session
	Secure   bool    `json:"secure"`
	HTTPOnly bool    `json:"httpOnly"`
	SameSite string  `json:"sameSite,omitempty"` // "Strict"|"Lax"|"None"|""
}

CookieRecord holds the subset of fields ghostchrome injects via CDP at session start. Mirrors the relevant columns of Chrome's Cookies SQLite schema, plus the decrypted plaintext value.

func ExportDecryptedCookies

func ExportDecryptedCookies(cookiesPath string) ([]CookieRecord, error)

ExportDecryptedCookies opens the SQLite Cookies db at path, decrypts every v10-tagged encrypted_value via macOS Keychain, and returns the list as portable CookieRecord values. Source file is not modified.

func LoadCookiesJSON

func LoadCookiesJSON(profileDir string) ([]CookieRecord, error)

LoadCookiesJSON reads the snapshot if present. Returns nil, nil when the file is absent (no import done on this profile).

type StorageCookie

type StorageCookie struct {
	Name     string  `json:"name"`
	Value    string  `json:"value"`
	Domain   string  `json:"domain"`
	Path     string  `json:"path"`
	Expires  float64 `json:"expires,omitempty"`
	HTTPOnly bool    `json:"httpOnly,omitempty"`
	Secure   bool    `json:"secure,omitempty"`
	SameSite string  `json:"sameSite,omitempty"`
}

StorageCookie uses the Playwright-compatible field names (sameSite as string, expires as float64 seconds-since-epoch).

type StorageKeyValue

type StorageKeyValue struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

StorageKeyValue is a single localStorage entry.

type StorageOrigin

type StorageOrigin struct {
	Origin       string            `json:"origin"`
	LocalStorage []StorageKeyValue `json:"localStorage"`
}

StorageOrigin groups localStorage entries by origin. sessionStorage is NOT persisted: it's per-tab and generally not replayable.

type StorageState

type StorageState struct {
	Cookies []StorageCookie `json:"cookies"`
	Origins []StorageOrigin `json:"origins"`
}

StorageState mirrors the Playwright storageState JSON shape so a state file produced by ghostchrome can be loaded by Playwright (and vice versa, within reasonable limits).

func SaveStorageState

func SaveStorageState(browser *rod.Browser, page *rod.Page) (*StorageState, error)

SaveStorageState captures cookies (browser-wide) and localStorage for the origin of the current page. Callers can concatenate multiple SaveStorageState runs if they need multiple origins.

Jump to

Keyboard shortcuts

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