rt

package
v0.4.15 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

runtime globals and utilities.

Index

Constants

Variables

View Source
var (
	ErrNotUnique = fmt.Errorf("value is not unique")
	ErrNilFilter = fmt.Errorf("cannot use a nil Unique filter")
)
View Source
var Errorf func(format string, args ...any)

Set these hooks to capture runtime errors orlog messages. If not set, will report to stdout.

View Source
var Logf func(format string, args ...any)
View Source
var SLOW_DELAY = 1 * time.Second

Default duration when SLOW is requested with invalid millis expression. Can be adjusted before running a request calling SLOW. Use for debugging only.

Functions

func Click

func Click(el *Element, which InputMouseButton, count int)

Click on an element. Use which to choose from "left", "right" or "middle" (default left). Use count to specify number of clicks (defaults 1).

func ClosePage

func ClosePage(page *Page) error

close page, set page pointer to nil on success.

func GetAttribute added in v0.4.9

func GetAttribute(el *Element, att string) string

Retrieve attribute from element. Return empty string on error.

func GetElemText added in v0.4.9

func GetElemText(elem *Element) string

Get text for element. Never wait, never fail. Return "" if error.

func GetPageText added in v0.4.9

func GetPageText(page *Page) string

Return string content of the html element in page, or "" if error. Never abort, never wait.

func GetText

func GetText(el *Element) string

Retrieve text from a *rod.Element. Return empty string if not found.

func Input

func Input(el *Element, txt string)

Input a txt in an element, after selecting and focusing on it.

func InputFrom

func InputFrom(css string, txt string, pageOrElement Elementer)

Select an element and input a txt in it.

func MustSerialize added in v0.4.9

func MustSerialize(a any) string

See Serialize. Panic on error.

func NewSelectAllIterator

func NewSelectAllIterator[T Elementer](ctx context.Context, pageOrElement T, css string, limit int, xpath bool) *selectAllIteratorP

func Pages added in v0.4.14

func Pages() ([]any, error)

Get the array of opened pages. Note : returns a GSC array ([]any), not a []*rod.Page array.

func SafeSprintf added in v0.4.9

func SafeSprintf(format string, a ...any) (result string, err error)

SafePrintf is like Sprintf, but return runtime formatting errors without panic

func Serialize added in v0.4.9

func Serialize(a any) (string, error)

Serialize a value to string, using the GSC syntax. Only values produced by GSC itself can be serialized. Maps keys are sorted to guarantee determistic serialization. Non recognized values will trigger an error.

func SetBrowserDataDir

func SetBrowserDataDir(dir string) (err error)

The directory to save brawser internal states into (cookies, etc ...)

func SetHeadless

func SetHeadless(h bool) error

Set browser in headless mode. Browser should not have started already.

func SetIgnore

func SetIgnore(patt ...string) error

Which requests patterns will always be ignored. Eg : ".jpeg", ".png", ...

Types

type Browser added in v0.4.9

type Browser = rod.Browser

defining type alias to decouple from actual driver.

func GetBrowser

func GetBrowser() *Browser

Threadsafe and lazy access to the browser singleton.

type Element added in v0.4.9

type Element = rod.Element

defining type alias to decouple from actual driver.

type Elementer

type Elementer interface {
	Elements(string) (Elements, error)
	ElementsX(string) (Elements, error)
	Element(string) (*Element, error)
	ElementX(string) (*Element, error)
}

Elementer can provide Elements or Element. Typically, a page or an element.

type Elements added in v0.4.9

type Elements = rod.Elements

defining type alias to decouple from actual driver.

type Hash added in v0.4.9

type Hash [md5.Size]byte

Hash type (an array, not a slice)

func HashGSC added in v0.4.9

func HashGSC(a any) (Hash, error)

Compute the Hash of any GSC serializable value. Error if a cannot be GSC-serializable.

type InputMouseButton added in v0.4.9

type InputMouseButton = proto.InputMouseButton

defining type alias to decouple from actual driver.

type Iterator

type Iterator[T any] interface {
	Next() (next T, ok bool)
}

Generic iterator interface

func NewForLoopIterator added in v0.4.9

func NewForLoopIterator(from, to, step int) Iterator[int]

No enforcing on dangerous values, such as step = 0. May loop forever. It is not a bug, but a feature ;-).

func NewForLoopIteratorSafe added in v0.4.9

func NewForLoopIteratorSafe(from, to, step int) Iterator[int]

Same, but adjusts provided values to ensure no endless loops and positive direction.

type Page added in v0.4.9

type Page = rod.Page

defining type alias to decouple from actual driver.

func GetPage

func GetPage(ctx context.Context, url string) *Page

Get a new page. Use empty string for empty page. Browser is started if not already available.

type Unique added in v0.4.9

type Unique struct {
	// contains filtered or unexported fields
}

Uniqueness filter, using a GSC Hash. Use u := new(Unique) to initialize it. Typically for RETURN DISTINCT. For rod.Element, you may prefer using element.Equal(element) to comprare actual DOM elements in browser.

func (*Unique) Add added in v0.4.9

func (u *Unique) Add(a any) error

Add a value to the uniqueness filter. Return error if value was already there, or cannot be serialized.

Jump to

Keyboard shortcuts

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