browser

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package browser contains the state and navigation lifecycle of a Growse browser window.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFormValidation      = errors.New("form validation failed")
	ErrSubmissionPrevented = errors.New("form submission was prevented")
)

Functions

func IsTrustedOrigin

func IsTrustedOrigin(u *url.URL) bool

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 New

func New(client ResourceLoader) *Browser

New creates a browser with no page loaded.

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 (*Browser) ActivateCheckable added in v0.8.0

func (b *Browser) ActivateCheckable(nodeID dom.NodeID) bool

ActivateCheckable toggles a checkbox or selects one radio in its group.

func (*Browser) Back

func (b *Browser) Back(ctx context.Context) (*Page, error)

Back loads the previous successful navigation entry.

func (*Browser) CanBack

func (b *Browser) CanBack() bool

CanBack reports whether Back has a target entry.

func (*Browser) CanForward

func (b *Browser) CanForward() bool

CanForward reports whether Forward has a target entry.

func (*Browser) ClearHover

func (b *Browser) ClearHover() bool

ClearHover clears transient hover state from the active page.

func (*Browser) Close

func (b *Browser) Close() error

Close はアクティブページに属するRuntimeを停止する。

func (*Browser) CommitInputValue

func (b *Browser) CommitInputValue(nodeID dom.NodeID, value string) bool

CommitInputValue はテキストinputの編集確定をchangeイベントとして配信する。

func (*Browser) DispatchClick

func (b *Browser) DispatchClick(nodeID dom.NodeID, x, y float32) bool

DispatchClick はアクティブページの対象ノードへクリックを配信する。

func (*Browser) Forward

func (b *Browser) Forward(ctx context.Context) (*Page, error)

Forward loads the next navigation entry after a successful Back.

func (*Browser) HasAnimationFrameCallbacks added in v0.9.0

func (b *Browser) HasAnimationFrameCallbacks() bool

HasAnimationFrameCallbacks reports whether WebGo requested another frame.

func (*Browser) InspectPage added in v0.9.0

func (b *Browser) InspectPage(inspect func(*Page) bool) bool

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

func (b *Browser) MoveFormFocus(reverse bool) bool

MoveFormFocus advances focus through enabled controls in DOM order.

func (*Browser) Navigate

func (b *Browser) Navigate(ctx context.Context, rawURL string) (*Page, error)

Navigate retrieves an HTML document and makes it the active page. The current page is preserved if validation or loading fails.

func (*Browser) Page

func (b *Browser) Page() *Page

Page returns the currently active page, or nil before the first successful navigation.

func (*Browser) Reload

func (b *Browser) Reload(ctx context.Context) (*Page, error)

Reload refreshes the active page without adding a history entry.

func (*Browser) ReloadIgnoringCache added in v0.9.0

func (b *Browser) ReloadIgnoringCache(ctx context.Context) (*Page, error)

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

func (b *Browser) ResetForm(nodeID dom.NodeID) bool

ResetForm restores a form's controls to their HTML attribute defaults.

func (*Browser) RunAnimationFrame added in v0.9.0

func (b *Browser) RunAnimationFrame(current time.Time) bool

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) SetInputValue

func (b *Browser) SetInputValue(nodeID dom.NodeID, value string) bool

SetInputValue はユーザー入力をアクティブページの編集可能なText Controlへ反映する。

func (*Browser) SetOnMutation

func (b *Browser) SetOnMutation(callback func())

SetOnMutation はWebGoによるDOM変更後の通知先を設定する。

func (*Browser) SetPage

func (b *Browser) SetPage(page *Page)

SetPage replaces the active page. Passing nil clears the active page.

func (*Browser) SetReducedMotion

func (b *Browser) SetReducedMotion(reduce bool) bool

SetReducedMotion updates the browser preference exposed through the prefers-reduced-motion media feature.

func (*Browser) SetSelectValue added in v0.8.0

func (b *Browser) SetSelectValue(nodeID dom.NodeID, value string) bool

SetSelectValue changes a select to an enabled option and dispatches the input/change pair produced by a committed user selection.

func (*Browser) Submit added in v0.8.0

func (b *Browser) Submit(ctx context.Context, formID, submitterID dom.NodeID) (*Page, error)

Submit validates and dispatches a cancelable submit event before navigation.

func (*Browser) SubmitForm

func (b *Browser) SubmitForm(nodeID dom.NodeID) bool

SubmitForm はinputを含む最も近いformへsubmitイベントを配信する。

func (*Browser) SubmitGET added in v0.8.0

func (b *Browser) SubmitGET(ctx context.Context, formID, submitterID dom.NodeID) (*Page, error)

SubmitGET serializes a form into the action query and navigates with history.

func (*Browser) SubmitPOST added in v0.8.0

func (b *Browser) SubmitPOST(ctx context.Context, formID, submitterID dom.NodeID) (*Page, error)

SubmitPOST sends URL-encoded entries and navigates to the response document.

func (*Browser) UpdateFocus

func (b *Browser) UpdateFocus(nodeID dom.NodeID) bool

UpdateFocus updates the element which matches the :focus pseudo-class.

func (*Browser) UpdateHistoryScroll added in v0.9.0

func (b *Browser) UpdateHistoryScroll(first, offset int)

UpdateHistoryScroll はUIの現在scroll位置をactive History entryへ保存する。

func (*Browser) UpdateHover

func (b *Browser) UpdateHover(nodeID dom.NodeID, x, y float32) bool

UpdateHover updates the active page's hovered element path.

func (*Browser) UpdateViewport

func (b *Browser) UpdateViewport(width, height float32) bool

UpdateViewport recomputes viewport-relative values when the content area changes.

func (*Browser) ValidateForm added in v0.8.0

func (b *Browser) ValidateForm(nodeID dom.NodeID) bool

ValidateForm focuses the first invalid control and reports whether the form is valid.

type Page

type Page struct {
	HistoryID        uint64
	HistoryState     string
	ScrollFirst      int
	ScrollOffset     int
	ScrollRevision   uint64
	URL              *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
	Scripts          []Script
	ScriptErrors     []string
	RuntimeStarted   bool
	RuntimeError     string
	HoverTarget      dom.NodeID
	HoverPath        []dom.NodeID
	FocusTarget      dom.NodeID
	Submitter        dom.NodeID
	ViewportWidth    float32
	ViewportHeight   float32
	ReducedMotion    bool
	StyleRevision    uint64
}

Page holds the state of one loaded document.

Runtimeの状態はスクリプト取得エラーと分けて保持し、Goコードを実行できない場合も ページの表示を継続できるようにする。

func NewPage

func NewPage(pageURL *url.URL) *Page

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

func (p *Page) ActiveAnimations(current time.Time) bool

ActiveAnimations reports whether this page needs another animation frame.

func (*Page) AnimatedStyles

func (p *Page) AnimatedStyles(current time.Time) style.Map

AnimatedStyles samples this page's CSS Animations and Transitions at current without changing its underlying computed style map.

func (*Page) LinkURL

func (p *Page) LinkURL(nodeID dom.NodeID) (*url.URL, bool)

LinkURL resolves the nearest anchor at nodeID against the page URL.

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.

Jump to

Keyboard shortcuts

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