Documentation
¶
Overview ¶
Package browser contains the state and navigation lifecycle of a Growse browser window.
Index ¶
- Variables
- func IsTrustedOrigin(u *url.URL) bool
- type Browser
- func New(client ResourceLoader) *Browser
- func NewWithEngineFactory(client ResourceLoader, factory runtimemodel.EngineFactory) *Browser
- func NewWithEngineFactoryAndStorage(client ResourceLoader, factory runtimemodel.EngineFactory, ...) *Browser
- func NewWithEngineFactoryAndStorageAndServiceWorkers(client ResourceLoader, factory runtimemodel.EngineFactory, ...) *Browser
- func NewWithRuntimeFactory(client ResourceLoader, factory runtimemodel.Factory) *Browser
- func NewWithRuntimeFactoryAndStorage(client ResourceLoader, factory runtimemodel.Factory, ...) *Browser
- func NewWithRuntimeFactoryAndStorageAndServiceWorkers(client ResourceLoader, factory runtimemodel.Factory, ...) *Browser
- func (b *Browser) ActivateCheckable(nodeID dom.NodeID) bool
- func (b *Browser) Back(ctx context.Context) (*Page, error)
- func (b *Browser) CanBack() bool
- func (b *Browser) CanForward() bool
- func (b *Browser) ClearHover() bool
- func (b *Browser) Close() error
- func (b *Browser) CommitInputValue(nodeID dom.NodeID, value string) bool
- func (b *Browser) DispatchClick(nodeID dom.NodeID, x, y float32) bool
- func (b *Browser) Engine() runtimemodel.Engine
- func (b *Browser) Forward(ctx context.Context) (*Page, error)
- func (b *Browser) HasAnimationFrameCallbacks() bool
- func (b *Browser) InspectPage(inspect func(*Page) bool) bool
- func (b *Browser) MoveFormFocus(reverse bool) bool
- func (b *Browser) Navigate(ctx context.Context, rawURL string) (*Page, error)
- func (b *Browser) Page() *Page
- func (b *Browser) Reload(ctx context.Context) (*Page, error)
- func (b *Browser) ReloadIgnoringCache(ctx context.Context) (*Page, error)
- func (b *Browser) ResetForm(nodeID dom.NodeID) bool
- func (b *Browser) RunAnimationFrame(current time.Time) bool
- func (b *Browser) SetAnimationClock(clock animationmodel.Clock)
- func (b *Browser) SetDevToolsSession(session *devtools.SessionStore)
- func (b *Browser) SetEngine(ctx context.Context, engine runtimemodel.Engine) (*Page, error)
- func (b *Browser) SetFetchLimiter(limiter *fetchapi.Limiter)
- func (b *Browser) SetInputValue(nodeID dom.NodeID, value string) bool
- func (b *Browser) SetOnMutation(callback func())
- func (b *Browser) SetPage(page *Page)
- func (b *Browser) SetReducedMotion(reduce bool) bool
- func (b *Browser) SetSelectValue(nodeID dom.NodeID, value string) bool
- func (b *Browser) SetTabActive(active bool)
- func (b *Browser) Submit(ctx context.Context, formID, submitterID dom.NodeID) (*Page, error)
- func (b *Browser) SubmitForm(nodeID dom.NodeID) bool
- func (b *Browser) SubmitGET(ctx context.Context, formID, submitterID dom.NodeID) (*Page, error)
- func (b *Browser) SubmitPOST(ctx context.Context, formID, submitterID dom.NodeID) (*Page, error)
- func (b *Browser) UpdateFocus(nodeID dom.NodeID) bool
- func (b *Browser) UpdateHistoryScroll(first, offset int)
- func (b *Browser) UpdateHover(nodeID dom.NodeID, x, y float32) bool
- func (b *Browser) UpdateViewport(width, height float32) bool
- func (b *Browser) ValidateForm(nodeID dom.NodeID) bool
- type BrowserFactory
- type FontRange
- type FontResource
- type Frame
- func (frame *Frame) AuthorizeFormSubmission() error
- func (frame *Frame) AuthorizePopup() error
- func (frame *Frame) AuthorizeTopNavigation(userActivated bool) error
- func (frame *Frame) Close() error
- func (frame *Frame) Navigate(ctx context.Context, rawURL string) error
- func (frame *Frame) Reload(ctx context.Context) error
- func (frame *Frame) SetScroll(x, y float32)
- func (frame *Frame) SetViewport(x, y, width, height float32)
- type FrameViewport
- type Page
- func (p *Page) ActiveAnimations(current time.Time) bool
- func (p *Page) AnimatedStyles(current time.Time) style.Map
- func (p *Page) FrameByElement(elementID dom.NodeID) (*Frame, bool)
- func (p *Page) LinkDestination(nodeID dom.NodeID) (*url.URL, string, bool)
- func (p *Page) LinkURL(nodeID dom.NodeID) (*url.URL, bool)
- func (page *Page) RuntimeDiagnostics() []devtools.RuntimeContext
- func (p *Page) SyncFrameViewports(tree *layoutmodel.Tree)
- type ResourceLoader
- type Script
- type Session
- func (s *Session) ActiveBrowser() (*Browser, bool)
- func (s *Session) ActiveBrowserTarget() (TabID, *Browser, bool)
- func (s *Session) ActiveTab() (TabSnapshot, bool)
- func (s *Session) BeginTabNavigation(id TabID) (TabSnapshot, error)
- func (s *Session) Close() error
- func (s *Session) CloseTab(id TabID) (TabCloseResult, error)
- func (s *Session) FinishTabNavigation(id TabID, failed bool) (TabSnapshot, error)
- func (s *Session) NewTab(initialURL *url.URL) (TabSnapshot, error)
- func (s *Session) SelectNext() (TabSnapshot, error)
- func (s *Session) SelectPrevious() (TabSnapshot, error)
- func (s *Session) SelectTab(id TabID) (TabSnapshot, error)
- func (s *Session) SelectTabAt(position int) (TabSnapshot, error)
- func (s *Session) SetOnActiveMutation(callback func())
- func (s *Session) SetTabTitle(id TabID, title string) (TabSnapshot, error)
- func (s *Session) SubmitFormToNewTab(ctx context.Context, sourceID TabID, formID, submitterID dom.NodeID) (TabSnapshot, *Page, error)
- func (s *Session) Tabs() []TabSnapshot
- type SessionPolicy
- type Tab
- type TabCloseResult
- type TabID
- type TabSnapshot
- type TabState
Constants ¶
This section is empty.
Variables ¶
var ( ErrFormValidation = errors.New("form validation failed") ErrSubmissionPrevented = errors.New("form submission was prevented") ErrInvalidEngine = errors.New("invalid runtime engine") )
var ( ErrTabIDExhausted = errors.New("tab id space is exhausted") ErrTabBrowser = errors.New("tab browser factory returned nil") ErrTabBrowserReuse = errors.New("tab browser factory reused an existing browser") ErrTabNotFound = errors.New("tab was not found") ErrTabLimit = errors.New("tab limit was reached") ErrTabURLTooLong = errors.New("tab URL is too long") ErrTabTitle = errors.New("tab title is invalid") )
var ErrFormTarget = errors.New("form target is not supported")
Functions ¶
func IsTrustedOrigin ¶
IsTrustedOrigin reports whether automatic Go execution is permitted for u.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser owns the state for one browser window.
MVPでは1つのアクティブページ、線形の閲覧履歴、信頼済みページごとに 独立した1つのGo Runtimeを保持する。
func NewWithEngineFactory ¶ added in v0.13.0
func NewWithEngineFactory(client ResourceLoader, factory runtimemodel.EngineFactory) *Browser
NewWithEngineFactory はGo / JavaScriptを選択できるBrowserを生成する。
func NewWithEngineFactoryAndStorage ¶ added in v0.13.0
func NewWithEngineFactoryAndStorage(client ResourceLoader, factory runtimemodel.EngineFactory, manager *storagecore.Manager) *Browser
NewWithEngineFactoryAndStorage はEngine選択と注入Storage profileを使用するBrowserを生成する。
func NewWithEngineFactoryAndStorageAndServiceWorkers ¶ added in v0.14.0
func NewWithEngineFactoryAndStorageAndServiceWorkers(client ResourceLoader, factory runtimemodel.EngineFactory, manager *storagecore.Manager, serviceWorkers *serviceworker.Manager) *Browser
NewWithEngineFactoryAndStorageAndServiceWorkers injects shared profile state.
func NewWithRuntimeFactory ¶
func NewWithRuntimeFactory(client ResourceLoader, factory runtimemodel.Factory) *Browser
NewWithRuntimeFactory は信頼済みページのスクリプトを実行するBrowserを生成する。
func NewWithRuntimeFactoryAndStorage ¶ added in v0.9.0
func NewWithRuntimeFactoryAndStorage(client ResourceLoader, factory runtimemodel.Factory, manager *storagecore.Manager) *Browser
NewWithRuntimeFactoryAndStorage は注入されたStorage profileを使用するBrowserを生成する。
func NewWithRuntimeFactoryAndStorageAndServiceWorkers ¶ added in v0.14.0
func NewWithRuntimeFactoryAndStorageAndServiceWorkers(client ResourceLoader, factory runtimemodel.Factory, manager *storagecore.Manager, serviceWorkers *serviceworker.Manager) *Browser
NewWithRuntimeFactoryAndStorageAndServiceWorkers injects shared profile state.
func (*Browser) ActivateCheckable ¶ added in v0.8.0
ActivateCheckable toggles a checkbox or selects one radio in its group.
func (*Browser) CanForward ¶
CanForward reports whether Forward has a target entry.
func (*Browser) ClearHover ¶
ClearHover clears transient hover state from the active page.
func (*Browser) CommitInputValue ¶
CommitInputValue はテキストinputの編集確定をchangeイベントとして配信する。
func (*Browser) DispatchClick ¶
DispatchClick はアクティブページの対象ノードへクリックを配信する。
func (*Browser) Engine ¶ added in v0.13.0
func (b *Browser) Engine() runtimemodel.Engine
Engine はこのTabが次のPage loadで使用するEngineを返す。
func (*Browser) HasAnimationFrameCallbacks ¶ added in v0.9.0
HasAnimationFrameCallbacks reports whether WebGo requested another frame.
func (*Browser) InspectPage ¶ added in v0.9.0
InspectPage runs a read-only inspection of the active Page on its serialized Page event queue. Callers should use it when WebGo callbacks may still mutate the DOM asynchronously.
func (*Browser) MoveFormFocus ¶ added in v0.8.0
MoveFormFocus advances focus through enabled controls in DOM order.
func (*Browser) Navigate ¶
Navigate retrieves an HTML document and makes it the active page. The current page is preserved if validation or loading fails.
func (*Browser) Page ¶
Page returns the currently active page, or nil before the first successful navigation.
func (*Browser) ReloadIgnoringCache ¶ added in v0.9.0
ReloadIgnoringCache refreshes the active page and its subresources while asking HTTP caches to revalidate them. It does not add a history entry.
func (*Browser) ResetForm ¶ added in v0.8.0
ResetForm restores a form's controls to their HTML attribute defaults.
func (*Browser) RunAnimationFrame ¶ added in v0.9.0
RunAnimationFrame delivers one Gio frame timestamp to the active WebGo runtime.
func (*Browser) SetAnimationClock ¶
func (b *Browser) SetAnimationClock(clock animationmodel.Clock)
SetAnimationClock replaces the page animation clock. Tests can inject a controllable Clock before navigation; nil restores the production clock.
func (*Browser) SetDevToolsSession ¶ added in v0.12.0
func (b *Browser) SetDevToolsSession(session *devtools.SessionStore)
SetDevToolsSession shares the Network diagnostics budget across session tabs.
func (*Browser) SetFetchLimiter ¶ added in v0.11.0
SetFetchLimiter sets the Browser Session shared WebGo Fetch limit.
func (*Browser) SetInputValue ¶
SetInputValue はユーザー入力をアクティブページの編集可能なText Controlへ反映する。
func (*Browser) SetOnMutation ¶
func (b *Browser) SetOnMutation(callback func())
SetOnMutation はWebGoによるDOM変更後の通知先を設定する。
func (*Browser) SetReducedMotion ¶
SetReducedMotion updates the browser preference exposed through the prefers-reduced-motion media feature.
func (*Browser) SetSelectValue ¶ added in v0.8.0
SetSelectValue changes a select to an enabled option and dispatches the input/change pair produced by a committed user selection.
func (*Browser) SetTabActive ¶ added in v0.10.0
SetTabActive controls whether frame-driven page work may run for this Browser.
func (*Browser) Submit ¶ added in v0.8.0
Submit validates and dispatches a cancelable submit event before navigation.
func (*Browser) SubmitForm ¶
SubmitForm はinputを含む最も近いformへsubmitイベントを配信する。
func (*Browser) SubmitGET ¶ added in v0.8.0
SubmitGET serializes a form into the action query and navigates with history.
func (*Browser) SubmitPOST ¶ added in v0.8.0
SubmitPOST sends URL-encoded entries and navigates to the response document.
func (*Browser) UpdateFocus ¶
UpdateFocus updates the element which matches the :focus pseudo-class.
func (*Browser) UpdateHistoryScroll ¶ added in v0.9.0
UpdateHistoryScroll はUIの現在scroll位置をactive History entryへ保存する。
func (*Browser) UpdateHover ¶
UpdateHover updates the active page's hovered element path.
func (*Browser) UpdateViewport ¶
UpdateViewport recomputes viewport-relative values when the content area changes.
type BrowserFactory ¶ added in v0.10.0
type BrowserFactory func() *Browser
BrowserFactory creates the isolated Browser owned by a new tab.
type FontRange ¶ added in v0.15.0
type FontRange struct{ Start, End rune }
FontRange is one inclusive @font-face unicode-range interval.
type FontResource ¶ added in v0.15.0
type FontResource struct {
Family, Style, Weight, Stretch string
Display string
UnicodeRanges []FontRange
URL, FinalURL, Format string
Loaded, Decoded bool
Error string
Face *textfont.Face
}
FontResource is one validated and decoded @font-face source.
type Frame ¶ added in v0.14.0
type Frame struct {
ID uint64
ElementID dom.NodeID
ParentID uint64
Depth int
Generation uint64
URL *url.URL
Page *Page
Viewport FrameViewport
ScrollX float32
ScrollY float32
LoadError string
Loaded bool
Closed bool
Sandbox runtimemodel.FramePolicy
// contains filtered or unexported fields
}
Frame is one nested browsing context owned by a parent Page.
func (*Frame) AuthorizeFormSubmission ¶ added in v0.14.0
AuthorizeFormSubmission applies the sandbox form gate before any side effect.
func (*Frame) AuthorizePopup ¶ added in v0.14.0
AuthorizePopup applies the sandbox auxiliary-context gate before any side effect.
func (*Frame) AuthorizeTopNavigation ¶ added in v0.14.0
AuthorizeTopNavigation applies the user-activation sandbox gate.
func (*Frame) Navigate ¶ added in v0.14.0
Navigate loads a new independent Document into this Frame.
func (*Frame) Reload ¶ added in v0.14.0
Reload reloads this Frame without replacing its parent element identity.
func (*Frame) SetScroll ¶ added in v0.14.0
SetScroll updates the child viewport scroll offset without escaping its document extent.
func (*Frame) SetViewport ¶ added in v0.14.0
SetViewport records the iframe border box and its mandatory clipping region.
type FrameViewport ¶ added in v0.14.0
type FrameViewport struct {
X, Y, Width, Height float32
ClipX, ClipY float32
ClipWidth float32
ClipHeight float32
}
FrameViewport is the iframe border box and its clipped child viewport.
type Page ¶
type Page struct {
HistoryID uint64
HistoryState string
ScrollFirst int
ScrollOffset int
ScrollRevision uint64
URL *url.URL
BaseURL *url.URL
StatusCode int
ContentType string
Source []byte
Document *dom.Document
Events *events.Dispatcher
Stylesheet *css.Stylesheet
ComputedStyles style.Map
Animations *style.AnimationRegistry
Transitions *style.TransitionRegistry
BackgroundImages map[string]image.Image
BackgroundErrors []string
ImageResources map[dom.NodeID]layoutmodel.ImageResource
Images map[string]image.Image
ImageErrors []string
Fonts []FontResource
FontErrors []string
WebFonts *layoutmodel.FontSet
Engine runtimemodel.Engine
Scripts []Script
ImportMap map[string]string
ScriptErrors []string
RuntimeStarted bool
RuntimeError string
Sandbox runtimemodel.SandboxStatus
HoverTarget dom.NodeID
HoverPath []dom.NodeID
FocusTarget dom.NodeID
FocusVisible bool
Submitter dom.NodeID
ViewportWidth float32
ViewportHeight float32
ReducedMotion bool
StyleRevision uint64
DevTools *devtools.PageStore
Frames []*Frame
FramePolicy runtimemodel.FramePolicy
// contains filtered or unexported fields
}
Page holds the state of one loaded document.
Runtimeの状態はスクリプト取得エラーと分けて保持し、Goコードを実行できない場合も ページの表示を継続できるようにする。
func NewPage ¶
NewPage creates a page for pageURL. A nil URL is allowed for documents such as an in-memory error page that do not have a network location.
func (*Page) ActiveAnimations ¶
ActiveAnimations reports whether this page needs another animation frame.
func (*Page) AnimatedStyles ¶
AnimatedStyles samples this page's CSS Animations and Transitions at current without changing its underlying computed style map.
func (*Page) FrameByElement ¶ added in v0.14.0
FrameByElement returns the live top-level Frame hosted by elementID.
func (*Page) LinkDestination ¶ added in v0.10.0
LinkDestination resolves the nearest anchor URL and normalized target.
func (*Page) RuntimeDiagnostics ¶ added in v0.14.0
func (page *Page) RuntimeDiagnostics() []devtools.RuntimeContext
RuntimeDiagnostics returns bounded, secret-free Page, Frame, and Service Worker metadata.
func (*Page) SyncFrameViewports ¶ added in v0.14.0
func (p *Page) SyncFrameViewports(tree *layoutmodel.Tree)
SyncFrameViewports maps the parent layout geometry into clipped child viewports.
type ResourceLoader ¶
type ResourceLoader interface {
Get(ctx context.Context, resourceURL *url.URL) (*network.Response, error)
}
ResourceLoader retrieves a resource for navigation.
type Script ¶
type Script = runtimemodel.Script
Script is one Go source discovered in document order.
type Session ¶ added in v0.10.0
type Session struct {
// contains filtered or unexported fields
}
Session owns an ordered collection of tabs and at most one active tab.
func NewSession ¶ added in v0.10.0
func NewSession(factory ...BrowserFactory) *Session
NewSession creates an empty browser session.
func NewSessionWithPolicy ¶ added in v0.10.0
func NewSessionWithPolicy(factory BrowserFactory, policy SessionPolicy) *Session
NewSessionWithPolicy creates an empty browser session with explicit limits.
func (*Session) ActiveBrowser ¶ added in v0.10.0
ActiveBrowser returns the Browser currently selected by browser chrome. Callers keep the returned pointer to pin an operation to this tab even if another tab becomes active before the operation completes.
func (*Session) ActiveBrowserTarget ¶ added in v0.10.0
ActiveBrowserTarget atomically returns the ID and Browser selected at the start of a chrome operation.
func (*Session) ActiveTab ¶ added in v0.10.0
func (s *Session) ActiveTab() (TabSnapshot, bool)
ActiveTab returns the active tab without exposing mutable session state.
func (*Session) BeginTabNavigation ¶ added in v0.10.0
func (s *Session) BeginTabNavigation(id TabID) (TabSnapshot, error)
BeginTabNavigation marks one tab as loading without changing selection.
func (*Session) Close ¶ added in v0.10.0
Close transitions every tab to closed and releases each owned Browser.
func (*Session) CloseTab ¶ added in v0.10.0
func (s *Session) CloseTab(id TabID) (TabCloseResult, error)
CloseTab removes a tab and deterministically selects its right neighbor or, when there is no right neighbor, its left neighbor.
func (*Session) FinishTabNavigation ¶ added in v0.10.0
func (s *Session) FinishTabNavigation(id TabID, failed bool) (TabSnapshot, error)
FinishTabNavigation publishes a result to its target tab without selecting it.
func (*Session) NewTab ¶ added in v0.10.0
func (s *Session) NewTab(initialURL *url.URL) (TabSnapshot, error)
NewTab adds an empty tab or a tab with a requested initial URL. Navigation is performed separately so callers can control its context and lifecycle.
func (*Session) SelectNext ¶ added in v0.10.0
func (s *Session) SelectNext() (TabSnapshot, error)
SelectNext selects the next live tab, wrapping at the end.
func (*Session) SelectPrevious ¶ added in v0.10.0
func (s *Session) SelectPrevious() (TabSnapshot, error)
SelectPrevious selects the previous live tab, wrapping at the beginning.
func (*Session) SelectTab ¶ added in v0.10.0
func (s *Session) SelectTab(id TabID) (TabSnapshot, error)
SelectTab makes the identified live tab active.
func (*Session) SelectTabAt ¶ added in v0.10.0
func (s *Session) SelectTabAt(position int) (TabSnapshot, error)
SelectTabAt makes the live tab at position active.
func (*Session) SetOnActiveMutation ¶ added in v0.10.0
func (s *Session) SetOnActiveMutation(callback func())
SetOnActiveMutation registers the Browser Window invalidation callback.
func (*Session) SetTabTitle ¶ added in v0.10.0
func (s *Session) SetTabTitle(id TabID, title string) (TabSnapshot, error)
SetTabTitle stores a validated document title for browser chrome.
func (*Session) SubmitFormToNewTab ¶ added in v0.10.0
func (s *Session) SubmitFormToNewTab(ctx context.Context, sourceID TabID, formID, submitterID dom.NodeID) (TabSnapshot, *Page, error)
SubmitFormToNewTab validates a _blank form submission and executes it in an isolated, newly-active tab.
func (*Session) Tabs ¶ added in v0.10.0
func (s *Session) Tabs() []TabSnapshot
Tabs returns the tabs in their display order.
type SessionPolicy ¶ added in v0.10.0
type SessionPolicy struct {
MaxTabs int
MaxTabID uint64
MaxTitleBytes int
MaxURLBytes int
MaxFetches int
}
SessionPolicy bounds tab-owned state before memory or identifiers are consumed.
func DefaultSessionPolicy ¶ added in v0.10.0
func DefaultSessionPolicy() SessionPolicy
DefaultSessionPolicy returns the production safety limits.
type Tab ¶ added in v0.10.0
type Tab struct {
// contains filtered or unexported fields
}
Tab is one top-level page owned by a browser session.
type TabCloseResult ¶ added in v0.10.0
type TabCloseResult struct {
Closed TabID
Active TabSnapshot
HasActive bool
}
TabCloseResult reports the active tab selected after a close operation.
type TabID ¶ added in v0.10.0
type TabID uint64
TabID identifies one tab for the lifetime of a browser session.