Categorygithub.com/mpdroog/godet
modulepackage
0.0.0-20250221112557-ed96c784c1f1
Repository: https://github.com/mpdroog/godet.git
Documentation: pkg.go.dev

# README

Go Documentation Go Report Card Actions Status

godet

Remote client for Chrome DevTools

Installation

$ go get github.com/raff/godet

Documentation

http://godoc.org/github.com/raff/godet

Example

A pretty complete example is available at cmd/godet/main.go. This example is available at examples/example.go.

import "github.com/raff/godet"

// connect to Chrome instance
remote, err := godet.Connect("localhost:9222", true)
if err != nil {
    fmt.Println("cannot connect to Chrome instance:", err)
    return
}

// disconnect when done
defer remote.Close()

// get browser and protocol version
version, _ := remote.Version()
fmt.Println(version)

// get list of open tabs
tabs, _ := remote.TabList("")
fmt.Println(tabs)

// install some callbacks
remote.CallbackEvent(godet.EventClosed, func(params godet.Params) {
    fmt.Println("RemoteDebugger connection terminated.")
})

remote.CallbackEvent("Network.requestWillBeSent", func(params godet.Params) {
    fmt.Println("requestWillBeSent",
        params["type"],
        params["documentURL"],
        params["request"].(map[string]interface{})["url"])
})

remote.CallbackEvent("Network.responseReceived", func(params godet.Params) {
    fmt.Println("responseReceived",
        params["type"],
        params["response"].(map[string]interface{})["url"])
})

remote.CallbackEvent("Log.entryAdded", func(params godet.Params) {
    entry := params["entry"].(map[string]interface{})
    fmt.Println("LOG", entry["type"], entry["level"], entry["text"])
})

// block loading of most images
_ = remote.SetBlockedURLs("*.jpg", "*.png", "*.gif")

// create new tab
tab, _ := remote.NewTab("https://www.google.com")
fmt.Println(tab)

// enable event processing
remote.RuntimeEvents(true)
remote.NetworkEvents(true)
remote.PageEvents(true)
remote.DOMEvents(true)
remote.LogEvents(true)

// navigate in existing tab
_ = remote.ActivateTab(tabs[0])

// re-enable events when changing active tab
remote.AllEvents(true) // enable all events

_, _ = remote.Navigate("https://www.google.com")

// evaluate Javascript expression in existing context
res, _ := remote.EvaluateWrap(`
    console.log("hello from godet!")
    return 42;
`)
fmt.Println(res)

// take a screenshot
_ = remote.SaveScreenshot("screenshot.png", 0644, 0, true)

// or save page as PDF
_ = remote.SavePDF("page.pdf", 0644)

# Packages

No description provided by the author

# Functions

If set, after this many virtual milliseconds have elapsed virtual time will be paused and a\nvirtualTimeBudgetExpired event is sent.
No description provided by the author
Connect to the remote debugger and return `RemoteDebugger` object.
ConsoleAPICallback processes the Runtime.consolAPICalled event and returns printable info.
Dimensions sets the current page dimensions for PrintToPDF.
DisplayHeaderFooter instructs PrintToPDF to print headers/footers or not.
No description provided by the author
Headers set specified HTTP headers.
Host set the host header.
No description provided by the author
If set, base::Time::Now will be overriden to initially return this value.
LandscapeMode instructs PrintToPDF to print pages in landscape mode.
No description provided by the author
Margins sets the margin sizes for PrintToPDF.
If set this specifies the maximum number of tasks that can be run before virtual is forced\nforwards to prevent deadlock.
No description provided by the author
No description provided by the author
PageRanges instructs PrintToPDF to print only the specified range of pages.
PortraitMode instructs PrintToPDF to print pages in portrait mode.
printBackground instructs PrintToPDF to print background graphics.
No description provided by the author
No description provided by the author
Scale instructs PrintToPDF to scale the pages (1.0 is current scale).
No description provided by the author
No description provided by the author
No description provided by the author
If set the virtual time policy change should be deferred until any frame starts navigating.\nNote any previous deferred policy change is superseded.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
EventClosed represents the "RemoteDebugger.closed" event.
EventClosed represents the "RemoteDebugger.disconnected" event.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NavigationCancel cancels the navigation.
NavigationCancelAndIgnore cancels the navigation and makes the requester of the navigation acts like the request was never made.
NavigationProceed allows the navigation.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
VirtualTimePolicyAdvance specifies that if the scheduler runs out of immediate work, the virtual time base may fast forward to allow the next delayed task (if any) to run.
VirtualTimePolicyPause specifies that the virtual time base may not advance.
VirtualTimePolicyPauseIfNetworkFetchesPending specifies that the virtual time base may not advance if there are any pending resource fetches.

# Variables

ErrorClose is returned if a method is called after the connection has been close.
ErrorNoActiveTab is returned if there are no active tabs (of type "page").
ErrorNoResponse is returned if a method was expecting a response but got nil instead.
ErrorNoWsURL is returned if the active tab has no websocket URL.
default gorilla/websocket buffer size.
this should be large enough to send large scripts.

# Structs

No description provided by the author
Domain holds a domain name and version.
EvaluateError is returned by Evaluate in case of expression errors.
No description provided by the author
NavigationEntry represent a navigation history entry.
Profile represents a profile data structure.
ProfileNode represents a profile node data structure.
RemoteDebugger implements an interface for Chrome DevTools.
No description provided by the author
Tab represents an opened tab/page.
Version holds the DevTools version information.

# Type aliases

No description provided by the author
DownloadBehaviour defines the type for Page.SetDownloadBehavior.
ErrorReason defines what error should be generated to abort a request in ContinueInterceptedRequest.
No description provided by the author
EventCallback represents a callback event, associated with a method.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NavigationResponse defines the type for ProcessNavigation `response`.
Params is a type alias for the event params structure.
PrintToPDFOption defines the functional option for PrintToPDF.
No description provided by the author
No description provided by the author
No description provided by the author
VirtualTimePolicy defines the type for Emulation.SetVirtualTimePolicy.