Documentation
¶
Index ¶
- Constants
- func DecryptCookiesInPlace(cookiesPath string) (total, decrypted, failed int, err error)
- func InjectCookies(page *rod.Page, cookies []CookieRecord) (int, error)
- func LoadStorageState(browser *rod.Browser, page *rod.Page, state *StorageState) error
- func SaveCookiesJSON(profileDir string, cookies []CookieRecord) error
- type CookieRecord
- type StorageCookie
- type StorageKeyValue
- type StorageOrigin
- type StorageState
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.