chromium

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 9 Imported by: 0

README

Chromium

codecov

A wrapper package for go-rod/rod

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ElementMissing = errors.New("element missing")
	InputFailed    = errors.New("input failed")
	WaitFailed     = errors.New("wait failed")
	ClickFailed    = errors.New("click failed")
	TaskTimeout    = errors.New("task timeout")
)

Functions

This section is empty.

Types

type Browser

type Browser struct {
	*rod.Browser
	// contains filtered or unexported fields
}

Browser is a wrapper that embeds rod.Browser instance

func NewBrowser

func NewBrowser(pagePoolSize int) (*Browser, error)

NewBrowser returns new browser with given pool size. Note that the pagePoolSize cannot be changed after the initialization.

func NewBrowserWithProxy

func NewBrowserWithProxy(pagePoolSize int, proxy string) (*Browser, error)

NewBrowserWithProxy returns new browser with given pool size and proxy. Note that the pagePoolSize and proxy cannot be changed after the initialization.

func (*Browser) CleanUp

func (b *Browser) CleanUp()

CleanUp wait then wipe all resources under this browser instance.

func (*Browser) GetPage

func (b *Browser) GetPage() *Page

GetPage return a page from this Browser's page pool. Note that it will block until a page is available from the pool. It is required for a caller to put back the page to the pool via PutPage function.

func (*Browser) PutPage

func (b *Browser) PutPage(p *Page)

PutPage puts a page back to the browser's page pool. Note that GetPage will be blocked until there is a page available from the pool. By putting a page via this function will ensure next page resource to be served from a caller of GetPage function.

type Page

type Page struct {
	*rod.Page
	// contains filtered or unexported fields
}

func (*Page) CleanUp

func (p *Page) CleanUp()

CleanUp calls page done once and only once, signalling Browser such that the page is actually closed.

func (*Page) ClickNavigate

func (p *Page) ClickNavigate(selector string, timeout time.Duration) error

ClickNavigate clicks an element that is matching the given selector as criteria.

func (*Page) Dialogs

func (p *Page) Dialogs() []*proto.PageJavascriptDialogOpening

Dialogs returns history of current page's dialogs.

func (*Page) HasElement

func (p *Page) HasElement(selector string) (*rod.Element, error)

HasElement checks if any element matching the given selector. If exists, will return an element with no error, or vise versa.

func (*Page) SaveDialog

func (p *Page) SaveDialog(d *proto.PageJavascriptDialogOpening)

SaveDialog appends given proto.PageJavascriptDialogOpening to current page's dialog history.

func (*Page) TryInput

func (p *Page) TryInput(selector, text string) error

TryInput is a conjunction of Page.WaitVisibleElement and *rod.Element's Input function. It will propagate any error from subsequent actions by immediately returning that non-nil error. It will return error as nil if the action has been successfully executed.

func (*Page) TryNavigate

func (p *Page) TryNavigate(url string, predicate Predicate[*Page], backoff time.Duration) error

TryNavigate is a safe-guarding method of navigation with indefinite retry. Need of this navigation arose when navigation is succeeded with 2XX with blank HTML response. Logic to determine whether the navigation succeeded or not depends on Predicate for given Page.

func (*Page) WaitJSObject

func (p *Page) WaitJSObject(objName string) error

func (*Page) WaitJSObjectFor

func (p *Page) WaitJSObjectFor(objName string, until time.Duration) error

WaitJSObjectFor enforces this page to await for specified JavaScript Object to be loaded to given page, for specified time duration. It will wait for the item by each depth for the name by dot delimiter.

func (*Page) WaitVisibleElement

func (p *Page) WaitVisibleElement(selector string) (el *rod.Element, err error)

WaitVisibleElement is a shortcut for search and wait for element to be visible (i.e. interact-ready) Any failure from child action will be propagated. Will return an element with no error on success, otherwise will return nil with error for failing reason.

type PagePool

type PagePool chan *Page

func (PagePool) CleanUp

func (p PagePool) CleanUp()

func (PagePool) Get

func (p PagePool) Get() *Page

func (PagePool) Put

func (p PagePool) Put(page *Page)

type Predicate

type Predicate[T any] func(item T) bool

Predicate is a generic function that examines an item of type T matches or not, mainly to delegate logic for switch.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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