Documentation
¶
Overview ¶
Package state is the browser's in-memory model: windows, tabs, per-window active tab, ordering, the closed-tab stack and per-tab navigation history. It is pure data plus a mutex, with no I/O and no engine dependency, and it renders to the JSON snapshot / RFC 7386 merge patches that the chrome page consumes as the `state` and `state.patch` messages.
Snapshot schema (what the chrome page receives):
{
"window": {"id":1,"w":1280,"h":800,"scale":1,"incognito":false,"focused":true},
"tabs": [{"id","url","title","favicon","loading","progress","canBack","canForward",
"security":{"level","https","certValid","issuer"},"audio","pinned","muted",
"incognito","discarded","blocked"}, ...], // visual order, pinned first
"active": "tab-id",
"url","title","loading","canBack","canForward","security","bookmarked","incognito",
// mirrors of the active tab for the toolbar
"theme": "light|dark|system",
"sidebar": {"open":false,"width":360},
"settings": {...},
"find": {"open":false,"query":"","matches":0,"index":0},
"closedTabs": 0
}
Index ¶
- func Apply(target, patch map[string]any) map[string]any
- func Diff(old, new map[string]any) map[string]any
- func Normalize(v map[string]any) map[string]any
- type ClosedTab
- type Find
- type Model
- func (m *Model) Activate(id string) bool
- func (m *Model) Active(win int) string
- func (m *Model) AddTab(win int, t Tab, index int, activate bool)
- func (m *Model) AddWindow(w, h int, scale float64, incognito bool) int
- func (m *Model) CloseTab(id string) (next string, ok bool)
- func (m *Model) ClosedCount() int
- func (m *Model) Move(id string, to int) bool
- func (m *Model) Navigated(id, url string, replace bool)
- func (m *Model) Order(win int) []string
- func (m *Model) PopClosed() (ClosedTab, bool)
- func (m *Model) Rev() uint64
- func (m *Model) SetFocused(win int, f bool)
- func (m *Model) SetWindowSize(win, w, h int, scale float64)
- func (m *Model) Snapshot(win int) map[string]any
- func (m *Model) Tab(id string) (Tab, bool)
- func (m *Model) TabCount() int
- func (m *Model) Traverse(id string, delta int) (string, bool)
- func (m *Model) Update(id string, fn func(t *Tab)) bool
- func (m *Model) WindowInfo(win int) (Window, bool)
- type Security
- type Sidebar
- type Tab
- type Window
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClosedTab ¶
type ClosedTab struct {
URL string `json:"url"`
Title string `json:"title"`
History []string `json:"history,omitempty"`
HIdx int `json:"hidx"`
Scroll int `json:"scroll"`
Pinned bool `json:"pinned"`
Index int `json:"index"`
Window int `json:"window"`
Incognito bool `json:"-"`
At time.Time `json:"at"`
}
ClosedTab is an entry of the reopen stack.
type Find ¶
type Find struct {
Open bool `json:"open"`
Query string `json:"query"`
Matches int `json:"matches"`
Index int `json:"index"`
}
Find is the find-in-page bar state.
type Model ¶
type Model struct {
Theme string
Sidebar Sidebar
Find Find
Settings map[string]any
// Bookmarked answers "is this URL bookmarked" for the toolbar star.
Bookmarked func(url string) bool
// contains filtered or unexported fields
}
Model is the whole browser state. All methods are safe for concurrent use.
func (*Model) AddTab ¶
AddTab inserts a tab. index < 0 appends (after pinned tabs for unpinned). The tab becomes active when activate is true.
func (*Model) CloseTab ¶
CloseTab removes a tab, pushes it on the reopen stack (not for incognito tabs, which must leave no trace) and returns the tab that became active ("" if the window is now empty).
func (*Model) ClosedCount ¶
ClosedCount is the size of the reopen stack.
func (*Model) Navigated ¶
Navigated records a committed navigation in the tab's history. replace overwrites the current entry (redirects, reload); traverse moves the index (back/forward) without adding.
func (*Model) SetFocused ¶
SetFocused records window focus.
func (*Model) SetWindowSize ¶
SetWindowSize records the logical size and device scale.
type Security ¶
type Security struct {
Level string `json:"level"` // "secure" | "insecure" | "internal" | "error" | "none"
HTTPS bool `json:"https"`
CertValid bool `json:"certValid"`
Issuer string `json:"issuer,omitempty"`
}
Security describes the connection security shown by the lock icon.
type Tab ¶
type Tab struct {
ID string `json:"id"`
URL string `json:"url"`
Title string `json:"title"`
Favicon string `json:"favicon,omitempty"`
Loading bool `json:"loading"`
Progress float64 `json:"progress"`
CanBack bool `json:"canBack"`
CanForward bool `json:"canForward"`
Security Security `json:"security"`
Audio bool `json:"audio"` // legacy name of Audible
Crashed bool `json:"crashed"` // the tab's engine worker panicked
Pinned bool `json:"pinned"`
Muted bool `json:"muted"`
Incognito bool `json:"incognito"`
Discarded bool `json:"discarded"`
Blocked int `json:"blocked"` // trackers blocked on this tab
Popup bool `json:"popup,omitempty"` // opened by a page's window.open / link target (the tab strip marks it)
Cam bool `json:"-"` // the page is using the camera
Mic bool `json:"-"` // ...the microphone
// not sent to the chrome page
Window int `json:"-"`
History []string `json:"-"` // navigation entries (urls)
HIdx int `json:"-"`
Scroll int `json:"-"` // device-independent scroll offset, for session restore
Opened time.Time `json:"-"`
Opener string `json:"-"` // id of the tab whose page opened this popup
}
Tab is one browser tab as the chrome page sees it.