drivers

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Event indicating to wait for value to appear
	WaitEventPresence = 0

	// Event indicating to wait for value to disappear
	WaitEventAbsence = 1
)
View Source
const DefaultTimeout = time.Second * 30

Variables

View Source
var (
	HTTPHeaderType   = core.NewType("HTTPHeader")
	HTTPCookieType   = core.NewType("HTTPCookie")
	HTMLElementType  = core.NewType("HTMLElement")
	HTMLDocumentType = core.NewType("HTMLDocument")
)

Functions

func Compare added in v0.7.0

func Compare(first, second core.Type) int64

func IsScreenshotFormatValid added in v0.7.0

func IsScreenshotFormatValid(format string) bool

func WithContext added in v0.7.0

func WithContext(ctx context.Context, drv Driver, opts ...Option) context.Context

func WithDefaultTimeout added in v0.7.0

func WithDefaultTimeout(ctx context.Context) (context.Context, context.CancelFunc)

Types

type Driver added in v0.7.0

type Driver interface {
	io.Closer
	Name() string
	LoadDocument(ctx context.Context, params LoadDocumentParams) (HTMLDocument, error)
}

func FromContext added in v0.7.0

func FromContext(ctx context.Context, name string) (Driver, error)

type HTMLDocument added in v0.7.0

type HTMLDocument interface {
	HTMLNode

	DocumentElement() HTMLElement

	GetURL() core.Value

	SetURL(ctx context.Context, url values.String) error

	GetCookies(ctx context.Context) (*values.Array, error)

	SetCookies(ctx context.Context, cookies ...HTTPCookie) error

	DeleteCookies(ctx context.Context, cookies ...HTTPCookie) error

	Navigate(ctx context.Context, url values.String) error

	NavigateBack(ctx context.Context, skip values.Int) (values.Boolean, error)

	NavigateForward(ctx context.Context, skip values.Int) (values.Boolean, error)

	ClickBySelector(ctx context.Context, selector values.String) (values.Boolean, error)

	ClickBySelectorAll(ctx context.Context, selector values.String) (values.Boolean, error)

	InputBySelector(ctx context.Context, selector values.String, value core.Value, delay values.Int) (values.Boolean, error)

	SelectBySelector(ctx context.Context, selector values.String, value *values.Array) (*values.Array, error)

	PrintToPDF(ctx context.Context, params PDFParams) (values.Binary, error)

	CaptureScreenshot(ctx context.Context, params ScreenshotParams) (values.Binary, error)

	ScrollTop(ctx context.Context) error

	ScrollBottom(ctx context.Context) error

	ScrollBySelector(ctx context.Context, selector values.String) error

	ScrollByXY(ctx context.Context, x, y values.Float) error

	MoveMouseByXY(ctx context.Context, x, y values.Float) error

	MoveMouseBySelector(ctx context.Context, selector values.String) error

	WaitForNavigation(ctx context.Context) error

	WaitForElement(ctx context.Context, selector values.String, when WaitEvent) error

	WaitForAttributeBySelector(ctx context.Context, selector, name values.String, value core.Value, when WaitEvent) error

	WaitForAttributeBySelectorAll(ctx context.Context, selector, name values.String, value core.Value, when WaitEvent) error

	WaitForStyleBySelector(ctx context.Context, selector, name values.String, value core.Value, when WaitEvent) error

	WaitForStyleBySelectorAll(ctx context.Context, selector, name values.String, value core.Value, when WaitEvent) error

	WaitForClassBySelector(ctx context.Context, selector, class values.String, when WaitEvent) error

	WaitForClassBySelectorAll(ctx context.Context, selector, class values.String, when WaitEvent) error
}

The Document interface represents any web page loaded in the browser and serves as an entry point into the web page's content, which is the DOM tree.

type HTMLElement added in v0.7.0

