-
Notifications
You must be signed in to change notification settings - Fork 17
Overview
The API is laid out match the Chrme DevTools Protocol Viewer documentation. That documentation should be used to reference specific behavior and data. Standard GoDoc generated documentation is also available and kept updated.
Following the examples of starting Chrome and opening a new tab, the full DevTools Protocol is available. The API "Domains" are available as methods that return a struct containing the methods available to each domain. For example, to execute the Page.captureScreenshot
call, simply execute the matching call using your tab
reference pointer:
resultChan := tab.Page().CaptureScreenshot(
&page.CaptureScreenshotParams{
Format: page.Format.Jpeg,
Quality: 50,
},
)
screenshot := <-resultChan
Notice that the call returns a channel that will return the results when they become available. This is due to the asyncronous nature of writing messages to a socket and polling for the response and is true of all calls in this API. Because this is consistent across all protocol calls, a more idomatic way of writing code for calls that need to block until a response is available is to receive directly from the channel rather than writing it to a variable:
screenshot := <-tab.Page().CaptureScreenshot(
&page.CaptureScreenshotParams{
Format: page.Format.Jpeg,
Quality: 50,
},
)
There are some portions of the DevTools Protocol that conflict with idiomatic Go practices, in those cases the naming paridigm has been broken a bit. For example, the protocol data type Animation.AnimationEffect
has been renamed to animation.Effect
to avoid stutter in the API. This change has been consistently made across all data types that would cause similar stutter.
All protocol calls that take parameters accept a struct matching the method call with the string Params
appended and ALL calls return a struct named similarly but with the string Result
appended. As in the example above, the method Page.CaptureScreenshot
accepts a pointer to a page.CaptureScreenshotParams
struct and returns a pointer to an page.CaptureScreenshotResult
struct.
Calls that don't have a documented return value like Animation.disable
will still return a struct with an Err
property containing any errors that occurred while communicating with the chrome websocket or processing the response. All result structs have this Err
property which implements error
for application error handling:
if nil != screenshot.Err {
// handle error case
}
"When the eagle flies, does it forget that its feet have touched the ground? When the tiger lands upon its prey, does it forget its moment in the air? Three pounds of VAX!"