browser

package
v0.0.0-...-731e79c Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Attr

type Attr interface {
	Node
	LocalName() string
	Name() string
	NamespaceURI() string
	OwnerElement() Element
	Prefix() string
	GetValue() string
	SetValue(val string)
}

type Attributes

type Attributes []*html.Attribute

TODO: In the DOM, this is a `NamedNodeMap`. Is that useful in Go?

func (Attributes) Length

func (attrs Attributes) Length() int

type Browser

type Browser struct {
	Client              http.Client
	ScriptEngine        ScriptEngine
	ScriptEngineFactory ScriptEngineFactory
}

Pretty stupid right now, but should _probably_ allow handling multiple windows/tabs. Particularly if testing login flow; where the login

func NewBrowserFromHandler

func NewBrowserFromHandler(handler http.Handler) Browser

func (Browser) Open

func (b Browser) Open(url string) Document

TODO: Delete

func (Browser) OpenWindow

func (b Browser) OpenWindow(location string) (Window, error)

TODO: Rename to Open

type CSSHelper

type CSSHelper struct{ Node }

func (CSSHelper) QuerySelector

func (h CSSHelper) QuerySelector(pattern string) (Node, error)

func (CSSHelper) QuerySelectorAll

func (d CSSHelper) QuerySelectorAll(pattern string) (StaticNodeList, error)

type CustomEvent

type CustomEvent interface {
	Event
}

func NewCustomEvent

func NewCustomEvent(eventType string) CustomEvent

type Document

type Document interface {
	RootNode
	Body() Element
	Head() Element
	CreateDocumentFragment() DocumentFragment
	CreateElement(string) Element
	DocumentElement() Element
	// contains filtered or unexported methods
}

func NewDocument

func NewDocument() Document

func ParseHtmlStream

func ParseHtmlStream(s io.Reader) Document

func ParseHtmlString

func ParseHtmlString(s string) Document

type DocumentEvent

type DocumentEvent = string
const (
	DocumentEventDOMContentLoaded DocumentEvent = "DOMContentLoaded"
	DocumentEventLoad             DocumentEvent = "load"
)

type DocumentFragment

type DocumentFragment interface {
	RootNode
}

func NewDocumentFragment

func NewDocumentFragment(ownerDocument Document) DocumentFragment

type Element

type Element interface {
	ElementContainer
	Append(Element) Element
	GetAttribute(name string) string
	SetAttribute(name string, value string)
	GetAttributes() NamedNodeMap
	InsertAdjacentHTML(position string, text string) error
	OuterHTML() string
	TagName() string
	// contains filtered or unexported methods
}

An Element in the document. Can be either an HTMLElement or an [XMLElement]

func NewElement

func NewElement(tagName string, ownerDocument Document) Element

func NewHTMLElement

func NewHTMLElement(node *html.Node, ownerDocument Document) Element

func NewHTMLHtmlElement

func NewHTMLHtmlElement(node *html.Node, ownerDocument Document) Element

func NewHTMLUnknownElement

func NewHTMLUnknownElement(node *html.Node, ownerDocument Document) Element

type ElementContainer

type ElementContainer interface {
	Node
	Append(Element) Element
	QuerySelector(string) (Node, error)
	QuerySelectorAll(string) (StaticNodeList, error)
}

ElementContainer defines common functionality in Document, DocumentFragment, and Element. While they all have Node as the direct base class in the DOM spec; they share a common set of functions operating on elements

type ElementSteps

type ElementSteps interface {
	Connected(w Window, n Element)
}

type Entity

type Entity interface {
	ObjectId() ObjectId
}

type Event

type Event interface {
	Type() string
}

type EventHandler

type EventHandler interface {
	HandleEvent(event Event) error
	// The interface for removing event handlers requires the caller to pass in
	// the same handler to `RemoveEventListener`. In Go; functions cannot be
	// compared for equality; so we need to have some kind of mechanism to
	// identify if two handlers are identical.
	Equals(other EventHandler) bool
}

EventHandler is the interface for an event handler. In JavaScript; an event handler can be a function; or an object with a `handleEvent` function.

Duplicate detection during _add_, or removal is based on equality. JavaScript equality does not translate natively to Go, so a handler must be able to detect equality by itself

func NewEventHandlerFunc

func NewEventHandlerFunc(handler HandlerFunc) EventHandler

NewEventHandlerFunc creates an EventHandler wrapping a function with the right signature. Calling this twice for the same Go-function will be treated as different event handlers; as Go functions do not support equality.