type HTMLElement interface {
	HTMLNode

	InnerText(ctx context.Context) values.String

	InnerHTML(ctx context.Context) values.String

	GetValue(ctx context.Context) core.Value

	SetValue(ctx context.Context, value core.Value) error

	GetStyles(ctx context.Context) (*values.Object, error)

	GetStyle(ctx context.Context, name values.String) (core.Value, error)

	SetStyles(ctx context.Context, values *values.Object) error

	SetStyle(ctx context.Context, name values.String, value core.Value) error

	RemoveStyle(ctx context.Context, name ...values.String) error

	GetAttributes(ctx context.Context) *values.Object

	GetAttribute(ctx context.Context, name values.String) core.Value

	SetAttributes(ctx context.Context, values *values.Object) error

	SetAttribute(ctx context.Context, name, value values.String) error

	RemoveAttribute(ctx context.Context, name ...values.String) error

	InnerHTMLBySelector(ctx context.Context, selector values.String) values.String

	InnerHTMLBySelectorAll(ctx context.Context, selector values.String) *values.Array

	InnerTextBySelector(ctx context.Context, selector values.String) values.String

	InnerTextBySelectorAll(ctx context.Context, selector values.String) *values.Array

	Click(ctx context.Context) (values.Boolean, error)

	Input(ctx context.Context, value core.Value, delay values.Int) error

	Select(ctx context.Context, value *values.Array) (*values.Array, error)

	ScrollIntoView(ctx context.Context) error

	Hover(ctx context.Context) error

	WaitForAttribute(ctx context.Context, name values.String, value core.Value, when WaitEvent) error

	WaitForStyle(ctx context.Context, name values.String, value core.Value, when WaitEvent) error

	WaitForClass(ctx context.Context, class values.String, when WaitEvent) error
}

HTMLElement is the most general base interface which most objects in a Document implement.

type HTMLNode added in v0.7.0

type HTMLNode interface {
	core.Value
	core.Iterable
	core.Getter
	core.Setter
	collections.Measurable
	io.Closer

	NodeType() values.Int

	NodeName() values.String

	GetChildNodes(ctx context.Context) core.Value

	GetChildNode(ctx context.Context, idx values.Int) core.Value

	QuerySelector(ctx context.Context, selector values.String) core.Value

	QuerySelectorAll(ctx context.Context, selector values.String) core.Value

	CountBySelector(ctx context.Context, selector values.String) values.Int

	ExistsBySelector(ctx context.Context, selector values.String) values.Boolean
}

Node is an interface from which a number of DOM API object types inherit. It allows those types to be treated similarly; for example, inheriting the same set of methods, or being tested in the same way.

type HTTPCookie added in v0.7.0

type HTTPCookie struct {
	Name     string
	Value    string
	Path     string
	Domain   string
	Expires  time.Time
	MaxAge   int
	Secure   bool
	HTTPOnly bool
	SameSite SameSite
}

HTTPCookie HTTPCookie object

func (HTTPCookie) Compare added in v0.7.0

func (c HTTPCookie) Compare(other core.Value) int64

func (HTTPCookie) Copy added in v0.7.0

func (c HTTPCookie) Copy() core.Value

func (HTTPCookie) GetIn added in v0.7.0

func (c HTTPCookie) GetIn(_ context.Context, path []core.Value) (core.Value, error)

func (HTTPCookie) Hash added in v0.7.0

func (c HTTPCookie) Hash() uint64

func (HTTPCookie) MarshalJSON added in v0.7.0

func (c HTTPCookie) MarshalJSON() ([]byte, error)

func (HTTPCookie) String added in v0.7.0

func (c HTTPCookie) String() string

func (HTTPCookie) Type added in v0.7.0

func (c HTTPCookie) Type() core.Type

func (HTTPCookie) Unwrap added in v0.7.0

func (c HTTPCookie) Unwrap() interface{}

type HTTPHeader added in v0.7.0

type HTTPHeader map[string][]string

HTTPCookie HTTPCookie object

func (HTTPHeader) Compare added in v0.7.0

func (h HTTPHeader) Compare(other core.Value) int64

func (HTTPHeader) Copy added in v0.7.0

func (h HTTPHeader) Copy() core.Value

func (HTTPHeader) Get added in v0.7.0

