browser

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 21 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

This section is empty.

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 (*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) 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) 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 はユーザー入力をアクティブページのテキストinputへ反映する。

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

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

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

func (*Browser) UpdateFocus

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

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

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.

type Page

type Page struct {
	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
	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