Documentation ¶
Index ¶
- Constants
- Variables
- func Compare(first, second core.Type) int64
- func IsScreenshotFormatValid(format string) bool
- func WithContext(ctx context.Context, drv Driver, opts ...Option) context.Context
- type Driver
- type HTMLDocument
- type HTMLElement
- type HTMLNode
- type HTMLPage
- type HTTPCookie
- func (c HTTPCookie) Compare(other core.Value) int64
- func (c HTTPCookie) Copy() core.Value
- func (c HTTPCookie) GetIn(_ context.Context, path []core.Value) (core.Value, error)
- func (c HTTPCookie) Hash() uint64
- func (c HTTPCookie) MarshalJSON() ([]byte, error)
- func (c HTTPCookie) String() string
- func (c HTTPCookie) Type() core.Type
- func (c HTTPCookie) Unwrap() interface{}
- type HTTPCookies
- func (c HTTPCookies) Compare(other core.Value) int64
- func (c HTTPCookies) Copy() core.Value
- func (c HTTPCookies) Get(key values.String) (core.Value, values.Boolean)
- func (c HTTPCookies) GetIn(ctx context.Context, path []core.Value) (core.Value, error)
- func (c HTTPCookies) Hash() uint64
- func (c HTTPCookies) Keys() []values.String
- func (c HTTPCookies) Length() values.Int
- func (c HTTPCookies) MarshalJSON() ([]byte, error)
- func (c HTTPCookies) Set(key values.String, value core.Value)
- func (c HTTPCookies) String() string
- func (c HTTPCookies) Type() core.Type
- func (c HTTPCookies) Unwrap() interface{}
- type HTTPHeaders
- func (h HTTPHeaders) Compare(other core.Value) int64
- func (h HTTPHeaders) Copy() core.Value
- func (h HTTPHeaders) Get(key string) string
- func (h HTTPHeaders) GetIn(_ context.Context, path []core.Value) (core.Value, error)
- func (h HTTPHeaders) Hash() uint64
- func (h HTTPHeaders) MarshalJSON() ([]byte, error)
- func (h HTTPHeaders) Set(key, value string)
- func (h HTTPHeaders) String() string
- func (h HTTPHeaders) Type() core.Type
- func (h HTTPHeaders) Unwrap() interface{}
- type HTTPResponse
- func (resp *HTTPResponse) Compare(other core.Value) int64
- func (resp *HTTPResponse) Copy() core.Value
- func (resp *HTTPResponse) GetIn(ctx context.Context, path []core.Value) (core.Value, error)
- func (resp *HTTPResponse) Hash() uint64
- func (resp *HTTPResponse) MarshalJSON() ([]byte, error)
- func (resp *HTTPResponse) String() string
- func (resp *HTTPResponse) Type() core.Type
- func (resp *HTTPResponse) Unwrap() interface{}
- type Option
- type PDFParams
- type Params
- type ParseParams
- type SameSite
- type ScreenshotFormat
- type ScreenshotParams
- type ScrollBehavior
- type ScrollHorizontalAlignment
- type ScrollOptions
- type ScrollVerticalAlignment
- type Viewport
- type WaitEvent
Constants ¶
const ( DefaultPageLoadTimeout = 60000 DefaultWaitTimeout = 5000 DefaultKeyboardDelay = 25 DefaultMouseDelay = 10 DefaultTimeout = 30000 )
const ( // Event indicating to wait for value to appear WaitEventPresence = 0 // Event indicating to wait for value to disappear WaitEventAbsence = 1 )
Variables ¶
var ( ErrDetached = errors.New("element detached") ErrNotFound = errors.New("element(s) not found") )
var ( HTTPResponseType = core.NewType("HTTPResponse") HTTPHeaderType = core.NewType("HTTPHeaders") HTTPCookieType = core.NewType("HTTPCookie") HTTPCookiesType = core.NewType("HTTPCookies") HTMLElementType = core.NewType("HTMLElement") HTMLDocumentType = core.NewType("HTMLDocument") HTMLPageType = core.NewType("HTMLPageType") )
Functions ¶
func IsScreenshotFormatValid ¶ added in v0.7.0
Types ¶
type Driver ¶ added in v0.7.0
type HTMLDocument ¶ added in v0.7.0
type HTMLDocument interface { HTMLNode GetTitle() values.String GetElement() HTMLElement GetURL() values.String GetName() values.String GetParentDocument(ctx context.Context) (HTMLDocument, error) GetChildDocuments(ctx context.Context) (*values.Array, error) ScrollTop(ctx context.Context, options ScrollOptions) error ScrollBottom(ctx context.Context, options ScrollOptions) error ScrollBySelector(ctx context.Context, selector values.String, options ScrollOptions) error ScrollByXY(ctx context.Context, x, y values.Float, options ScrollOptions) error MoveMouseByXY(ctx context.Context, x, y values.Float) 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 }
func ToDocument ¶ added in v0.8.0
func ToDocument(value core.Value) (HTMLDocument, error)
type HTMLElement ¶ added in v0.7.0
type HTMLElement interface { HTMLNode GetInnerText(ctx context.Context) (values.String, error) SetInnerText(ctx context.Context, innerText values.String) error GetInnerHTML(ctx context.Context) (values.String, error) SetInnerHTML(ctx context.Context, innerHTML values.String) error GetValue(ctx context.Context) (core.Value, error) 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, error) GetAttribute(ctx context.Context, name values.String) (core.Value, error) 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 GetInnerHTMLBySelector(ctx context.Context, selector values.String) (values.String, error) SetInnerHTMLBySelector(ctx context.Context, selector, innerHTML values.String) error GetInnerHTMLBySelectorAll(ctx context.Context, selector values.String) (*values.Array, error) GetInnerTextBySelector(ctx context.Context, selector values.String) (values.String, error) SetInnerTextBySelector(ctx context.Context, selector, innerText values.String) error GetInnerTextBySelectorAll(ctx context.Context, selector values.String) (*values.Array, error) Click(ctx context.Context, count values.Int) error ClickBySelector(ctx context.Context, selector values.String, count values.Int) error ClickBySelectorAll(ctx context.Context, selector values.String, count values.Int) error Clear(ctx context.Context) error ClearBySelector(ctx context.Context, selector values.String) error Input(ctx context.Context, value core.Value, delay values.Int) error InputBySelector(ctx context.Context, selector values.String, value core.Value, delay values.Int) error Select(ctx context.Context, value *values.Array) (*values.Array, error) SelectBySelector(ctx context.Context, selector values.String, value *values.Array) (*values.Array, error) ScrollIntoView(ctx context.Context, options ScrollOptions) error Focus(ctx context.Context) error FocusBySelector(ctx context.Context, selector values.String) error Blur(ctx context.Context) error BlurBySelector(ctx context.Context, selector values.String) error Hover(ctx context.Context) error HoverBySelector(ctx context.Context, selector values.String) 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 GetMainFrame implement.
type HTMLNode ¶ added in v0.7.0
type HTMLNode interface { core.Value core.Iterable core.Getter core.Setter collections.Measurable io.Closer IsDetached() values.Boolean GetNodeType() values.Int GetNodeName() values.String GetChildNodes(ctx context.Context) (*values.Array, error) GetChildNode(ctx context.Context, idx values.Int) (core.Value, error) QuerySelector(ctx context.Context, selector values.String) (core.Value, error) QuerySelectorAll(ctx context.Context, selector values.String) (*values.Array, error) CountBySelector(ctx context.Context, selector values.String) (values.Int, error) ExistsBySelector(ctx context.Context, selector values.String) (values.Boolean, error) XPath(ctx context.Context, expression values.String) (core.Value, error) }
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 HTMLPage ¶ added in v0.8.0
type HTMLPage interface { core.Value core.Iterable core.Getter core.Setter collections.Measurable io.Closer IsClosed() values.Boolean GetURL() values.String GetMainFrame() HTMLDocument GetFrames(ctx context.Context) (*values.Array, error) GetFrame(ctx context.Context, idx values.Int) (core.Value, error) GetCookies(ctx context.Context) (HTTPCookies, error) SetCookies(ctx context.Context, cookies HTTPCookies) error DeleteCookies(ctx context.Context, cookies HTTPCookies) error GetResponse(ctx context.Context) (HTTPResponse, error) PrintToPDF(ctx context.Context, params PDFParams) (values.Binary, error) CaptureScreenshot(ctx context.Context, params ScreenshotParams) (values.Binary, error) }
HTMLPage interface represents any web page loaded in the browser and serves as an entry point into the web page's content
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) Copy ¶ added in v0.7.0
func (c HTTPCookie) Copy() core.Value
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 HTTPCookies ¶ added in v0.9.0
type HTTPCookies map[string]HTTPCookie
func NewHTTPCookies ¶ added in v0.10.0
func NewHTTPCookies() HTTPCookies
func (HTTPCookies) Copy ¶ added in v0.10.0
func (c HTTPCookies) Copy() core.Value
func (HTTPCookies) Hash ¶ added in v0.10.0
func (c HTTPCookies) Hash() uint64
func (HTTPCookies) Keys ¶ added in v0.10.0
func (c HTTPCookies) Keys() []values.String
func (HTTPCookies) Length ¶ added in v0.10.0
func (c HTTPCookies) Length() values.Int
func (HTTPCookies) MarshalJSON ¶ added in v0.10.0
func (c HTTPCookies) MarshalJSON() ([]byte, error)
func (HTTPCookies) Set ¶ added in v0.10.0
func (c HTTPCookies) Set(key values.String, value core.Value)
func (HTTPCookies) String ¶ added in v0.10.0
func (c HTTPCookies) String() string
func (HTTPCookies) Type ¶ added in v0.10.0
func (c HTTPCookies) Type() core.Type
func (HTTPCookies) Unwrap ¶ added in v0.10.0
func (c HTTPCookies) Unwrap() interface{}
type HTTPHeaders ¶ added in v0.8.2
HTTPHeaders HTTP header object
func NewHTTPHeaders ¶ added in v0.8.2
func NewHTTPHeaders(values map[string][]string) HTTPHeaders
func (HTTPHeaders) Copy ¶ added in v0.8.2
func (h HTTPHeaders) Copy() core.Value
func (HTTPHeaders) Get ¶ added in v0.8.2
func (h HTTPHeaders) Get(key string) string
func (HTTPHeaders) Hash ¶ added in v0.8.2
func (h HTTPHeaders) Hash() uint64
func (HTTPHeaders) MarshalJSON ¶ added in v0.8.2
func (h HTTPHeaders) MarshalJSON() ([]byte, error)
func (HTTPHeaders) Set ¶ added in v0.8.2
func (h HTTPHeaders) Set(key, value string)
func (HTTPHeaders) String ¶ added in v0.8.2
func (h HTTPHeaders) String() string
func (HTTPHeaders) Type ¶ added in v0.8.2
func (h HTTPHeaders) Type() core.Type
func (HTTPHeaders) Unwrap ¶ added in v0.8.2
func (h HTTPHeaders) Unwrap() interface{}
type HTTPResponse ¶ added in v0.10.0
type HTTPResponse struct { StatusCode int Status string Headers HTTPHeaders }
HTTPResponse HTTP response object.
func (*HTTPResponse) Compare ¶ added in v0.10.0
func (resp *HTTPResponse) Compare(other core.Value) int64
func (*HTTPResponse) Copy ¶ added in v0.10.0
func (resp *HTTPResponse) Copy() core.Value
func (*HTTPResponse) Hash ¶ added in v0.10.0
func (resp *HTTPResponse) Hash() uint64
func (*HTTPResponse) MarshalJSON ¶ added in v0.10.0
func (resp *HTTPResponse) MarshalJSON() ([]byte, error)
func (*HTTPResponse) String ¶ added in v0.10.0
func (resp *HTTPResponse) String() string
func (*HTTPResponse) Type ¶ added in v0.10.0
func (resp *HTTPResponse) Type() core.Type
func (*HTTPResponse) Unwrap ¶ added in v0.10.0
func (resp *HTTPResponse) Unwrap() interface{}
type PDFParams ¶ added in v0.7.0
type PDFParams struct { // Paper orientation. Defaults to false. Landscape values.Boolean 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 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 Params ¶ added in v0.8.0
type Params struct { URL string UserAgent string KeepCookies bool Cookies HTTPCookies Headers HTTPHeaders Viewport *Viewport }
type ParseParams ¶ added in v0.10.0
type ParseParams struct { Content []byte KeepCookies bool Cookies HTTPCookies Headers HTTPHeaders Viewport *Viewport }
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 ScrollBehavior ¶ added in v0.11.0
type ScrollBehavior int
ScrollBehavior defines the transition animation. In HTML specification, default value is auto, but in Ferret it's instant. More details here https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
const ( ScrollBehaviorInstant ScrollBehavior = 0 ScrollBehaviorSmooth ScrollBehavior = 1 ScrollBehaviorAuto ScrollBehavior = 2 )
func NewScrollBehavior ¶ added in v0.11.0
func NewScrollBehavior(value string) ScrollBehavior
func (ScrollBehavior) String ¶ added in v0.11.0
func (b ScrollBehavior) String() string
type ScrollHorizontalAlignment ¶ added in v0.11.0
type ScrollHorizontalAlignment int
ScrollHorizontalAlignment defines horizontal alignment after scrolling. In HTML specification, default value is nearest, but in Ferret it's center. More details here https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
const ( ScrollHorizontalAlignmentCenter ScrollHorizontalAlignment = 0 ScrollHorizontalAlignmentStart ScrollHorizontalAlignment = 1 ScrollHorizontalAlignmentEnd ScrollHorizontalAlignment = 2 ScrollHorizontalAlignmentNearest ScrollHorizontalAlignment = 3 )
func NewScrollHorizontalAlignment ¶ added in v0.11.0
func NewScrollHorizontalAlignment(value string) ScrollHorizontalAlignment
func (ScrollHorizontalAlignment) String ¶ added in v0.11.0
func (a ScrollHorizontalAlignment) String() string
type ScrollOptions ¶ added in v0.11.0
type ScrollOptions struct { Behavior ScrollBehavior Block ScrollVerticalAlignment Inline ScrollHorizontalAlignment }
ScrollOptions defines how scroll animation should be performed.
type ScrollVerticalAlignment ¶ added in v0.11.0
type ScrollVerticalAlignment int
ScrollVerticalAlignment defines vertical alignment after scrolling. In HTML specification, default value is start, but in Ferret it's center. More details here https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
const ( ScrollVerticalAlignmentCenter ScrollVerticalAlignment = 0 ScrollVerticalAlignmentStart ScrollVerticalAlignment = 1 ScrollVerticalAlignmentEnd ScrollVerticalAlignment = 2 ScrollVerticalAlignmentNearest ScrollVerticalAlignment = 3 )
func NewScrollVerticalAlignment ¶ added in v0.11.0
func NewScrollVerticalAlignment(value string) ScrollVerticalAlignment
func (ScrollVerticalAlignment) String ¶ added in v0.11.0
func (a ScrollVerticalAlignment) String() string