func (h HTTPHeader) Get(key string) string

func (HTTPHeader) GetIn added in v0.7.0

func (h HTTPHeader) GetIn(_ context.Context, path []core.Value) (core.Value, error)

func (HTTPHeader) Hash added in v0.7.0

func (h HTTPHeader) Hash() uint64

func (HTTPHeader) MarshalJSON added in v0.7.0

func (h HTTPHeader) MarshalJSON() ([]byte, error)

func (HTTPHeader) Set added in v0.7.0

func (h HTTPHeader) Set(key, value string)

func (HTTPHeader) String added in v0.7.0

func (h HTTPHeader) String() string

func (HTTPHeader) Type added in v0.7.0

func (h HTTPHeader) Type() core.Type

func (HTTPHeader) Unwrap added in v0.7.0

func (h HTTPHeader) Unwrap() interface{}

type LoadDocumentParams added in v0.7.0

type LoadDocumentParams struct {
	URL         string
	UserAgent   string
	KeepCookies bool
	Cookies     []HTTPCookie
	Header      HTTPHeader
}

type Option added in v0.7.0

type Option func(drv Driver, opts *options)

func AsDefault added in v0.7.0

func AsDefault() Option

type PDFParams added in v0.7.0

type PDFParams struct {
	// Paper orientation. Defaults to false.
	Landscape values.Boolean
	// Display values and footer. Defaults to false.
	DisplayHeaderFooter values.Boolean
	// Print background graphics. Defaults to false.
	PrintBackground values.Boolean
	// Scale of the webpage rendering. Defaults to 1.
	Scale values.Float
	// Paper width in inches. Defaults to 8.5 inches.
	PaperWidth values.Float
	// Paper height in inches. Defaults to 11 inches.
	PaperHeight values.Float
	// Top margin in inches. Defaults to 1cm (~0.4 inches).
	MarginTop values.Float
	// Bottom margin in inches. Defaults to 1cm (~0.4 inches).
	MarginBottom values.Float
	// Left margin in inches. Defaults to 1cm (~0.4 inches).
	MarginLeft values.Float
	// Right margin in inches. Defaults to 1cm (~0.4 inches).
	MarginRight values.Float
	// Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
	PageRanges values.String
	// Whether to silently ignore invalid but successfully parsed page ranges, such as '3-2'. Defaults to false.
	IgnoreInvalidPageRanges values.Boolean
	// HTML template for the print values. Should be valid HTML markup with following classes used to inject printing values into them: - `date`: formatted print date - `title`: document title - `url`: document location - `pageNumber`: current page number - `totalPages`: total pages in the document
	// For example, `<span class=title></span>` would generate span containing the title.
	HeaderTemplate values.String
	// HTML template for the print footer. Should use the same format as the `headerTemplate`.
	FooterTemplate values.String
	// Whether or not to prefer page size as defined by css.
	// Defaults to false, in which case the content will be scaled to fit the paper size.
	PreferCSSPageSize values.Boolean
}

PDFParams represents the arguments for PrintToPDF function.

func NewDefaultHTMLPDFParams added in v0.7.0

func NewDefaultHTMLPDFParams() PDFParams

type SameSite added in v0.7.0

type SameSite int

Polyfill for Go 1.10

const (
	SameSiteDefaultMode SameSite = iota + 1
	SameSiteLaxMode
	SameSiteStrictMode
)

type ScreenshotFormat added in v0.7.0

type ScreenshotFormat string
const (
	ScreenshotFormatPNG  ScreenshotFormat = "png"
	ScreenshotFormatJPEG ScreenshotFormat = "jpeg"
)

type ScreenshotParams added in v0.7.0

type ScreenshotParams struct {
	X       values.Float
	Y       values.Float
	Width   values.Float
	Height  values.Float
	Format  ScreenshotFormat
	Quality values.Int
}

type WaitEvent added in v0.7.0

type WaitEvent int

WaitEvent is an enum that represents what event is needed to wait for

Directories

Path Synopsis
cdp

Jump to

Keyboard shortcuts

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