Documentation
¶
Overview ¶
Package session owns everything about a signed-in NotebookLM session: which host the account uses, the page tokens, cookies and their storage.
Index ¶
- Constants
- Variables
- func DefaultDir() (string, error)
- func IsNotebookHost(u *url.URL) bool
- func MigrateProfiles(oldDir, newDir string, kr Keyring) ([]string, error)
- type Cookie
- type DirEnv
- type Host
- type HostRedirectError
- type Jar
- func (j *Jar) Add(c Cookie)
- func (j *Jar) All() []Cookie
- func (j *Jar) Cookies(u *url.URL) []*http.Cookie
- func (j *Jar) Has(names ...string) bool
- func (j *Jar) HeaderFor(h Host) string
- func (j *Jar) Merge(resp *http.Response)
- func (j *Jar) Missing() []string
- func (j *Jar) Replace(cs []Cookie)
- func (j *Jar) SetCookies(u *url.URL, cs []*http.Cookie)
- func (j *Jar) Valid() bool
- type Keyring
- type OSKeyring
- type Profile
- type Store
- type TimeoutKeyring
- type Tokens
Constants ¶
const KeyringTimeout = 30 * time.Second
KeyringTimeout leaves time to answer the macOS "allow access" dialog.
Variables ¶
var ( ErrSignedOut = errors.New("session: signed out") ErrCookieMismatch = errors.New("session: cookie mismatch (cookies bound to another client)") ErrPageDrift = errors.New("session: page tokens not found (page layout changed)") )
var ErrKeyringTimeout = errors.New("session: the OS keyring did not answer (is the keychain locked or missing?)")
ErrKeyringTimeout: the OS keyring did not answer within the timeout.
var ErrStaleRevision = errors.New("session: profile changed on disk since it was loaded")
var ErrUndecryptable = errors.New("session: profile cannot be decrypted")
ErrUndecryptable marks a profile file that its key cannot decrypt: the key does not match (it was replaced), or the file is damaged. Such a profile can never be read again. A keyring that cannot answer is not this error.
Functions ¶
func IsNotebookHost ¶
IsNotebookHost is the only host check in the codebase. Upstreams that scattered host checks broke in five places on the rebrand.
func MigrateProfiles ¶ added in v0.3.2
MigrateProfiles copies profiles from an old profiles folder into newDir. A profile is copied only when newDir has none of that name and the old one decrypts with its own key; the key goes along (key file, or keyring entry under newDir's scoped name). The old folder and its keyring entries are never changed, so nothing is lost. A profile that does not decrypt (it belongs to another view of the folder, or its key is gone) is skipped. It is cheap when there is nothing to do and safe to run on every start; it returns the names it copied.
Types ¶
type Cookie ¶
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Domain string `json:"domain"`
Path string `json:"path"`
Expires time.Time `json:"expires,omitzero"`
Secure bool `json:"secure,omitempty"`
HTTPOnly bool `json:"httpOnly,omitempty"`
}
Cookie is a stored browser cookie. Domain starting with "." matches subdomains; otherwise it is host-only.
type DirEnv ¶ added in v0.3.2
type DirEnv struct {
GOOS string
Home func() (string, error) // os.UserHomeDir
Config func() (string, error) // os.UserConfigDir
}
DirEnv resolves the default config folders. The lookups are functions so tests can point them at temp folders and never read the real home or %APPDATA%.
func (DirEnv) ConfigDir ¶ added in v0.3.2
ConfigDir is the default sourcebolt config folder: %USERPROFILE%\.sourcebolt on Windows, <user config dir>/sourcebolt elsewhere.
Windows moved out of %APPDATA% because a process started by a packaged (MSIX) app, such as Claude Desktop from the Microsoft Store, gets AppData file-system virtualization: its writes to %APPDATA% land in a private copy, so two apps on one PC saw two different profile files. The user profile folder outside AppData is not virtualized.
func (DirEnv) LegacyConfigDir ¶ added in v0.3.2
LegacyConfigDir is the folder versions up to 0.3.1 used on Windows (%APPDATA%\sourcebolt), or "" when there is none to migrate from.
type Host ¶
type Host string
Host is a NotebookLM web host, optionally with a port (tests).
const HostDefault Host = "notebook.google.com"
HostDefault is where rebranded accounts land since July 2026.
type HostRedirectError ¶
type HostRedirectError struct{ To Host }
HostRedirectError means the account was redirected to another notebook host.
func (*HostRedirectError) Error ¶
func (e *HostRedirectError) Error() string
type Jar ¶
type Jar struct {
// contains filtered or unexported fields
}
Jar is a concurrency-safe cookie jar that implements http.CookieJar and merges Set-Cookie responses so rotated cookies are never lost.
func ImportHeader ¶
ImportHeader parses a raw "Cookie:" header, a bare "a=b; c=d" list or a cURL command copied from browser dev tools.
func ImportJSON ¶
ImportJSON parses an array of cookie objects (browser-extension exports). Expiry may be in seconds or milliseconds.
func ImportNetscape ¶
ImportNetscape parses a Netscape cookies.txt export.
func ParseExport ¶ added in v0.3.2
ParseExport reads a cookie export in format "netscape", "json" or "header". An empty format is detected: a leading "[" is JSON, a tab is Netscape, anything else is a Cookie header.
func (*Jar) Replace ¶
Replace swaps the jar contents in place, so every holder of the jar pointer sees the new session (a fresh login picked up by a running server).
func (*Jar) SetCookies ¶
SetCookies implements http.CookieJar.
type Keyring ¶
type Keyring interface {
Get(service, user string) (string, error)
Set(service, user, value string) error
Delete(service, user string) error
}
Keyring is the subset of an OS keyring the store needs.
type OSKeyring ¶
type OSKeyring struct{}
OSKeyring uses the platform keyring (Windows Credential Manager, macOS Keychain, Linux Secret Service). Only a 32-byte key goes there: Windows limits entries to 2,560 bytes, too small for a cookie jar.
Every call gives up after KeyringTimeout: on macOS the keyring is the `security` tool, which waits forever on a locked or missing keychain when nobody can unlock it (ssh, CI, a headless Mac). A new profile's key then goes to the key file instead.
type Profile ¶
type Profile struct {
Name string
Host Host
Jar *Jar
Rev int64 // revision on disk; Save fails if someone else saved since Load
Updated time.Time
KeyInFile bool // the encryption key lives in a 0600 file (no OS keyring)
}
Profile is one signed-in Google account.
type Store ¶
type Store interface {
Load(name string) (*Profile, error)
Save(p *Profile) error
Delete(name string) error
List() ([]string, error)
}
Store persists profiles.
func NewFileStore ¶
NewFileStore stores each profile as an AES-256-GCM encrypted file in dir.
type TimeoutKeyring ¶ added in v0.3.0
TimeoutKeyring returns ErrKeyringTimeout when Inner does not answer within Timeout. The abandoned call keeps running in the background.
func (TimeoutKeyring) Delete ¶ added in v0.3.0
func (k TimeoutKeyring) Delete(s, u string) error
func (TimeoutKeyring) Get ¶ added in v0.3.0
func (k TimeoutKeyring) Get(s, u string) (string, error)
func (TimeoutKeyring) Set ¶ added in v0.3.0
func (k TimeoutKeyring) Set(s, u, v string) error