func NewEventHandlerFuncWithoutError

func NewEventHandlerFuncWithoutError(handler HandlerFuncWithoutError) EventHandler

type EventTarget

type EventTarget interface {
	// ObjectId is used internally for the scripting engine to associate a v8
	// object with the Go object it wraps.
	ObjectId() ObjectId
	AddEventListener(eventType string, listener EventHandler)
	RemoveEventListener(eventType string, listener EventHandler)
	DispatchEvent(event Event) error
}

func NewEventTarget

func NewEventTarget() EventTarget

type HTMLElement

type HTMLElement interface {
	Element
}

type HandlerFunc

type HandlerFunc = func(Event) error

type HandlerFuncWithoutError

type HandlerFuncWithoutError = func(Event)

type HandlerRoundTripper

type HandlerRoundTripper struct{ http.Handler }

func (HandlerRoundTripper) RoundTrip

func (h HandlerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type Location

type Location interface {
	GetHash() string
	GetHost() string
	GetHostname() string
	GetHref() string
	// TODO
	// SetHref(href string)
	GetOrigin() string
	GetPathname() string
	GetPort() string
	GetProtocol() string
	GetSearch() string
}

func NewLocation

func NewLocation(url *url.URL) Location

type NamedNodeMap

type NamedNodeMap interface {
	Entity
	Length() int
	Item(index int) Attr
}

func NewNamedNodeMapForElement

func NewNamedNodeMapForElement(ownerElement Element) NamedNodeMap

type Node

type Node interface {
	EventTarget
	AppendChild(node Node) Node
	ChildNodes() []Node
	Connected() bool
	InsertBefore(newNode Node, referenceNode Node) (Node, error)
	NodeName() string
	NodeType() NodeType
	OwnerDocument() Document // TODO: Element, not Node
	Parent() Node
	RemoveChild(node Node) error
	NextSibling() Node
	// contains filtered or unexported methods
}

func NewTextNode

func NewTextNode(node *html.Node, text string) Node

type NodeHelper

type NodeHelper struct{ Node }

func (NodeHelper) AppendChild

func (n NodeHelper) AppendChild(child Node) Node

func (NodeHelper) InsertBefore

func (n NodeHelper) InsertBefore(newChild Node, referenceNode Node) (Node, error)

type NodeIterator

type NodeIterator struct{ Node }

type NodeType

type NodeType int
const (
	NodeTypeElement               NodeType = 1
	NodeTypeAttribute             NodeType = 2
	NodeTypeText                  NodeType = 3
	NodeTypeCDataSection          NodeType = 4
	NodeTypeProcessingInstruction NodeType = 7
	NodeTypeComment               NodeType = 8
	NodeTypeDocument              NodeType = 9
	NodeTypeDocumentType          NodeType = 10
	NodeTypeDocumentFragment      NodeType = 11
)

type ObjectId

type ObjectId = int32

func NewObjectId

func NewObjectId() ObjectId

type RootNode

type RootNode interface {
	ElementContainer
	GetElementById(string) Element
}

RootNode implements defines common behaviour between Document and DocumentFragment. While they both have Node as the direct base class in the DOM spec; they share a common set of functions operating on elements.

type RootNodeHelper

type RootNodeHelper struct{ RootNode }

func (RootNodeHelper) GetElementById

func (d RootNodeHelper) GetElementById(id string) Element

type ScriptElementRules

type ScriptElementRules struct{}

func (ScriptElementRules) Connected

func (r ScriptElementRules) Connected(win Window, node Element)

type ScriptEngine

type ScriptEngine interface {
	// Run a script, and convert the result to a Go type. This will result in an
	// error if the returned value cannot be represented as a Go type.
	Eval(script string) (any, error)
	// Run a script, ignoring any returned value
	Run(script string) error
}

type ScriptEngineFactory

type ScriptEngineFactory interface {
	NewScriptEngine(window Window) ScriptEngine
}

type ShadowRoot

type ShadowRoot interface {
	DocumentFragment
}

type StaticNodeList

type StaticNodeList []Node

type TextNode

type TextNode interface {
	Node
	Text() string
}

type Window

type Window interface {
	EventTarget
	Document() Document
	// TODO: Remove, for testing
	LoadHTML(string) error
	Eval(string) (any, error)
	Run(string) error
	SetScriptRunner(ScriptEngine)
	Location() Location
}

func NewWindow

func NewWindow(url *url.URL) Window

Jump to

Keyboard shortcuts

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