Documentation ¶
Overview ¶
Example ¶
This example opens https://github.com/, searches for "git", and then gets the header element which gives the description for Git.
package main import ( "fmt" "time" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/input" ) func main() { // Launch a new browser with default options, and connect to it. browser := rod.New().MustConnect() // Even you forget to close, rod will close it after main process ends. defer browser.MustClose() // Timeout will be passed to all chained function calls. // The code will panic out if any chained call is used after the timeout. page := browser.Timeout(time.Minute).MustPage("https://github.com") // We use css selector to get the search input element and input "git" page.MustElement("input").MustInput("git").MustPress(input.Enter) // Wait until css selector get the element then get the text content of it. text := page.MustElement(".codesearch-results p").MustText() fmt.Println(text) // Get all input elements. Rod supports query elements by css selector, xpath, and regex. // For more detailed usage, check the query_test.go file. fmt.Println("Found", len(page.MustElements("input")), "input elements") // Eval js on the page page.MustEval(`console.log("hello world")`) // Pass parameters as json objects to the js function. This one will return 3 fmt.Println("1 + 2 =", page.MustEval(`(a, b) => a + b`, 1, 2).Int()) // When eval on an element, you can use "this" to access the DOM element. fmt.Println(page.MustElement("title").MustEval(`this.innerText`).String()) }
Output: Git is the most widely used version control system. Found 5 input elements 1 + 2 = 3 Search · git · GitHub
Example (Customize_browser_launch) ¶
Shows how we can further customize the browser with the launcher library. Usually you use launcher lib to set the browser's command line flags (switches). Doc for flags: https://peter.sh/experiments/chromium-command-line-switches
package main import ( "fmt" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/launcher" ) func main() { url := launcher.New(). Proxy("127.0.0.1:8080"). // set flag "--proxy-server=127.0.0.1:8080" Delete("use-mock-keychain"). // delete flag "--use-mock-keychain" MustLaunch() browser := rod.New().ControlURL(url).MustConnect() defer browser.MustClose() // So that we don't have to self issue certs for MITM browser.MustIgnoreCertErrors(true) // Adding authentication to the proxy, for the next auth request. // We use CLI tool "mitmproxy --proxyauth user:pass" as an example. browser.MustHandleAuth("user", "pass") // mitmproxy needs a cert config to support https. We use http here instead, // for example fmt.Println(browser.MustPage("https://example.com/").MustElement("title").MustText()) }
Output:
Example (Customize_retry_strategy) ¶
Shows how to change the retry/polling options that is used to query elements. This is useful when you want to customize the element query retry logic.
package main import ( "context" "errors" "fmt" "time" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/utils" ) func main() { browser := rod.New().Timeout(time.Minute).MustConnect() defer browser.MustClose() page := browser.MustPage("https://github.com") // sleep for 0.5 seconds before every retry sleeper := func() utils.Sleeper { return func(context.Context) error { time.Sleep(time.Second / 2) return nil } } el, _ := page.Sleeper(sleeper).Element("input") // If sleeper is nil page.ElementE will query without retrying. // If nothing found it will return an error. el, err := page.Sleeper(nil).Element("input") if errors.Is(err, rod.ErrElementNotFound) { fmt.Println("element not found") } else if err != nil { panic(err) } fmt.Println(el.MustEval(`this.name`).String()) }
Output: q
Example (Direct_cdp) ¶
When rod doesn't have a feature that you need. You can easily call the cdp to achieve it. List of cdp API: https://chromedevtools.github.io/devtools-protocol
package main import ( "encoding/json" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/proto" ) func main() { page := rod.New().MustConnect().MustPage("") // Rod doesn't have a method to enable AD blocking, // but you can call cdp interface directly to achieve it. // Doc: https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-setAdBlockingEnabled _ = proto.PageSetAdBlockingEnabled{ Enabled: true, }.Call(page) // You can even use JSON directly to do the same thing above. params, _ := json.Marshal(map[string]bool{ "enabled": true, }) ctx, client, id := page.CallContext() _, _ = client.Call(ctx, id, "Page.setAdBlockingEnabled", params) }
Output:
Example (Disable_headless_to_debug) ¶
Shows how to disable headless mode and debug. Rod provides a lot of debug options, you can set them with setter methods or use environment variables. Doc for environment variables: https://pkg.go.dev/github.com/go-rod/rod/lib/defaults
package main import ( "fmt" "time" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/input" "github.com/go-rod/rod/lib/launcher" "github.com/go-rod/rod/lib/utils" ) func main() { // Headless runs the browser on foreground, you can also use env "rod=show" // Devtools opens the tab in each new tab opened automatically l := launcher.New(). Headless(false). Devtools(true) defer l.Cleanup() url := l.MustLaunch() // Trace shows verbose debug information for each action executed // Slowmotion is a debug related function that waits 2 seconds between // each action, making it easier to inspect what your code is doing. browser := rod.New(). Timeout(time.Minute). ControlURL(url). Trace(true). Slowmotion(2 * time.Second). MustConnect() // ServeMonitor plays screenshots of each tab. This feature is extremely // useful when debugging with headless mode. // You can also enable it with env rod=monitor launcher.NewBrowser().Open(browser.ServeMonitor("")) defer browser.MustClose() page := browser.MustPage("https://www.wikipedia.org/") page.MustElement("#searchLanguage").MustSelect("[lang=zh]") page.MustElement("#searchInput").MustInput("热干面") page.Keyboard.MustPress(input.Enter) fmt.Println(page.MustElement("#firstHeading").MustText()) // Response gets the binary of the image as a []byte. img := page.MustElement(`[alt="Hot Dry Noodles.jpg"]`).MustResource() fmt.Println(len(img)) // print the size of the image utils.Pause() // pause goroutine }
Output:
Example (Error_handling) ¶
We use "Must" prefixed functions to write example code. But in production you may want to use the no-prefix version of them. About why we use "Must" as the prefix, it's similar with https://golang.org/pkg/regexp/#MustCompile
package main import ( "context" "errors" "fmt" "time" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/utils" ) func main() { page := rod.New().MustConnect().MustPage("https://example.com") // The two code blocks below are basically the same: // The block below is better for production code. It follows the standards of golang error handling. // Usually, this style will make error handling more consistent and precisely. { el, err := page.Element("a") if err != nil { fmt.Print(err) return } html, err := el.HTML() if err != nil { fmt.Print(err) return } fmt.Println(html) } // The block below is better for example code or quick scripting. We use panic to short-circuit logics. // So that we can code in fluent style: https://en.wikipedia.org/wiki/Fluent_interface // It will reduce the code to type, but it may also catch extra errors (less consistent and precisely). { err := rod.Try(func() { fmt.Println(page.MustElement("a").MustHTML()) }) fmt.Print(err) } // Catch specified error types { _, err := page.Timeout(3 * time.Second).Eval(`foo()`) if errors.Is(err, context.DeadlineExceeded) { // timeout error fmt.Println("timeout err") } else if errors.Is(err, rod.ErrEval) { // eval error // print the stack trace fmt.Printf("%+v\n", err) // print more details utils.Dump(rod.AsError(err).Details) } else if err != nil { panic(err) } } }
Output:
Example (Handle_events) ¶
Shows how to listen for events.
package main import ( "context" "fmt" "time" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/proto" ) func main() { browser := rod.New().Timeout(time.Minute).MustConnect() defer browser.MustClose() ctx, cancel := context.WithCancel(context.Background()) defer cancel() page := browser.Context(ctx).MustPage("") done := make(chan int) // Listen for all events of console output. go page.EachEvent(func(e *proto.RuntimeConsoleAPICalled) { log := page.MustObjectsToJSON(e.Args).Join(" ") fmt.Println(log) close(done) })() wait := page.WaitEvent(&proto.PageLoadEventFired{}) page.MustNavigate("https://example.com") wait() // EachEvent allows us to achieve the same functionality as above. if false { // Subscribe events before they happen, run the "wait()" to start consuming // the events. We can return an optional stop signal unsubscribe events. wait := page.EachEvent(func(e *proto.PageLoadEventFired) (stop bool) { return true }) page.MustNavigate("https://example.com") wait() } page.MustEval(`console.log("hello", "world")`) <-done }
Output: hello world
Example (Hijack_requests) ¶
Shows how to intercept requests and modify both the request and the response. The entire process of hijacking one request:
browser --req-> rod ---> server ---> rod --res-> browser
The --req-> and --res-> are the parts that can be modified.
package main import ( "fmt" "time" "github.com/go-rod/rod" ) func main() { browser := rod.New().Timeout(time.Minute).MustConnect() defer browser.MustClose() router := browser.HijackRequests() defer router.MustStop() router.MustAdd("*.js", func(ctx *rod.Hijack) { // Here we update the request's header. Rod gives functionality to // change or update all parts of the request. Refer to the documentation // for more information. ctx.Request.Req().Header.Set("My-Header", "test") // LoadResponse runs the default request to the destination of the request. // Not calling this will require you to mock the entire response. // This can be done with the SetXxx (Status, Header, Body) functions on the // ctx.Response struct. ctx.MustLoadResponse() // Here we append some code to every js file. // The code will update the document title to "hi" ctx.Response.SetBody(ctx.Response.Body() + "\n document.title = 'hi' ") }) go router.Run() browser.MustPage("https://www.wikipedia.org/").MustWait(`document.title === 'hi'`) fmt.Println("done") }
Output: done
Example (Page_pdf) ¶
package main import ( "github.com/go-rod/rod" "github.com/go-rod/rod/lib/proto" "github.com/go-rod/rod/lib/utils" ) func main() { page := rod.New().MustConnect().MustPage("") wait := page.MustWaitNavigation() page.MustNavigate("https://github.com") wait() // until the navigation to settle down // simple version page.MustPDF("my.pdf") // customization version pdf, _ := page.PDF(&proto.PagePrintToPDF{ PaperWidth: 8.5, PaperHeight: 11, PageRanges: "1-3", IgnoreInvalidPageRanges: false, DisplayHeaderFooter: true, }) _ = utils.OutputFile("my.pdf", pdf) }
Output:
Example (Page_screenshot) ¶
package main import ( "github.com/go-rod/rod" "github.com/go-rod/rod/lib/proto" "github.com/go-rod/rod/lib/utils" ) func main() { page := rod.New().MustConnect().MustPage("") wait := page.MustWaitNavigation() page.MustNavigate("https://github.com") wait() // until the navigation to settle down // simple version page.MustScreenshot("my.png") // customization version img, _ := page.Screenshot(true, &proto.PageCaptureScreenshot{ Format: proto.PageCaptureScreenshotFormatJpeg, Quality: 90, Clip: &proto.PageViewport{ X: 0, Y: 0, Width: 300, Height: 200, Scale: 1, }, FromSurface: true, }) _ = utils.OutputFile("my.jpg", img) }
Output:
Example (Race_selectors) ¶
Show how to handle multiple results of an action. Such as when you login a page, the result can be success or wrong password.
package main import ( "fmt" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/input" ) func main() { browser := rod.New().MustConnect() defer browser.MustClose() page := browser.MustPage("http://testing-ground.scraping.pro/login") page.MustElement("#usr").MustInput("admin") page.MustElement("#pwd").MustInput("12345").MustPress(input.Enter) // It will keep retrying until one selector has found a match page.Race().MustElement("h3.success", func(el *rod.Element) { // when successful login fmt.Println(el.MustText()) }).MustElement("h3.error", func(el *rod.Element) { // when wrong username or password fmt.Println(el.MustText()) }).MustDo() }
Output: WELCOME :)
Example (Search) ¶
Example_search shows how to use Search to get element inside nested iframes or shadow DOMs. It works the same as https://developers.google.com/web/tools/chrome-devtools/dom#search
package main import ( "fmt" "time" "github.com/go-rod/rod" ) func main() { browser := rod.New().Timeout(time.Minute).MustConnect() defer browser.MustClose() page := browser.MustPage("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe") // get the code mirror editor inside the iframe el := page.MustSearch(".CodeMirror") fmt.Println(*el.MustAttribute("class")) }
Output: CodeMirror cm-s-default CodeMirror-wrap
Example (States) ¶
Shows how to update the state of the current page. In this example we enable the network domain.
package main import ( "fmt" "time" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/proto" ) func main() { browser := rod.New().Timeout(time.Minute).MustConnect() defer browser.MustClose() page := browser.MustPage("") // LoadState detects whether the network domain is enabled or not. fmt.Println(page.LoadState(&proto.NetworkEnable{})) _ = proto.NetworkEnable{}.Call(page) // Check if the network domain is successfully enabled. fmt.Println(page.LoadState(&proto.NetworkEnable{})) }
Output: false true
Example (Timeout_handling) ¶
Usage of timeout context
package main import ( "context" "time" "github.com/go-rod/rod" ) func main() { page := rod.New().MustConnect().MustPage("https://github.com") page. // Set a 5-second timeout for all chained actions Timeout(5 * time.Second). // The total time for MustWaitLoad and MustElement must be less than 5 seconds MustWaitLoad(). MustElement("title"). // Actions after CancelTimeout won't be affected by the 5-second timeout CancelTimeout(). // Set a 10-second timeout for all chained actions Timeout(10 * time.Second). // Panics if it takes more than 10 seconds MustText() // The two code blocks below are basically the same: { page.Timeout(5 * time.Second).MustElement("a").CancelTimeout() } { // Use this way you can customize your own way to cancel long-running task ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) page.Context(ctx).MustElement("a") cancel() } }
Output:
Example (Wait_for_animation) ¶
Example_wait_for_animation is an example to simulate humans more accurately. If a button is moving too fast, you cannot click it as a human. To more accurately simulate human inputs, actions triggered by Rod can be based on mouse point location, so you can allow Rod to wait for the button to become stable before it tries clicking it.
package main import ( "fmt" "time" "github.com/go-rod/rod" ) func main() { browser := rod.New().Timeout(time.Minute).MustConnect() defer browser.MustClose() page := browser.MustPage("https://getbootstrap.com/docs/4.0/components/modal/") page.MustWaitLoad().MustElement("[data-target='#exampleModalLive']").MustClick() saveBtn := page.MustElementR("#exampleModalLive button", "Close") // Here, WaitStable will wait until the save button's position becomes // stable. The timeout is 5 seconds, after which it times out (or after 1 // minute since the browser was created). Timeouts from parents are // inherited to the children as well. saveBtn.Timeout(5 * time.Second).MustWaitStable().MustClick().MustWaitInvisible() fmt.Println("done") }
Output: done
Example (Wait_for_request) ¶
When you want to wait for an ajax request to complete, this example will be useful.
package main import ( "fmt" "time" "github.com/go-rod/rod" ) func main() { browser := rod.New().Timeout(time.Minute).MustConnect() defer browser.MustClose() page := browser.MustPage("https://duckduckgo.com/") // Start to analyze request events wait := page.MustWaitRequestIdle() // This will trigger the search ajax request page.MustElement("#search_form_input_homepage").MustClick().MustInput("test") // Wait until there's no active requests wait() // We want to make sure that after waiting, there are some autocomplete // suggestions available. fmt.Println(len(page.MustElements(".search__autocomplete .acp")) > 0) }
Output: true
Index ¶
- Variables
- func Event(msg *cdp.Event, evt proto.Payload) bool
- func SprintFnThis(js string) string
- func Try(fn func()) (err error)
- type Browser
- func (b *Browser) Call(ctx context.Context, sessionID, methodName string, params json.RawMessage) (res []byte, err error)
- func (b *Browser) CallContext() (context.Context, proto.Client, string)
- func (b *Browser) CancelTimeout() *Browser
- func (b *Browser) Client(c Client) *Browser
- func (b *Browser) Close() error
- func (b *Browser) Connect() error
- func (b *Browser) Context(ctx context.Context) *Browser
- func (b *Browser) ControlURL(url string) *Browser
- func (b *Browser) DefaultViewport(viewport *proto.EmulationSetDeviceMetricsOverride) *Browser
- func (b *Browser) DisableDomain(sessionID proto.TargetSessionID, method proto.Payload) (recover func())
- func (b *Browser) EachEvent(callbacks ...interface{}) (wait func())
- func (b *Browser) EnableDomain(sessionID proto.TargetSessionID, method proto.Payload) (recover func())
- func (b *Browser) Event() *goob.Observable
- func (b *Browser) HandleAuth(username, password string) func() error
- func (b *Browser) Headless() bool
- func (b *Browser) HijackRequests() *HijackRouter
- func (b *Browser) IgnoreCertErrors(enable bool) error
- func (b *Browser) Incognito() (*Browser, error)
- func (b *Browser) LoadState(sessionID proto.TargetSessionID, method proto.Payload) (has bool)
- func (b *Browser) MustClose()
- func (b *Browser) MustConnect() *Browser
- func (b *Browser) MustHandleAuth(username, password string)
- func (b *Browser) MustIgnoreCertErrors(enable bool) *Browser
- func (b *Browser) MustIncognito() *Browser
- func (b *Browser) MustPage(url string) *Page
- func (b *Browser) MustPageFromTargetID(targetID proto.TargetTargetID) *Page
- func (b *Browser) MustPages() Pages
- func (b *Browser) Page(url string) (p *Page, err error)
- func (b *Browser) PageFromTarget(targetID proto.TargetTargetID) (*Page, error)
- func (b *Browser) Pages() (Pages, error)
- func (b *Browser) ServeMonitor(host string) string
- func (b *Browser) Sleeper(sleeper func() utils.Sleeper) *Browser
- func (b *Browser) Slowmotion(delay time.Duration) *Browser
- func (b *Browser) Timeout(d time.Duration) *Browser
- func (b *Browser) Trace(enable bool) *Browser
- func (b *Browser) TraceLog(l TraceLog) *Browser
- func (b *Browser) WaitEvent(e proto.Payload) (wait func())
- type Client
- type Element
- func (el *Element) Attribute(name string) (*string, error)
- func (el *Element) Blur() error
- func (el *Element) Box() (*proto.DOMRect, error)
- func (el *Element) CallContext() (context.Context, proto.Client, string)
- func (el *Element) CancelTimeout() *Element
- func (el *Element) CanvasToImage(format string, quality float64) ([]byte, error)
- func (el *Element) Click(button proto.InputMouseButton) error
- func (el *Element) Clickable() (bool, error)
- func (el *Element) ContainsElement(target *Element) (bool, error)
- func (el *Element) Context(ctx context.Context) *Element
- func (el *Element) Describe(depth int, pierce bool) (*proto.DOMNode, error)
- func (el *Element) Element(selectors ...string) (*Element, error)
- func (el *Element) ElementByJS(opts *EvalOptions) (*Element, error)
- func (el *Element) ElementR(pairs ...string) (*Element, error)
- func (el *Element) ElementX(xPaths ...string) (*Element, error)
- func (el *Element) Elements(selector string) (Elements, error)
- func (el *Element) ElementsByJS(opts *EvalOptions) (Elements, error)
- func (el *Element) ElementsX(xpath string) (Elements, error)
- func (el *Element) Eval(js string, params ...interface{}) (*proto.RuntimeRemoteObject, error)
- func (el *Element) EvalWithOptions(opts *EvalOptions) (*proto.RuntimeRemoteObject, error)
- func (el *Element) Focus() error
- func (el *Element) Frame() (*Page, error)
- func (el *Element) HTML() (string, error)
- func (el *Element) Has(selector string) (bool, *Element, error)
- func (el *Element) HasR(selector, regex string) (bool, *Element, error)
- func (el *Element) HasX(selector string) (bool, *Element, error)
- func (el *Element) Hover() error
- func (el *Element) Input(text string) error
- func (el *Element) Matches(selector string) (bool, error)
- func (el *Element) MustAttribute(name string) *string
- func (el *Element) MustBlur() *Element
- func (el *Element) MustBox() *proto.DOMRect
- func (el *Element) MustCanvasToImage(format string, quality float64) []byte
- func (el *Element) MustClick() *Element
- func (el *Element) MustClickable() bool
- func (el *Element) MustContainsElement(target *Element) bool
- func (el *Element) MustDescribe() *proto.DOMNode
- func (el *Element) MustElement(selector string) *Element
- func (el *Element) MustElementByJS(js string, params ...interface{}) *Element
- func (el *Element) MustElementR(selector, regex string) *Element
- func (el *Element) MustElementX(xpath string) *Element
- func (el *Element) MustElements(selector string) Elements
- func (el *Element) MustElementsByJS(js string, params ...interface{}) Elements
- func (el *Element) MustElementsX(xpath string) Elements
- func (el *Element) MustEval(js string, params ...interface{}) proto.JSON
- func (el *Element) MustFocus() *Element
- func (el *Element) MustFrame() *Page
- func (el *Element) MustHTML() string
- func (el *Element) MustHas(selector string) bool
- func (el *Element) MustHasR(selector, regex string) bool
- func (el *Element) MustHasX(selector string) bool
- func (el *Element) MustHover() *Element
- func (el *Element) MustInput(text string) *Element
- func (el *Element) MustMatches(selector string) bool
- func (el *Element) MustNext() *Element
- func (el *Element) MustNodeID() proto.DOMNodeID
- func (el *Element) MustParent() *Element
- func (el *Element) MustParents(selector string) Elements
- func (el *Element) MustPress(key rune) *Element
- func (el *Element) MustPrevious() *Element
- func (el *Element) MustProperty(name string) proto.JSON
- func (el *Element) MustRelease()
- func (el *Element) MustResource() []byte
- func (el *Element) MustScreenshot(toFile ...string) []byte
- func (el *Element) MustScrollIntoView() *Element
- func (el *Element) MustSelect(selectors ...string) *Element
- func (el *Element) MustSelectAllText() *Element
- func (el *Element) MustSelectText(regex string) *Element
- func (el *Element) MustSetFiles(paths ...string) *Element
- func (el *Element) MustShadowRoot() *Element
- func (el *Element) MustTap() *Element
- func (el *Element) MustText() string
- func (el *Element) MustVisible() bool
- func (el *Element) MustWait(js string, params ...interface{}) *Element
- func (el *Element) MustWaitInvisible() *Element
- func (el *Element) MustWaitLoad() *Element
- func (el *Element) MustWaitStable() *Element
- func (el *Element) MustWaitVisible() *Element
- func (el *Element) Next() (*Element, error)
- func (el *Element) NodeID() (proto.DOMNodeID, error)
- func (el *Element) Parent() (*Element, error)
- func (el *Element) Parents(selector string) (Elements, error)
- func (el *Element) Press(key rune) error
- func (el *Element) Previous() (*Element, error)
- func (el *Element) Property(name string) (proto.JSON, error)
- func (el *Element) Release() error
- func (el *Element) Resource() ([]byte, error)
- func (el *Element) Screenshot(format proto.PageCaptureScreenshotFormat, quality int) ([]byte, error)
- func (el *Element) ScrollIntoView() error
- func (el *Element) Select(selectors []string) error
- func (el *Element) SelectAllText() error
- func (el *Element) SelectText(regex string) error
- func (el *Element) SetFiles(paths []string) error
- func (el *Element) ShadowRoot() (*Element, error)
- func (el *Element) Sleeper(sleeper func() utils.Sleeper) *Element
- func (el *Element) Tap() error
- func (el *Element) Text() (string, error)
- func (el *Element) Timeout(d time.Duration) *Element
- func (el *Element) Trace(msg string) (removeOverlay func())
- func (el *Element) Visible() (bool, error)
- func (el *Element) Wait(js string, params ...interface{}) error
- func (el *Element) WaitInvisible() error
- func (el *Element) WaitLoad() error
- func (el *Element) WaitStable(interval time.Duration) error
- func (el *Element) WaitVisible() error
- type Elements
- type Error
- type EvalOptions
- type Hijack
- type HijackRequest
- func (ctx *HijackRequest) Body() string
- func (ctx *HijackRequest) Header(key string) string
- func (ctx *HijackRequest) Headers() proto.NetworkHeaders
- func (ctx *HijackRequest) JSONBody() gjson.Result
- func (ctx *HijackRequest) Method() string
- func (ctx *HijackRequest) Req() *http.Request
- func (ctx *HijackRequest) SetBody(obj interface{}) *HijackRequest
- func (ctx *HijackRequest) SetContext(c context.Context) *HijackRequest
- func (ctx *HijackRequest) Type() proto.NetworkResourceType
- func (ctx *HijackRequest) URL() *url.URL
- type HijackResponse
- func (ctx *HijackResponse) Body() string
- func (ctx *HijackResponse) Fail(reason proto.NetworkErrorReason) *HijackResponse
- func (ctx *HijackResponse) Headers() http.Header
- func (ctx *HijackResponse) Payload() *proto.FetchFulfillRequest
- func (ctx *HijackResponse) SetBody(obj interface{}) *HijackResponse
- func (ctx *HijackResponse) SetHeader(pairs ...string) *HijackResponse
- type HijackRouter
- func (r *HijackRouter) Add(pattern string, resourceType proto.NetworkResourceType, handler func(*Hijack)) error
- func (r *HijackRouter) MustAdd(pattern string, handler func(*Hijack)) *HijackRouter
- func (r *HijackRouter) MustRemove(pattern string) *HijackRouter
- func (r *HijackRouter) MustStop()
- func (r *HijackRouter) Remove(pattern string) error
- func (r *HijackRouter) Run()
- func (r *HijackRouter) Stop() error
- type JSArgs
- type Keyboard
- func (k *Keyboard) Down(key rune) error
- func (k *Keyboard) InsertText(text string) error
- func (k *Keyboard) MustDown(key rune) *Keyboard
- func (k *Keyboard) MustInsertText(text string) *Keyboard
- func (k *Keyboard) MustPress(key rune) *Keyboard
- func (k *Keyboard) MustUp(key rune) *Keyboard
- func (k *Keyboard) Press(key rune) error
- func (k *Keyboard) Up(key rune) error
- type Mouse
- func (m *Mouse) Click(button proto.InputMouseButton) error
- func (m *Mouse) Down(button proto.InputMouseButton, clicks int64) error
- func (m *Mouse) Move(x, y float64, steps int) error
- func (m *Mouse) MustClick(button proto.InputMouseButton) *Mouse
- func (m *Mouse) MustDown(button proto.InputMouseButton) *Mouse
- func (m *Mouse) MustMove(x, y float64) *Mouse
- func (m *Mouse) MustScroll(x, y float64) *Mouse
- func (m *Mouse) MustUp(button proto.InputMouseButton) *Mouse
- func (m *Mouse) Scroll(offsetX, offsetY float64, steps int) error
- func (m *Mouse) Up(button proto.InputMouseButton, clicks int64) error
- type Page
- func (p *Page) AddScriptTag(url, content string) error
- func (p *Page) AddStyleTag(url, content string) error
- func (p *Page) CallContext() (context.Context, proto.Client, string)
- func (p *Page) CancelTimeout() *Page
- func (p *Page) Close() error
- func (p *Page) Context(ctx context.Context) *Page
- func (p *Page) Cookies(urls []string) ([]*proto.NetworkCookie, error)
- func (p *Page) DisableDomain(method proto.Payload) (recover func())
- func (p *Page) EachEvent(callbacks ...interface{}) (wait func())
- func (p *Page) Element(selectors ...string) (*Element, error)
- func (p *Page) ElementByJS(opts *EvalOptions) (*Element, error)
- func (p *Page) ElementFromNode(id proto.DOMNodeID) (*Element, error)
- func (p *Page) ElementFromObject(id proto.RuntimeRemoteObjectID) *Element
- func (p *Page) ElementFromPoint(x, y int64) (*Element, error)
- func (p *Page) ElementR(pairs ...string) (*Element, error)
- func (p *Page) ElementX(xPaths ...string) (*Element, error)
- func (p *Page) Elements(selector string) (Elements, error)
- func (p *Page) ElementsByJS(opts *EvalOptions) (Elements, error)
- func (p *Page) ElementsX(xpath string) (Elements, error)
- func (p *Page) Emulate(device devices.Device, landscape bool) error
- func (p *Page) EnableDomain(method proto.Payload) (recover func())
- func (p *Page) Eval(js string, jsArgs ...interface{}) (*proto.RuntimeRemoteObject, error)
- func (p *Page) EvalOnNewDocument(js string) (proto.PageScriptIdentifier, error)
- func (p *Page) EvalWithOptions(opts *EvalOptions) (*proto.RuntimeRemoteObject, error)
- func (p *Page) Expose(name string) (callback chan string, stop func(), err error)
- func (p *Page) ExposeJSHelper() *Page
- func (p *Page) GetDownloadFile(pattern string, resourceType proto.NetworkResourceType, client *http.Client) func() (http.Header, []byte, error)
- func (p *Page) GetWindow() (*proto.BrowserBounds, error)
- func (p *Page) HandleDialog(accept bool, promptText string) func() error
- func (p *Page) Has(selectors ...string) (bool, *Element, error)
- func (p *Page) HasR(selector, regex string) (bool, *Element, error)
- func (p *Page) HasX(selectors ...string) (bool, *Element, error)
- func (p *Page) HijackRequests() *HijackRouter
- func (p *Page) Info() (*proto.TargetTargetInfo, error)
- func (p *Page) IsIframe() bool
- func (p *Page) LoadState(method proto.Payload) (has bool)
- func (p *Page) MustAddScriptTag(url string) *Page
- func (p *Page) MustAddStyleTag(url string) *Page
- func (p *Page) MustClose()
- func (p *Page) MustCookies(urls ...string) []*proto.NetworkCookie
- func (p *Page) MustElement(selectors ...string) *Element
- func (p *Page) MustElementByJS(js string, params ...interface{}) *Element
- func (p *Page) MustElementFromNode(id proto.DOMNodeID) *Element
- func (p *Page) MustElementFromPoint(left, top int) *Element
- func (p *Page) MustElementR(pairs ...string) *Element
- func (p *Page) MustElementX(xPaths ...string) *Element
- func (p *Page) MustElements(selector string) Elements
- func (p *Page) MustElementsByJS(js string, params ...interface{}) Elements
- func (p *Page) MustElementsX(xpath string) Elements
- func (p *Page) MustEmulate(device devices.Device) *Page
- func (p *Page) MustEval(js string, params ...interface{}) proto.JSON
- func (p *Page) MustEvalOnNewDocument(js string)
- func (p *Page) MustExpose(name string) (callback chan string, stop func())
- func (p *Page) MustGetDownloadFile(pattern string) func() []byte
- func (p *Page) MustGetWindow() *proto.BrowserBounds
- func (p *Page) MustHandleDialog(accept bool, promptText string) (wait func())
- func (p *Page) MustHas(selector string) bool
- func (p *Page) MustHasR(selector, regex string) bool
- func (p *Page) MustHasX(selector string) bool
- func (p *Page) MustInfo() *proto.TargetTargetInfo
- func (p *Page) MustNavigate(url string) *Page
- func (p *Page) MustNavigateBack() *Page
- func (p *Page) MustNavigateForward() *Page
- func (p *Page) MustObjectToJSON(obj *proto.RuntimeRemoteObject) proto.JSON
- func (p *Page) MustObjectsToJSON(list []*proto.RuntimeRemoteObject) proto.JSON
- func (p *Page) MustPDF(toFile ...string) []byte
- func (p *Page) MustRelease(objectID proto.RuntimeRemoteObjectID) *Page
- func (p *Page) MustReload() *Page
- func (p *Page) MustScreenshot(toFile ...string) []byte
- func (p *Page) MustScreenshotFullPage(toFile ...string) []byte
- func (p *Page) MustSearch(queries ...string) *Element
- func (p *Page) MustSetCookies(cookies ...*proto.NetworkCookieParam) *Page
- func (p *Page) MustSetExtraHeaders(dict ...string) (cleanup func())
- func (p *Page) MustSetUserAgent(req *proto.NetworkSetUserAgentOverride) *Page
- func (p *Page) MustStopLoading() *Page
- func (p *Page) MustViewport(width, height int64, deviceScaleFactor float64, mobile bool) *Page
- func (p *Page) MustWait(js string, params ...interface{})
- func (p *Page) MustWaitIdle() *Page
- func (p *Page) MustWaitLoad() *Page
- func (p *Page) MustWaitNavigation() func()
- func (p *Page) MustWaitOpen() (wait func() (newPage *Page))
- func (p *Page) MustWaitPauseOpen() (wait func() *Page, resume func())
- func (p *Page) MustWaitRequestIdle(excludes ...string) (wait func())
- func (p *Page) MustWindow(left, top, width, height int64) *Page
- func (p *Page) MustWindowFullscreen() *Page
- func (p *Page) MustWindowMaximize() *Page
- func (p *Page) MustWindowMinimize() *Page
- func (p *Page) MustWindowNormal() *Page
- func (p *Page) Navigate(url string) error
- func (p *Page) NavigateBack() error
- func (p *Page) NavigateForward() error
- func (p *Page) ObjectToJSON(obj *proto.RuntimeRemoteObject) (proto.JSON, error)
- func (p *Page) Overlay(left, top, width, height float64, msg string) (remove func())
- func (p *Page) PDF(req *proto.PagePrintToPDF) (*StreamReader, error)
- func (p *Page) Race() *RaceContext
- func (p *Page) Release(objectID proto.RuntimeRemoteObjectID) error
- func (p *Page) Reload() error
- func (p *Page) Root() *Page
- func (p *Page) Screenshot(fullpage bool, req *proto.PageCaptureScreenshot) ([]byte, error)
- func (p *Page) Search(from, to int, queries ...string) (Elements, error)
- func (p *Page) SetCookies(cookies []*proto.NetworkCookieParam) error
- func (p *Page) SetExtraHeaders(dict []string) (func(), error)
- func (p *Page) SetUserAgent(req *proto.NetworkSetUserAgentOverride) error
- func (p *Page) SetViewport(params *proto.EmulationSetDeviceMetricsOverride) error
- func (p *Page) SetWindow(bounds *proto.BrowserBounds) error
- func (p *Page) Sleeper(sleeper func() utils.Sleeper) *Page
- func (p *Page) StopLoading() error
- func (p *Page) Timeout(d time.Duration) *Page
- func (p *Page) Wait(thisID proto.RuntimeRemoteObjectID, js string, params JSArgs) error
- func (p *Page) WaitEvent(e proto.Payload) (wait func())
- func (p *Page) WaitIdle(timeout time.Duration) (err error)
- func (p *Page) WaitLoad() error
- func (p *Page) WaitNavigation(name proto.PageLifecycleEventName) func()
- func (p *Page) WaitOpen() func() (*Page, error)
- func (p *Page) WaitPauseOpen() (func() (*Page, error), func() error, error)
- func (p *Page) WaitRequestIdle(d time.Duration, includes, excludes []string) func()
- type Pages
- type RaceContext
- func (rc *RaceContext) Do() error
- func (rc *RaceContext) Element(selector string, callback func(*Element) error) *RaceContext
- func (rc *RaceContext) ElementByJS(opts *EvalOptions, callback func(*Element) error) *RaceContext
- func (rc *RaceContext) ElementR(selector, regex string, callback func(*Element) error) *RaceContext
- func (rc *RaceContext) ElementX(selector string, callback func(*Element) error) *RaceContext
- func (rc *RaceContext) MustDo() *Page
- func (rc *RaceContext) MustElement(selector string, callback func(*Element)) *RaceContext
- func (rc *RaceContext) MustElementByJS(js string, params JSArgs, callback func(*Element) error) *RaceContext
- func (rc *RaceContext) MustElementR(selector, regex string, callback func(*Element)) *RaceContext
- func (rc *RaceContext) MustElementX(selector string, callback func(*Element)) *RaceContext
- type StreamReader
- type Touch
- func (t *Touch) Cancel() error
- func (t *Touch) End() error
- func (t *Touch) Move(points ...*proto.InputTouchPoint) error
- func (t *Touch) MustCancel() *Touch
- func (t *Touch) MustEnd() *Touch
- func (t *Touch) MustMove(points ...*proto.InputTouchPoint) *Touch
- func (t *Touch) MustStart(points ...*proto.InputTouchPoint) *Touch
- func (t *Touch) MustTap(x, y float64) *Touch
- func (t *Touch) Start(points ...*proto.InputTouchPoint) error
- func (t *Touch) Tap(x, y float64) error
- type TraceLog
- type TraceMsg
- type TraceType
Examples ¶
- Package
- Package (Customize_browser_launch)
- Package (Customize_retry_strategy)
- Package (Direct_cdp)
- Package (Disable_headless_to_debug)
- Package (Error_handling)
- Package (Handle_events)
- Package (Hijack_requests)
- Package (Page_pdf)
- Package (Page_screenshot)
- Package (Race_selectors)
- Package (Search)
- Package (States)
- Package (Timeout_handling)
- Package (Wait_for_animation)
- Package (Wait_for_request)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrValue error ErrValue = errors.New("error value") // ErrExpectElement error ErrExpectElement = errors.New("expect js to return an element") // ErrExpectElements error ErrExpectElements = errors.New("expect js to return an array of elements") // ErrElementNotFound error ErrElementNotFound = errors.New("cannot find element") // ErrSrcNotFound error ErrSrcNotFound = errors.New("element doesn't have src attribute") // ErrEval error ErrEval = errors.New("eval error") ErrNavigation = errors.New("navigation failed") // ErrPageCloseCanceled error ErrPageCloseCanceled = errors.New("page close canceled") // ErrNotClickable error ErrNotClickable = errors.New("element is not clickable") )
var DefaultSleeper = func() utils.Sleeper { return utils.BackoffSleeper(100*time.Millisecond, time.Second, nil) }
DefaultSleeper generates the default sleeper for retry, it uses backoff to grow the interval. The growth looks like: A(0) = 100ms, A(n) = A(n-1) * random[1.9, 2.1), A(n) < 1s
Functions ¶
func Event ¶
Event helps to convert a cdp.Event to proto.Payload. Returns false if the conversion fails
func SprintFnThis ¶
SprintFnThis wrap js with this, wrap function call if it's js expression
Types ¶
type Browser ¶
type Browser struct { // BrowserContextID is the id for incognito window BrowserContextID proto.BrowserBrowserContextID // contains filtered or unexported fields }
Browser represents the browser. It doesn't depends on file system, it should work with remote browser seamlessly. To check the env var you can use to quickly enable options from CLI, check here: https://pkg.go.dev/github.com/go-rod/rod/lib/defaults
func (*Browser) Call ¶
func (b *Browser) Call(ctx context.Context, sessionID, methodName string, params json.RawMessage) (res []byte, err error)
Call raw cdp interface directly
func (*Browser) CallContext ¶
CallContext parameters for proto
func (*Browser) CancelTimeout ¶
CancelTimeout context and reset the context to previous one
func (*Browser) ControlURL ¶
ControlURL set the url to remote control browser.
func (*Browser) DefaultViewport ¶ added in v0.49.3
func (b *Browser) DefaultViewport(viewport *proto.EmulationSetDeviceMetricsOverride) *Browser
DefaultViewport sets the default viewport for new page in the future. Default size is 1200x900. Set it to nil to disable it.
func (*Browser) DisableDomain ¶
func (b *Browser) DisableDomain(sessionID proto.TargetSessionID, method proto.Payload) (recover func())
DisableDomain and returns a recover function to restore previous state
func (*Browser) EachEvent ¶
func (b *Browser) EachEvent(callbacks ...interface{}) (wait func())
EachEvent of the specified event type, if any callback returns true the event loop will stop.
func (*Browser) EnableDomain ¶
func (b *Browser) EnableDomain(sessionID proto.TargetSessionID, method proto.Payload) (recover func())
EnableDomain and returns a recover function to restore previous state
func (*Browser) Event ¶
func (b *Browser) Event() *goob.Observable
Event returns the observable for browser events
func (*Browser) HandleAuth ¶
HandleAuth for the next basic HTTP authentication. It will prevent the popup that requires user to input user name and password. Ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
func (*Browser) HijackRequests ¶
func (b *Browser) HijackRequests() *HijackRouter
HijackRequests creates a new router instance for requests hijacking. When use Fetch domain outside the router should be stopped. Enabling hijacking disables page caching, but such as 304 Not Modified will still work as expected.
func (*Browser) IgnoreCertErrors ¶ added in v0.61.3
IgnoreCertErrors switch. If enabled, all certificate errors will be ignored.
func (*Browser) MustClose ¶ added in v0.50.0
func (b *Browser) MustClose()
MustClose the browser and release related resources
func (*Browser) MustConnect ¶ added in v0.50.0
MustConnect to the browser and start to control it. If fails to connect, try to run a local browser, if local browser not found try to download one.
func (*Browser) MustHandleAuth ¶ added in v0.50.0
MustHandleAuth for the next basic HTTP authentication. It will prevent the popup that requires user to input user name and password. Ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
func (*Browser) MustIgnoreCertErrors ¶ added in v0.61.3
MustIgnoreCertErrors switch. If enabled, all certificate errors will be ignored.
func (*Browser) MustIncognito ¶ added in v0.50.0
MustIncognito creates a new incognito browser
func (*Browser) MustPage ¶ added in v0.50.0
MustPage creates a new tab If url is empty, the default target will be "about:blank".
func (*Browser) MustPageFromTargetID ¶ added in v0.50.0
func (b *Browser) MustPageFromTargetID(targetID proto.TargetTargetID) *Page
MustPageFromTargetID creates a Page instance from a targetID
func (*Browser) Page ¶
Page doc is similar to the method MustPage If url is empty, the default target will be "about:blank".
func (*Browser) PageFromTarget ¶ added in v0.50.0
func (b *Browser) PageFromTarget(targetID proto.TargetTargetID) (*Page, error)
PageFromTarget creates a Page instance from a targetID
func (*Browser) ServeMonitor ¶
ServeMonitor starts the monitor server. The reason why not to use "chrome://inspect/#devices" is one target cannot be driven by multiple controllers.
func (*Browser) Slowmotion ¶
Slowmotion set the delay for each control action, such as the simulation of the human inputs
type Client ¶ added in v0.54.0
type Client interface { Connect(ctx context.Context) error Event() <-chan *cdp.Event Call(ctx context.Context, sessionID, method string, params interface{}) ([]byte, error) }
Client interface
type Element ¶
type Element struct { ObjectID proto.RuntimeRemoteObjectID // contains filtered or unexported fields }
Element represents the DOM element
func (*Element) Box ¶
Box returns the size of an element and its position relative to the main frame.
func (*Element) CallContext ¶
CallContext parameters for proto
func (*Element) CancelTimeout ¶
CancelTimeout context and reset the context to previous one
func (*Element) CanvasToImage ¶ added in v0.45.1
CanvasToImage get image data of a canvas. The default format is image/png. The default quality is 0.92. doc: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
func (*Element) Click ¶
func (el *Element) Click(button proto.InputMouseButton) error
Click will press then release the button just like a human.
func (*Element) Clickable ¶ added in v0.48.0
Clickable checks if the element is behind another element, such as when invisible or covered by a modal.
func (*Element) ContainsElement ¶ added in v0.48.0
ContainsElement check if the target is equal or inside the element.
func (*Element) Describe ¶
Describe doc is similar to the method MustDescribe please see https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-describeNode
func (*Element) ElementByJS ¶
func (el *Element) ElementByJS(opts *EvalOptions) (*Element, error)
ElementByJS doc is similar to the method MustElementByJS
func (*Element) ElementsByJS ¶
func (el *Element) ElementsByJS(opts *EvalOptions) (Elements, error)
ElementsByJS doc is similar to the method MustElementsByJS
func (*Element) Eval ¶
func (el *Element) Eval(js string, params ...interface{}) (*proto.RuntimeRemoteObject, error)
Eval doc is similar to the method MustEval
func (*Element) EvalWithOptions ¶ added in v0.50.0
func (el *Element) EvalWithOptions(opts *EvalOptions) (*proto.RuntimeRemoteObject, error)
EvalWithOptions of Eval
func (*Element) Matches ¶ added in v0.45.0
Matches checks if the element can be selected by the css selector
func (*Element) MustAttribute ¶ added in v0.50.0
MustAttribute returns the value of a specified attribute on the element. Please check the Property function before you use it, usually you don't want to use MustAttribute. https://stackoverflow.com/questions/6003819/what-is-the-difference-between-properties-and-attributes-in-html
func (*Element) MustBlur ¶ added in v0.50.0
MustBlur will call the blur function on the element. On inputs, this will deselect the element.
func (*Element) MustBox ¶ added in v0.50.0
MustBox returns the size of an element and its position relative to the main frame.
func (*Element) MustCanvasToImage ¶ added in v0.50.0
MustCanvasToImage get image data of a canvas. The default format is image/png. The default quality is 0.92. doc: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
func (*Element) MustClickable ¶ added in v0.50.0
MustClickable checks if the element is behind another element, such as when covered by a modal.
func (*Element) MustContainsElement ¶ added in v0.50.0
MustContainsElement check if the target is equal or inside the element.
func (*Element) MustDescribe ¶ added in v0.50.0
MustDescribe returns the element info Returned json: https://chromedevtools.github.io/devtools-protocol/tot/DOM#type-Node
func (*Element) MustElement ¶ added in v0.50.0
MustElement returns the first child that matches the css selector
func (*Element) MustElementByJS ¶ added in v0.50.0
MustElementByJS returns the element from the return value of the js
func (*Element) MustElementR ¶ added in v0.57.0
MustElementR returns the first element in the page that matches the CSS selector and its text matches the regex. The regex is the js regex, not golang's.
func (*Element) MustElementX ¶ added in v0.50.0
MustElementX returns the first child that matches the XPath selector
func (*Element) MustElements ¶ added in v0.50.0
MustElements returns all elements that match the css selector
func (*Element) MustElementsByJS ¶ added in v0.50.0
MustElementsByJS returns the elements from the return value of the js
func (*Element) MustElementsX ¶ added in v0.50.0
MustElementsX returns all elements that match the XPath selector
func (*Element) MustEval ¶ added in v0.50.0
MustEval evaluates js function on the element, the first param must be a js function definition For example: el.MustEval(`name => this.getAttribute(name)`, "value")
func (*Element) MustFrame ¶ added in v0.55.1
MustFrame creates a page instance that represents the iframe
func (*Element) MustHasR ¶ added in v0.61.0
MustHasR an element that matches the css selector and its text matches the regex.
func (*Element) MustInput ¶ added in v0.50.0
MustInput wll click the element and input the text. To empty the input you can use something like el.SelectAllText().MustInput("")
func (*Element) MustMatches ¶ added in v0.50.0
MustMatches checks if the element can be selected by the css selector
func (*Element) MustNodeID ¶ added in v0.50.0
MustNodeID of the node
func (*Element) MustParent ¶ added in v0.50.0
MustParent returns the parent element
func (*Element) MustParents ¶ added in v0.50.0
MustParents that match the selector
func (*Element) MustPrevious ¶ added in v0.50.0
MustPrevious returns the previous sibling element
func (*Element) MustProperty ¶ added in v0.50.0
MustProperty returns the value of a specified property on the element. It's similar to Attribute but attributes can only be string, properties can be types like bool, float, etc. https://stackoverflow.com/questions/6003819/what-is-the-difference-between-properties-and-attributes-in-html
func (*Element) MustRelease ¶ added in v0.50.0
func (el *Element) MustRelease()
MustRelease remote object on browser
func (*Element) MustResource ¶ added in v0.50.0
MustResource returns the binary of the "src" properly, such as the image or audio file.
func (*Element) MustScreenshot ¶ added in v0.50.0
MustScreenshot of the area of the element
func (*Element) MustScrollIntoView ¶ added in v0.50.0
MustScrollIntoView scrolls the current element into the visible area of the browser window if it's not already within the visible area.
func (*Element) MustSelect ¶ added in v0.50.0
MustSelect the option elements that match the selectors, the selector can be text content or css selector
func (*Element) MustSelectAllText ¶ added in v0.50.0
MustSelectAllText selects all text
func (*Element) MustSelectText ¶ added in v0.50.0
MustSelectText selects the text that matches the regular expression
func (*Element) MustSetFiles ¶ added in v0.50.0
MustSetFiles sets files for the given file input element
func (*Element) MustShadowRoot ¶ added in v0.50.0
MustShadowRoot returns the shadow root of this element
func (*Element) MustVisible ¶ added in v0.50.0
MustVisible returns true if the element is visible on the page
func (*Element) MustWaitInvisible ¶ added in v0.50.0
MustWaitInvisible until the element is not visible or removed
func (*Element) MustWaitLoad ¶ added in v0.50.0
MustWaitLoad for element like <img />
func (*Element) MustWaitStable ¶ added in v0.50.0
MustWaitStable waits until the size and position are stable. Useful when waiting for the animation of modal or button to complete so that we can simulate the mouse to move to it and click on it.
func (*Element) MustWaitVisible ¶ added in v0.50.0
MustWaitVisible until the element is visible
func (*Element) Screenshot ¶
func (el *Element) Screenshot(format proto.PageCaptureScreenshotFormat, quality int) ([]byte, error)
Screenshot of the area of the element
func (*Element) ScrollIntoView ¶
ScrollIntoView doc is similar to the method MustScrollIntoViewIfNeeded
func (*Element) SelectAllText ¶
SelectAllText doc is similar to the method MustSelectAllText
func (*Element) SelectText ¶
SelectText doc is similar to the method MustSelectText
func (*Element) ShadowRoot ¶
ShadowRoot returns the shadow root of this element
func (*Element) WaitInvisible ¶
WaitInvisible doc is similar to the method MustWaitInvisible
func (*Element) WaitStable ¶
WaitStable not using requestAnimation here because it can trigger to many checks, or miss checks for jQuery css animation.
func (*Element) WaitVisible ¶
WaitVisible doc is similar to the method MustWaitVisible
type Elements ¶
type Elements []*Element
Elements provides some helpers to deal with element list
type Error ¶
type Error struct { // Code is used to tell error types Code error // Details is a JSON object Details interface{} }
Error type for rod
type EvalOptions ¶ added in v0.50.0
type EvalOptions struct { // If enabled the eval will return an reference id for the // remote object. If disabled the remote object will be return as json. ByValue bool // ThisID is the this object when eval the js ThisID proto.RuntimeRemoteObjectID // JS function code to eval JS string // JSArgs of the js function JSArgs JSArgs }
EvalOptions object
func NewEvalOptions ¶ added in v0.50.0
func NewEvalOptions(js string, args JSArgs) *EvalOptions
NewEvalOptions creates a new EvalPayload
func (*EvalOptions) ByObject ¶ added in v0.50.0
func (e *EvalOptions) ByObject() *EvalOptions
ByObject disables ByValue.
func (*EvalOptions) This ¶ added in v0.50.0
func (e *EvalOptions) This(id proto.RuntimeRemoteObjectID) *EvalOptions
This set the ThisID
type Hijack ¶
type Hijack struct { Request *HijackRequest Response *HijackResponse OnError func(error) // Skip to next handler Skip bool // contains filtered or unexported fields }
Hijack context
func (*Hijack) ContinueRequest ¶ added in v0.42.0
func (h *Hijack) ContinueRequest(cq *proto.FetchContinueRequest)
ContinueRequest without hijacking
func (*Hijack) LoadResponse ¶
LoadResponse will send request to the real destination and load the response as default response to override.
func (*Hijack) MustLoadResponse ¶ added in v0.50.0
func (h *Hijack) MustLoadResponse()
MustLoadResponse will send request to the real destination and load the response as default response to override.
type HijackRequest ¶
type HijackRequest struct {
// contains filtered or unexported fields
}
HijackRequest context
func (*HijackRequest) Body ¶
func (ctx *HijackRequest) Body() string
Body of the request, devtools API doesn't support binary data yet, only string can be captured.
func (*HijackRequest) Headers ¶
func (ctx *HijackRequest) Headers() proto.NetworkHeaders
Headers of request
func (*HijackRequest) JSONBody ¶
func (ctx *HijackRequest) JSONBody() gjson.Result
JSONBody of the request
func (*HijackRequest) Req ¶ added in v0.52.0
func (ctx *HijackRequest) Req() *http.Request
Req returns the underlaying http.Request instance that will be used to send the request.
func (*HijackRequest) SetBody ¶
func (ctx *HijackRequest) SetBody(obj interface{}) *HijackRequest
SetBody of the request, if obj is []byte or string, raw body will be used, else it will be encoded as json.
func (*HijackRequest) SetContext ¶ added in v0.57.1
func (ctx *HijackRequest) SetContext(c context.Context) *HijackRequest
SetContext of the underlaying http.Request instance
func (*HijackRequest) Type ¶ added in v0.49.1
func (ctx *HijackRequest) Type() proto.NetworkResourceType
Type of the resource
type HijackResponse ¶
type HijackResponse struct {
// contains filtered or unexported fields
}
HijackResponse context
func (*HijackResponse) Fail ¶ added in v0.48.1
func (ctx *HijackResponse) Fail(reason proto.NetworkErrorReason) *HijackResponse
Fail request
func (*HijackResponse) Headers ¶
func (ctx *HijackResponse) Headers() http.Header
Headers of the payload
func (*HijackResponse) Payload ¶ added in v0.52.0
func (ctx *HijackResponse) Payload() *proto.FetchFulfillRequest
Payload to respond the request from the browser.
func (*HijackResponse) SetBody ¶
func (ctx *HijackResponse) SetBody(obj interface{}) *HijackResponse
SetBody of the payload, if obj is []byte or string, raw body will be used, else it will be encoded as json.
func (*HijackResponse) SetHeader ¶
func (ctx *HijackResponse) SetHeader(pairs ...string) *HijackResponse
SetHeader of the payload via key-value pairs
type HijackRouter ¶
type HijackRouter struct {
// contains filtered or unexported fields
}
HijackRouter context
func (*HijackRouter) Add ¶
func (r *HijackRouter) Add(pattern string, resourceType proto.NetworkResourceType, handler func(*Hijack)) error
Add a hijack handler to router, the doc of the pattern is the same as "proto.FetchRequestPattern.URLPattern". You can add new handler even after the "Run" is called.
func (*HijackRouter) MustAdd ¶ added in v0.50.0
func (r *HijackRouter) MustAdd(pattern string, handler func(*Hijack)) *HijackRouter
MustAdd a hijack handler to router, the doc of the pattern is the same as "proto.FetchRequestPattern.URLPattern". You can add new handler even after the "Run" is called.
func (*HijackRouter) MustRemove ¶ added in v0.50.0
func (r *HijackRouter) MustRemove(pattern string) *HijackRouter
MustRemove handler via the pattern
func (*HijackRouter) MustStop ¶ added in v0.50.0
func (r *HijackRouter) MustStop()
MustStop the router
func (*HijackRouter) Remove ¶
func (r *HijackRouter) Remove(pattern string) error
Remove handler via the pattern
func (*HijackRouter) Run ¶
func (r *HijackRouter) Run()
Run the router, after you call it, you shouldn't add new handler to it.
type JSArgs ¶ added in v0.57.0
type JSArgs []interface{}
JSArgs for eval
func JSArgsFromString ¶ added in v0.57.0
JSArgsFromString converts a string list into Array type
type Keyboard ¶
Keyboard represents the keyboard on a page, it's always related the main frame
func (*Keyboard) InsertText ¶
InsertText doc is similar to the method MustInsertText
func (*Keyboard) MustInsertText ¶ added in v0.50.0
MustInsertText like paste text into the page
type Mouse ¶
Mouse represents the mouse on a page, it's always related the main frame
func (*Mouse) Click ¶
func (m *Mouse) Click(button proto.InputMouseButton) error
Click doc is similar to the method MustClick
func (*Mouse) Down ¶
func (m *Mouse) Down(button proto.InputMouseButton, clicks int64) error
Down doc is similar to the method MustDown
func (*Mouse) MustClick ¶ added in v0.50.0
func (m *Mouse) MustClick(button proto.InputMouseButton) *Mouse
MustClick will press then release the button
func (*Mouse) MustDown ¶ added in v0.50.0
func (m *Mouse) MustDown(button proto.InputMouseButton) *Mouse
MustDown holds the button down
func (*Mouse) MustScroll ¶ added in v0.50.0
MustScroll with the relative offset
func (*Mouse) MustUp ¶ added in v0.50.0
func (m *Mouse) MustUp(button proto.InputMouseButton) *Mouse
MustUp release the button
type Page ¶
type Page struct { TargetID proto.TargetTargetID SessionID proto.TargetSessionID FrameID proto.PageFrameID // devices Mouse *Mouse Keyboard *Keyboard Touch *Touch // contains filtered or unexported fields }
Page represents the webpage We try to hold as less states as possible
func (*Page) AddScriptTag ¶
AddScriptTag to page. If url is empty, content will be used.
func (*Page) AddStyleTag ¶
AddStyleTag to page. If url is empty, content will be used.
func (*Page) CallContext ¶
CallContext parameters for proto
func (*Page) CancelTimeout ¶
CancelTimeout context and reset the context to previous one
func (*Page) Cookies ¶
func (p *Page) Cookies(urls []string) ([]*proto.NetworkCookie, error)
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) DisableDomain ¶
DisableDomain and returns a recover function to restore previous state
func (*Page) EachEvent ¶
func (p *Page) EachEvent(callbacks ...interface{}) (wait func())
EachEvent of the specified event type, if any callback returns true the event loop will stop.
func (*Page) ElementByJS ¶
func (p *Page) ElementByJS(opts *EvalOptions) (*Element, error)
ElementByJS returns the element from the return value of the js function. If sleeper is nil, no retry will be performed. thisID is the this value of the js function, when thisID is "", the this context will be the "window". If the js function returns "null", ElementByJS will retry, you can use custom sleeper to make it only retry once.
func (*Page) ElementFromNode ¶ added in v0.47.0
ElementFromNode creates an Element from the node id
func (*Page) ElementFromObject ¶ added in v0.47.0
func (p *Page) ElementFromObject(id proto.RuntimeRemoteObjectID) *Element
ElementFromObject creates an Element from the remote object id.
func (*Page) ElementFromPoint ¶ added in v0.48.0
ElementFromPoint creates an Element from the absolute point on the page. The point should include the window scroll offset.
func (*Page) ElementsByJS ¶
func (p *Page) ElementsByJS(opts *EvalOptions) (Elements, error)
ElementsByJS is different from ElementByJSE, it doesn't do retry
func (*Page) Emulate ¶ added in v0.42.1
Emulate the device, such as iPhone9. If device is devices.Clear, it will clear the override.
func (*Page) EnableDomain ¶
EnableDomain and returns a recover function to restore previous state
func (*Page) Eval ¶
func (p *Page) Eval(js string, jsArgs ...interface{}) (*proto.RuntimeRemoteObject, error)
Eval evalutes javascript on the page.
func (*Page) EvalOnNewDocument ¶ added in v0.44.0
func (p *Page) EvalOnNewDocument(js string) (proto.PageScriptIdentifier, error)
EvalOnNewDocument Evaluates given script in every frame upon creation (before loading frame's scripts).
func (*Page) EvalWithOptions ¶ added in v0.50.0
func (p *Page) EvalWithOptions(opts *EvalOptions) (*proto.RuntimeRemoteObject, error)
EvalWithOptions thisID is the remote objectID that will be the this of the js function, if it's empty "window" will be used. Set the byValue to true to reduce memory occupation. If the item in jsArgs is proto.RuntimeRemoteObjectID, the remote object will be used, else the item will be treated as JSON value.
func (*Page) Expose ¶ added in v0.49.1
Expose function to the page's window object. Must bind before navigate to the page. Bindings survive reloads. Binding function takes exactly one argument, this argument should be string.
func (*Page) ExposeJSHelper ¶ added in v0.45.0
ExposeJSHelper to page's window object, so you can debug helper.js in the browser console. Such as run `rod.elementR("div", "ok")` in the browser console to test the Page.ElementR.
func (*Page) GetDownloadFile ¶
func (p *Page) GetDownloadFile(pattern string, resourceType proto.NetworkResourceType, client *http.Client) func() (http.Header, []byte, error)
GetDownloadFile of the next download url that matches the pattern, returns the file content. The handler will be used once and removed.
func (*Page) GetWindow ¶
func (p *Page) GetWindow() (*proto.BrowserBounds, error)
GetWindow doc is similar to the method MustGetWindow
func (*Page) HandleDialog ¶
HandleDialog doc is similar to the method MustHandleDialog. Because the js will be paused, you should put the code that triggers in a goroutine.
func (*Page) HijackRequests ¶
func (p *Page) HijackRequests() *HijackRouter
HijackRequests same as Browser.HijackRequests, but scoped with the page
func (*Page) Info ¶ added in v0.42.1
func (p *Page) Info() (*proto.TargetTargetInfo, error)
Info of the page, such as the URL or title of the page
func (*Page) MustAddScriptTag ¶ added in v0.50.0
MustAddScriptTag to page. If url is empty, content will be used.
func (*Page) MustAddStyleTag ¶ added in v0.50.0
MustAddStyleTag to page. If url is empty, content will be used.
func (*Page) MustCookies ¶ added in v0.50.0
func (p *Page) MustCookies(urls ...string) []*proto.NetworkCookie
MustCookies 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) MustElement ¶ added in v0.50.0
MustElement retries until an element in the page that matches one of the CSS selectors
func (*Page) MustElementByJS ¶ added in v0.50.0
MustElementByJS retries until returns the element from the return value of the js function
func (*Page) MustElementFromNode ¶ added in v0.50.0
MustElementFromNode creates an Element from the node id
func (*Page) MustElementFromPoint ¶ added in v0.50.0
MustElementFromPoint creates an Element from the absolute point on the page. The point should include the window scroll offset.
func (*Page) MustElementR ¶ added in v0.57.0
MustElementR retries until an element in the page that matches one of the pairs. Each pairs is a css selector and a regex. A sample call will look like page.MustElementR("div", "click me"). The regex is the js regex, not golang's.
func (*Page) MustElementX ¶ added in v0.50.0
MustElementX retries until an element in the page that matches one of the XPath selectors
func (*Page) MustElements ¶ added in v0.50.0
MustElements returns all elements that match the css selector
func (*Page) MustElementsByJS ¶ added in v0.50.0
MustElementsByJS returns the elements from the return value of the js
func (*Page) MustElementsX ¶ added in v0.50.0
MustElementsX returns all elements that match the XPath selector
func (*Page) MustEmulate ¶ added in v0.50.0
MustEmulate the device, such as iPhone9. If device is empty, it will clear the override.
func (*Page) MustEval ¶ added in v0.50.0
MustEval js on the page. The first param must be a js function definition. For example page.MustEval(`n => n + 1`, 1) will return 2
func (*Page) MustEvalOnNewDocument ¶ added in v0.50.0
MustEvalOnNewDocument Evaluates given script in every frame upon creation (before loading frame's scripts).
func (*Page) MustExpose ¶ added in v0.50.0
MustExpose function to the page's window object. Must bind before navigate to the page. Bindings survive reloads. Binding function takes exactly one argument, this argument should be string.
func (*Page) MustGetDownloadFile ¶ added in v0.50.0
MustGetDownloadFile of the next download url that matches the pattern, returns the file content.
func (*Page) MustGetWindow ¶ added in v0.50.0
func (p *Page) MustGetWindow() *proto.BrowserBounds
MustGetWindow get window bounds
func (*Page) MustHandleDialog ¶ added in v0.50.0
MustHandleDialog accepts or dismisses next JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) Because alert will block js, usually you have to run the wait function inside a goroutine. Check the unit test for it for more information.
func (*Page) MustHasR ¶ added in v0.61.0
MustHasR an element that matches the css selector and its text matches the regex.
func (*Page) MustInfo ¶ added in v0.50.0
func (p *Page) MustInfo() *proto.TargetTargetInfo
MustInfo of the page, such as the URL or title of the page
func (*Page) MustNavigate ¶ added in v0.50.0
MustNavigate to url If url is empty, it will navigate to "about:blank".
func (*Page) MustNavigateBack ¶ added in v0.61.4
MustNavigateBack history
func (*Page) MustNavigateForward ¶ added in v0.61.4
MustNavigateForward history
func (*Page) MustObjectToJSON ¶ added in v0.50.0
func (p *Page) MustObjectToJSON(obj *proto.RuntimeRemoteObject) proto.JSON
MustObjectToJSON by remote object
func (*Page) MustObjectsToJSON ¶ added in v0.50.0
func (p *Page) MustObjectsToJSON(list []*proto.RuntimeRemoteObject) proto.JSON
MustObjectsToJSON by remote objects
func (*Page) MustRelease ¶ added in v0.50.0
func (p *Page) MustRelease(objectID proto.RuntimeRemoteObjectID) *Page
MustRelease remote object
func (*Page) MustScreenshot ¶ added in v0.50.0
MustScreenshot the page and returns the binary of the image If the toFile is "", it will save output to "tmp/screenshots" folder, time as the file name.
func (*Page) MustScreenshotFullPage ¶ added in v0.50.0
MustScreenshotFullPage including all scrollable content and returns the binary of the image.
func (*Page) MustSearch ¶ added in v0.50.0
MustSearch for each given query in the DOM tree until find one, 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) MustSetCookies ¶ added in v0.50.0
func (p *Page) MustSetCookies(cookies ...*proto.NetworkCookieParam) *Page
MustSetCookies of the page. Cookie format: https://chromedevtools.github.io/devtools-protocol/tot/Network#method-setCookie
func (*Page) MustSetExtraHeaders ¶ added in v0.50.0
MustSetExtraHeaders whether to always send extra HTTP headers with the requests from this page. The arguments are key-value pairs, you can set multiple key-value pairs at the same time.
func (*Page) MustSetUserAgent ¶ added in v0.50.0
func (p *Page) MustSetUserAgent(req *proto.NetworkSetUserAgentOverride) *Page
MustSetUserAgent Allows overriding user agent with the given string. If req is nil, the default user agent will be the same as a mac chrome.
func (*Page) MustStopLoading ¶ added in v0.50.0
MustStopLoading forces the page stop all navigations and pending resource fetches.
func (*Page) MustViewport ¶ added in v0.50.0
MustViewport overrides the values of device screen dimensions.
func (*Page) MustWaitIdle ¶ added in v0.50.0
MustWaitIdle wait until the next window.requestIdleCallback is called.
func (*Page) MustWaitLoad ¶ added in v0.50.0
MustWaitLoad wait until the `window.onload` is complete, resolve immediately if already fired.
func (*Page) MustWaitNavigation ¶ added in v0.63.2
func (p *Page) MustWaitNavigation() func()
MustWaitNavigation wait for lifecycle event "networkAlmostIdle" when navigating.
func (*Page) MustWaitOpen ¶ added in v0.50.0
MustWaitOpen waits for a new page opened by the current one
func (*Page) MustWaitPauseOpen ¶ added in v0.50.0
MustWaitPauseOpen waits for a page opened by the current page, before opening pause the js execution. Because the js will be paused, you should put the code that triggers it in a goroutine, such as the click.
func (*Page) MustWaitRequestIdle ¶ added in v0.50.0
MustWaitRequestIdle returns a wait function that waits until the page doesn't send request for 300ms. You can pass regular expressions to exclude the requests by their url.
func (*Page) MustWindow ¶ added in v0.50.0
MustWindow set the window location and size
func (*Page) MustWindowFullscreen ¶ added in v0.50.0
MustWindowFullscreen the window
func (*Page) MustWindowMaximize ¶ added in v0.50.0
MustWindowMaximize the window
func (*Page) MustWindowMinimize ¶ added in v0.50.0
MustWindowMinimize the window
func (*Page) MustWindowNormal ¶ added in v0.50.0
MustWindowNormal the window size
func (*Page) Navigate ¶
Navigate doc is similar to the method MustNavigate If url is empty, it will navigate to "about:blank".
func (*Page) NavigateBack ¶ added in v0.61.4
NavigateBack history.
func (*Page) NavigateForward ¶ added in v0.61.4
NavigateForward history.
func (*Page) ObjectToJSON ¶
ObjectToJSON by object id
func (*Page) PDF ¶
func (p *Page) PDF(req *proto.PagePrintToPDF) (*StreamReader, error)
PDF prints page as PDF
func (*Page) Race ¶ added in v0.57.0
func (p *Page) Race() *RaceContext
Race creates a context to race selectors
func (*Page) Release ¶
func (p *Page) Release(objectID proto.RuntimeRemoteObjectID) error
Release doc is similar to the method MustRelease
func (*Page) Screenshot ¶
Screenshot options: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-captureScreenshot
func (*Page) Search ¶ added in v0.47.0
Search for each 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 ¶
func (p *Page) SetCookies(cookies []*proto.NetworkCookieParam) error
SetCookies of the page. Cookie format: https://chromedevtools.github.io/devtools-protocol/tot/Network#method-setCookie
func (*Page) SetExtraHeaders ¶
SetExtraHeaders whether to always send extra HTTP headers with the requests from this page.
func (*Page) SetUserAgent ¶
func (p *Page) SetUserAgent(req *proto.NetworkSetUserAgentOverride) error
SetUserAgent Allows overriding user agent with the given string. If req is nil, the default user agent will be the same as a mac chrome.
func (*Page) SetViewport ¶ added in v0.62.0
func (p *Page) SetViewport(params *proto.EmulationSetDeviceMetricsOverride) error
SetViewport doc is similar to the method MustViewport. If params is nil, it will clear the override.
func (*Page) SetWindow ¶ added in v0.62.0
func (p *Page) SetWindow(bounds *proto.BrowserBounds) error
SetWindow https://chromedevtools.github.io/devtools-protocol/tot/Browser#type-Bounds
func (*Page) StopLoading ¶
StopLoading forces the page stop navigation and pending resource fetches.
func (*Page) WaitEvent ¶
WaitEvent waits for the next event for one time. It will also load the data into the event object.
func (*Page) WaitNavigation ¶ added in v0.63.2
func (p *Page) WaitNavigation(name proto.PageLifecycleEventName) func()
WaitNavigation wait for a page lifecycle event when navigating. Usually you will wait for proto.PageLifecycleEventNameNetworkAlmostIdle
func (*Page) WaitPauseOpen ¶ added in v0.49.3
WaitPauseOpen waits for a page opened by the current page, before opening pause the js execution. Because the js will be paused, you should put the code that triggers it in a goroutine.
func (*Page) WaitRequestIdle ¶
WaitRequestIdle returns a wait function that waits until no request for d duration. Be careful, d is not the max wait timeout, it's the least idle time. If you want to set a timeout you can use the "Page.Timeout" function. Use the includes and excludes regexp list to filter the requests by their url.
type Pages ¶
type Pages []*Page
Pages provides some helpers to deal with page list
func (Pages) First ¶ added in v0.53.0
First returns the first page, if the list is empty returns nil
func (Pages) MustFind ¶ added in v0.50.3
MustFind the page that has the specified element with the css selector
func (Pages) MustFindByURL ¶ added in v0.50.0
MustFindByURL returns the page that has the url that matches the regex
type RaceContext ¶ added in v0.57.0
type RaceContext struct {
// contains filtered or unexported fields
}
RaceContext stores the branches to race
func (*RaceContext) Element ¶ added in v0.57.0
func (rc *RaceContext) Element(selector string, callback func(*Element) error) *RaceContext
Element the doc is similar with MustElement but has a callback when a match is found
func (*RaceContext) ElementByJS ¶ added in v0.57.0
func (rc *RaceContext) ElementByJS(opts *EvalOptions, callback func(*Element) error) *RaceContext
ElementByJS the doc is similar with MustElementByJS but has a callback when a match is found
func (*RaceContext) ElementR ¶ added in v0.57.0
func (rc *RaceContext) ElementR(selector, regex string, callback func(*Element) error) *RaceContext
ElementR the doc is similar with ElementR but has a callback when a match is found
func (*RaceContext) ElementX ¶ added in v0.57.0
func (rc *RaceContext) ElementX(selector string, callback func(*Element) error) *RaceContext
ElementX the doc is similar with ElementX but has a callback when a match is found
func (*RaceContext) MustElement ¶ added in v0.57.0
func (rc *RaceContext) MustElement(selector string, callback func(*Element)) *RaceContext
MustElement the doc is similar with MustElement but has a callback when a match is found
func (*RaceContext) MustElementByJS ¶ added in v0.57.0
func (rc *RaceContext) MustElementByJS(js string, params JSArgs, callback func(*Element) error) *RaceContext
MustElementByJS the doc is similar with MustElementByJS but has a callback when a match is found
func (*RaceContext) MustElementR ¶ added in v0.57.0
func (rc *RaceContext) MustElementR(selector, regex string, callback func(*Element)) *RaceContext
MustElementR the doc is similar with MustElement but has a callback when a match is found
func (*RaceContext) MustElementX ¶ added in v0.57.0
func (rc *RaceContext) MustElementX(selector string, callback func(*Element)) *RaceContext
MustElementX the doc is similar with MustElement but has a callback when a match is found
type StreamReader ¶ added in v0.63.0
type StreamReader struct { Offset int64 // contains filtered or unexported fields }
StreamReader for browser data stream
func NewStreamReader ¶ added in v0.63.0
func NewStreamReader(c proto.Caller, h proto.IOStreamHandle) *StreamReader
NewStreamReader instance
type Touch ¶ added in v0.61.1
type Touch struct {
// contains filtered or unexported fields
}
Touch presents a touch device, such as a hand with fingers, each finger is a proto.InputTouchPoint. Touch events is stateless, we use the struct here only as a namespace to make the API style unified.
func (*Touch) Move ¶ added in v0.61.1
func (t *Touch) Move(points ...*proto.InputTouchPoint) error
Move touch points. Use the InputTouchPoint.ID (Touch.identifier) to track points. Doc: https://developer.mozilla.org/en-US/docs/Web/API/Touch_events
func (*Touch) MustCancel ¶ added in v0.61.1
MustCancel touch action
func (*Touch) MustMove ¶ added in v0.61.1
func (t *Touch) MustMove(points ...*proto.InputTouchPoint) *Touch
MustMove touch points. Use the InputTouchPoint.ID (Touch.identifier) to track points. Doc: https://developer.mozilla.org/en-US/docs/Web/API/Touch_events
func (*Touch) MustStart ¶ added in v0.61.1
func (t *Touch) MustStart(points ...*proto.InputTouchPoint) *Touch
MustStart a touch action
type TraceMsg ¶ added in v0.59.0
type TraceMsg struct { // Type of the message Type TraceType // Details is a json object Details interface{} }
TraceMsg for logger
type TraceType ¶ added in v0.59.0
type TraceType string
TraceType for logger
const ( // TraceTypeWaitRequestsIdle type TraceTypeWaitRequestsIdle TraceType = "wait requests idle" // TraceTypeWaitRequests type TraceTypeWaitRequests TraceType = "wait requests" // TraceTypeEval type TraceTypeEval TraceType = "eval" // TraceTypeAction type TraceTypeAction TraceType = "act" // TraceTypeInput type TraceTypeInput TraceType = "input" )
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
fixtures
|
|
lib
|
|
defaults
Package defaults holds some commonly used options parsed from env var "rod".
|
Package defaults holds some commonly used options parsed from env var "rod". |
examples/custom-websocket
Module
|