Documentation ¶
Overview ¶
Package browser the JS browser implementations
Index ¶
- func NewElement(ele *rod.Element, vm *goja.Runtime) goja.Value
- func NewPage(p *rod.Page, vm *goja.Runtime) goja.Value
- type Browser
- type Element
- func (el *Element) BackgroundImage(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) ContainsElement(element goja.Value) (bool, error)
- func (el *Element) Describe(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) ElementByJS(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) ElementR(selector, jsRegex string) (any, error)
- func (el *Element) Elements(selector string) (any, error)
- func (el *Element) ElementsByJS(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) ElementsX(xpath string) (any, error)
- func (el *Element) Equal(elm goja.Value) (bool, error)
- func (el *Element) Eval(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) Evaluate(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) Frame(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) Has(selector string) (bool, any, error)
- func (el *Element) HasR(selector, jsRegex string) (bool, any, error)
- func (el *Element) HasX(selector string) (bool, any, error)
- func (el *Element) Interactable(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) NElement(selector string) (any, error)
- func (el *Element) Next() any
- func (el *Element) Page() any
- func (el *Element) Parent() any
- func (el *Element) Parents(selector string) any
- func (el *Element) Previous() any
- func (el *Element) Resource(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) Screenshot(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) ShadowRoot() any
- func (el *Element) Shape(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) Wait(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (el *Element) WaitInteractable(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- type Elements
- type EvalOptions
- type Module
- type Page
- func (p *Page) Activate() (any, error)
- func (p *Page) Cookies(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) Element(selector string) (any, error)
- func (p *Page) ElementByJS(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) ElementFromNode(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) ElementFromObject(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) ElementFromPoint(x, y int) (any, error)
- func (p *Page) ElementR(selector, jsRegex string) (any, error)
- func (p *Page) ElementX(xPath string) (any, error)
- func (p *Page) Elements(selector string) (Elements, error)
- func (p *Page) ElementsByJS(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) ElementsX(xpath string) (Elements, error)
- func (p *Page) Emulate(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) Eval(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) Evaluate(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) GetResource(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) GetWindow(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) HandleDialog(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) Has(selector string) (bool, any, error)
- func (p *Page) HasR(selector, jsRegex string) (bool, any, error)
- func (p *Page) HasX(selector string) (bool, any, error)
- func (p *Page) Info(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) ObjectToJSON(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) PDF(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) Release(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) Screenshot(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) Search(query string) (any, error)
- func (p *Page) SetCookies(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) SetUserAgent(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) SetViewport(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) SetWindow(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) Timeout(timeout string) (page *Page, err error)
- func (p *Page) Wait(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
- func (p *Page) WaitIdle(timeout string) (err error)
- func (p *Page) WaitOpen(_ goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewElement ¶
NewElement creates a new Element mapping
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser module represents the browser. It doesn't depends on file system, it should work with remote browser seamlessly.
type Element ¶
Element represents the DOM element
func (*Element) BackgroundImage ¶
BackgroundImage returns the css background-image of the element
func (*Element) ContainsElement ¶
ContainsElement check if the target is equal or inside the element.
func (*Element) Describe ¶
Describe the current element. The depth is the maximum depth at which children should be retrieved, defaults to 1, use -1 for the entire subtree or provide an integer larger than 0. The pierce decides whether or not iframes and shadow roots should be traversed when returning the subtree. The returned proto.DOMNode.NodeID will always be empty, because NodeID is not stable (when proto.DOMDocumentUpdated is fired all NodeID on the page will be reassigned to another value) we don't recommend using the NodeID, instead, use the BackendNodeID to identify the element.
func (*Element) ElementByJS ¶
ElementByJS returns the element from the return value of the js
func (*Element) ElementR ¶
ElementR returns the first child element that matches the css selector and its text matches the jsRegex.
func (*Element) ElementsByJS ¶
ElementsByJS returns the elements from the return value of the js
func (*Element) Eval ¶
Eval is a shortcut for Element.Evaluate with AwaitPromise, ByValue and AutoExp set to true.
func (*Element) Evaluate ¶
Evaluate is just a shortcut of Page.Evaluate with This set to current element.
func (*Element) HasR ¶
HasR an element that matches the css selector and its display text matches the jsRegex.
func (*Element) Interactable ¶
Interactable checks if the element is interactable with cursor. The cursor can be mouse, finger, stylus, etc. If not interactable err will be ErrNotInteractable, such as when covered by a modal,
func (*Element) Resource ¶
Resource returns the "src" content of current element. Such as the jpg of <img src="a.jpg">
func (*Element) Screenshot ¶
Screenshot of the area of the element
func (*Element) ShadowRoot ¶
ShadowRoot returns the shadow root of this element
func (*Element) Shape ¶
Shape of the DOM element content. The shape is a group of 4-sides polygons. A 4-sides polygon is not necessary a rectangle. 4-sides polygons can be apart from each other. For example, we use 2 4-sides polygons to describe the shape below:
____________ ____________ / ___/ = /___________/ + _________ /________/ /________/
func (*Element) WaitInteractable ¶
WaitInteractable waits for the element to be interactable. It will try to scroll to the element on each try.
type Elements ¶
Elements provides some helpers to deal with element list
func NewElements ¶
NewElements creates a new Elements mapping
type EvalOptions ¶
type EvalOptions struct { ByValue bool `json:"byValue"` AwaitPromise bool `json:"awaitPromise"` ThisObj *proto.RuntimeRemoteObject `json:"thisObj"` JS string `json:"js"` JSArgs []any `json:"jsArgs"` UserGesture bool `json:"userGesture"` }
EvalOptions for Page.Evaluate
type Page ¶
Page the rod.Page mapping
func (*Page) Cookies ¶
Cookies returns the page cookies. By default it will return the cookies for current page. The urls is the list of URLs for which applicable cookies will be fetched.
func (*Page) Element ¶
Element retries until an element in the page that matches the CSS selector, then returns the matched element.
func (*Page) ElementByJS ¶
ElementByJS returns the element from the return value of the js function. If sleeper is nil, no retry will be performed. By default, it will retry until the js function doesn't return null. To customize the retry logic, check the examples of Page.Sleeper.
func (*Page) ElementFromNode ¶
ElementFromNode creates an Element from the node, NodeID or BackendNodeID must be specified.
func (*Page) ElementFromObject ¶
ElementFromObject creates an Element from the remote object id.
func (*Page) ElementFromPoint ¶
ElementFromPoint creates an Element from the absolute point on the page. The point should include the window scroll offset.
func (*Page) ElementR ¶
ElementR retries until an element in the page that matches the css selector and it's text matches the jsRegex, then returns the matched element.
func (*Page) ElementX ¶
ElementX retries until an element in the page that matches one of the XPath selectors, then returns the matched element.
func (*Page) ElementsByJS ¶
ElementsByJS returns the elements from the return value of the js
func (*Page) Emulate ¶
Emulate the device, such as iPhone9. If device is devices.Clear, it will clear the override.
func (*Page) GetResource ¶
GetResource content by the url. Such as image, css, html, etc. Use the proto.PageGetResourceTree to list all the resources.
func (*Page) HandleDialog ¶
HandleDialog accepts or dismisses next JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload). Because modal dialog will block js, usually you have to trigger the dialog in another goroutine. For example:
const { wait, handle } = page.handleDialog() page.element("button").click() wait() handle(true, "")
func (*Page) HasR ¶
HasR an element that matches the css selector and its display text matches the jsRegex.
func (*Page) ObjectToJSON ¶
ObjectToJSON by object id
func (*Page) Release ¶
Release the remote object. Usually, you don't need to call it. When a page is closed or reloaded, all remote objects will be released automatically. It's useful if the page never closes or reloads.
func (*Page) Screenshot ¶
Screenshot captures the screenshot of current page.
func (*Page) Search ¶
Search for the given query in the DOM tree until the result count is not zero, before that it will keep retrying. The query can be plain text or css selector or xpath. It will search nested iframes and shadow doms too.
func (*Page) SetCookies ¶
SetCookies is similar to Browser.SetCookies .
func (*Page) SetUserAgent ¶
SetUserAgent (browser brand, accept-language, etc) of the page. If req is nil, a default user agent will be used, a typical mac chrome.
func (*Page) SetViewport ¶
SetViewport overrides the values of device screen dimensions
func (*Page) Timeout ¶
Timeout returns a clone with the specified total timeout of all chained sub-operations