runtime

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package runtime はページで使用する交換可能なGo実行環境を定義する。

Index

Constants

View Source
const (
	EngineGo         Engine = "go"
	EngineJavaScript Engine = "javascript"

	ScriptParserBlocking ScriptSchedule = "parser-blocking"
	ScriptDefer          ScriptSchedule = "defer"
	ScriptAsync          ScriptSchedule = "async"

	ScriptClassic ScriptKind = "classic"
	ScriptModule  ScriptKind = "module"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DOMRect added in v0.15.0

type DOMRect struct {
	X, Y, Width, Height float32
}

DOMRect is the bounded CSS-pixel rectangle exposed to JavaScript.

type Engine added in v0.13.0

type Engine string

Engine はPage Scriptを評価する実行エンジンを識別する。

func NormalizeEngine added in v0.13.0

func NormalizeEngine(engine Engine) Engine

NormalizeEngine は既存呼び出しのzero valueをGoとして扱う。

func (Engine) Valid added in v0.13.0

func (engine Engine) Valid() bool

Valid はGrowseが選択可能なEngineかを返す。

type EngineFactory added in v0.13.0

type EngineFactory func(Engine) Runtime

EngineFactory は選択Engineに対応する独立したRuntimeを生成する。

func ForGo added in v0.13.0

func ForGo(factory Factory) EngineFactory

ForGo は既存のGo専用Factoryを言語選択可能なFactoryへ変換する。 JavaScriptを要求された場合はnilを返し、暗黙にGoへfallbackしない。

type Environment

type Environment struct {
	Document            *dom.Document
	Events              *events.Dispatcher
	BaseURL             *url.URL
	ResourceBaseURL     *url.URL
	ImportMap           map[string]string
	Fetch               func(context.Context, *network.Request) (*network.Response, error)
	FetchLimiter        *fetchapi.Limiter
	Navigate            func(*url.URL) error
	HistoryPush         func(string, *url.URL) error
	HistoryReplace      func(string, *url.URL) error
	HistoryTraverse     func(int) error
	HistoryInfo         func() (int, string)
	LocalStorage        *storagecore.Area
	SessionStorage      *storagecore.Area
	StorageSource       storagecore.MutationSource
	OnMutation          func()
	RefreshStyles       func(context.Context) error
	ReadRender          func(context.Context, dom.NodeID) (RenderSnapshot, error)
	RefreshImage        func(context.Context, dom.NodeID) (ImageState, error)
	ReadImage           func(dom.NodeID) ImageState
	ImageEventDelivered func(dom.NodeID)
	Media               MediaEnvironment
	RequestFrame        func()
	FrameScope          func(time.Time, func())
	ConsoleLog          func(message string)
	ConsoleRecord       func(level, message string)
	RuntimeFailure      func(error)
	Frames              []FrameAccess
	FrameMutation       func(frameID, generation uint64, document dom.DocumentSnapshot) error
	FramePolicy         FramePolicy
	Window              WindowContext
	PostMessage         func(target WindowReference, targetOrigin string, payload []byte) error
	ServiceWorker       *ServiceWorkerHost
}

Environment はRuntimeへ公開するページの状態を保持する。

type Factory

type Factory func() Runtime

Factory はページごとに独立したRuntimeを生成する。

type FrameAccess added in v0.14.0

type FrameAccess struct {
	ID         uint64
	ElementID  dom.NodeID
	Generation uint64
	Origin     string
	URL        string
	SameOrigin bool
	Document   *dom.Document
}

FrameAccess is the least-privilege view of one direct child browsing context. Document is present only while same-origin access is allowed.

type FramePolicy added in v0.14.0

type FramePolicy struct {
	Sandboxed                      bool
	AllowScripts                   bool
	AllowSameOrigin                bool
	AllowForms                     bool
	AllowPopups                    bool
	AllowTopNavigationByActivation bool
}

FramePolicy contains the capabilities granted by an iframe sandbox. A non-sandboxed context keeps the historical unrestricted behavior.

func (FramePolicy) AllowsForms added in v0.14.0

func (policy FramePolicy) AllowsForms() bool

AllowsForms reports whether form submission is enabled.

func (FramePolicy) AllowsPopups added in v0.14.0

func (policy FramePolicy) AllowsPopups() bool

AllowsPopups reports whether creation of auxiliary browsing contexts is enabled.

func (FramePolicy) AllowsScripts added in v0.14.0

func (policy FramePolicy) AllowsScripts() bool

AllowsScripts reports whether page code may be evaluated.

func (FramePolicy) AllowsTopNavigation added in v0.14.0

func (policy FramePolicy) AllowsTopNavigation(userActivated bool) bool

AllowsTopNavigation reports whether a user-activated top navigation is enabled.

func (FramePolicy) HasOpaqueOrigin added in v0.14.0

func (policy FramePolicy) HasOpaqueOrigin() bool

HasOpaqueOrigin reports whether the context has a unique opaque origin.

type FrameUpdater added in v0.14.0

type FrameUpdater interface {
	UpdateFrames([]FrameAccess)
}

FrameUpdater receives generation-scoped child Frame access changes.

type ImageState added in v0.15.0

type ImageState struct {
	URL                         string
	NaturalWidth, NaturalHeight float32
	Complete, Loaded, Deferred  bool
	Error                       string
}

ImageState is the browser-owned lifecycle snapshot exposed by HTMLImageElement.

type LocationUpdater added in v0.9.0

type LocationUpdater interface {
	UpdateLocation(*url.URL)
}

LocationUpdater はsame-document Navigationを現在Runtimeへ通知する。

type MediaEnvironment added in v0.15.0

type MediaEnvironment struct {
	ViewportWidth, ViewportHeight float32
	ColorScheme                   string
	Hover                         bool
	Pointer                       string
	ReducedMotion                 bool
}

MediaEnvironment is the browser-owned input used by matchMedia.

type MediaEnvironmentUpdater added in v0.15.0

type MediaEnvironmentUpdater interface {
	UpdateMediaEnvironment(MediaEnvironment)
}

MediaEnvironmentUpdater receives browser preference and viewport changes.

type MessageDispatcher added in v0.14.0

type MessageDispatcher interface {
	DispatchMessage(MessageEvent) error
}

MessageDispatcher receives one postMessage event on the Page queue.

type MessageEvent added in v0.14.0

type MessageEvent struct {
	Data   []byte
	Origin string
	Source WindowReference
}

MessageEvent is a bounded serialized structured-clone subset.

type NavigationEventDispatcher interface {
	DispatchPopState(state string)
	DispatchHashChange(oldURL, newURL string)
}

NavigationEventDispatcher はNavigation Eventを現在Runtimeへ配送する。

type RenderSnapshot added in v0.15.0

type RenderSnapshot struct {
	Revision     uint64            `json:"revision"`
	Style        map[string]string `json:"style,omitempty"`
	Rect         DOMRect           `json:"rect"`
	ClientWidth  float32           `json:"clientWidth"`
	ClientHeight float32           `json:"clientHeight"`
	ScrollWidth  float32           `json:"scrollWidth"`
	ScrollHeight float32           `json:"scrollHeight"`
}

RenderSnapshot is one browser-produced CSSOM and geometry read tied to one immutable Style/Layout revision.

type Runtime

type Runtime interface {
	Load(ctx context.Context, scripts []Script, environment Environment) error
	Start(ctx context.Context) error
	Stop() error
}

Runtime は1ページに属するGoスクリプトを実行する。

type SandboxReporter added in v0.14.0

type SandboxReporter interface {
	SandboxStatus() SandboxStatus
}

SandboxReporter is implemented by runtimes that verify an out-of-process sandbox before evaluating page code.

type SandboxStatus added in v0.14.0

type SandboxStatus struct {
	Generation         uint64   `json:"generation,omitempty"`
	Platform           string   `json:"platform"`
	Ready              bool     `json:"ready"`
	ProcessBoundary    bool     `json:"processBoundary"`
	BrokeredHostIO     bool     `json:"brokeredHostIo"`
	MinimalEnvironment bool     `json:"minimalEnvironment"`
	ParentLifecycle    bool     `json:"parentLifecycle"`
	MemoryLimitBytes   int64    `json:"memoryLimitBytes"`
	Constraints        []string `json:"constraints,omitempty"`
	Failure            string   `json:"failure,omitempty"`
}

SandboxStatus reports the process boundary that was verified before page code was accepted by a Runtime. Constraints only contains OS controls that the worker actually applied; optional controls are never treated as required.

type Script

type Script struct {
	Engine        Engine
	Kind          ScriptKind
	SourceURL     *url.URL
	Source        string
	Inline        bool
	Integrity     string
	CrossOrigin   string
	Schedule      ScriptSchedule
	DocumentOrder int
	FetchOrder    int
}

Script は文書内で見つかった1つの実行ソースを表す。

type ScriptKind added in v0.14.0

type ScriptKind string

ScriptKind distinguishes classic scripts from ECMAScript modules.

type ScriptSchedule added in v0.14.0

type ScriptSchedule string

ScriptSchedule identifies when a classic script participates in document loading. The zero value is parser-blocking for compatibility.

type ServiceWorkerHost added in v0.14.0

type ServiceWorkerHost struct {
	Register         func(scriptURL, scope string) (ServiceWorkerRegistration, error)
	Update           func(scope string) (ServiceWorkerRegistration, error)
	Unregister       func(scope string) (bool, error)
	GetRegistration  func(clientURL string) (*ServiceWorkerRegistration, error)
	GetRegistrations func() ([]ServiceWorkerRegistration, error)
	Controller       func() *ServiceWorkerRegistration
}

ServiceWorkerHost keeps registration policy and network I/O in the Browser.

type ServiceWorkerRegistration added in v0.14.0

type ServiceWorkerRegistration struct {
	ID                  uint64
	Generation          uint64
	Scope               string
	ScriptURL           string
	InstallingScriptURL string
	WaitingScriptURL    string
	ActiveScriptURL     string
	Installing          ServiceWorkerState
	Waiting             ServiceWorkerState
	Active              ServiceWorkerState
	Claimed             bool
}

ServiceWorkerRegistration is a serializable view of one scope registration.

type ServiceWorkerState added in v0.14.0

type ServiceWorkerState string

ServiceWorkerState is the lifecycle state exposed to JavaScript pages.

const (
	ServiceWorkerInstalling ServiceWorkerState = "installing"
	ServiceWorkerInstalled  ServiceWorkerState = "installed"
	ServiceWorkerActivating ServiceWorkerState = "activating"
	ServiceWorkerActivated  ServiceWorkerState = "activated"
	ServiceWorkerRedundant  ServiceWorkerState = "redundant"
)

type WindowContext added in v0.14.0

type WindowContext struct {
	Self     WindowReference
	Parent   WindowReference
	Top      WindowReference
	Children []WindowReference
}

WindowContext defines the self, parent, top, and direct child relationships.

type WindowReference added in v0.14.0

type WindowReference struct {
	ID         uint64
	Generation uint64
	Origin     string
	URL        string
	SameOrigin bool
}

WindowReference identifies one generation of a browsing context without exposing cross-origin DOM state.

type WindowUpdater added in v0.14.0

type WindowUpdater interface {
	UpdateWindow(WindowContext)
}

WindowUpdater refreshes generation-scoped child WindowProxy relationships.

Directories

Path Synopsis
Package isolated runs Growse page runtimes behind a bounded child-process protocol.
Package isolated runs Growse page runtimes behind a bounded child-process protocol.
Package javascript implements the page-scoped Growse JavaScript Runtime.
Package javascript implements the page-scoped Growse JavaScript Runtime.
Package workerproto defines the bounded wire format shared by the browser broker and isolated runtime workers.
Package workerproto defines the bounded wire format shared by the browser broker and isolated runtime workers.
Package yaegi はYaegiを使ったGrowseページのRuntimeを実装する。
Package yaegi はYaegiを使ったGrowseページのRuntimeを実装する。

Jump to

Keyboard shortcuts

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