Documentation ¶
Overview ¶
Autogcd - An automation interface for https://github.com/wirepair/gcd. Contains most functionality found in WebDriver and extends it to offer more low level features. This library was built due to WebDriver/Chromedriver also using the debugger service. Since it is not possible to attach to a Page's debugger twice, automating a custom extension with WebDriver turned out to not be possible.
The Chrome Debugger by nature is far more asynchronous than WebDriver. It is possible to work with elements even though the debugger has not yet notified us of their existence. To deal with this, Elements can be in multiple states; Ready, NotReady or Invalid. Only certain features are available when an Element is in a Ready state. If an Element is Invalid, it should no longer be used and references to it should be discarded.
Dealing with frames is also different than WebDriver. There is no SwitchToFrame, you simply pass in the frameId to certain methods that require it. You can lookup the these frame documents by finding frame/iframe Elements and requesting the document NodeId reference via the GetFrameDocumentNodeId method.
Lastly, dealing with windows... doesn't really work since they open a new tab. A possible solution would be to monitor the list of tabs by calling AutoGcd.RefreshTabs() and doing a diff of known versus new. You could then do a Tab.Reload() to refresh the page. It is recommended that you clear cache on the tab first so it is possible to trap the various network events. There are other dirty hacks you could do as well, such as injecting script to override window.open, or rewriting links etc.
Index ¶
- type AutoGcd
- func (auto *AutoGcd) ActivateTab(tab *Tab) error
- func (auto *AutoGcd) ActivateTabById(id string) error
- func (auto *AutoGcd) CloseTab(tab *Tab) error
- func (auto *AutoGcd) CloseTabById(id string) error
- func (auto *AutoGcd) GetAllTabs() map[string]*Tab
- func (auto *AutoGcd) GetChromeRevision() string
- func (auto *AutoGcd) GetTab() (*Tab, error)
- func (auto *AutoGcd) NewTab() (*Tab, error)
- func (auto *AutoGcd) RefreshTabList() (map[string]*Tab, error)
- func (auto *AutoGcd) SetTerminationHandler(handler gcd.TerminatedHandler)
- func (auto *AutoGcd) Shutdown() error
- func (auto *AutoGcd) Start() error
- type ChangeEventType
- type ConditionalFunc
- func ElementAttributeEquals(tab *Tab, element *Element, name, value string) ConditionalFunc
- func ElementByIdReady(tab *Tab, elementAttributeId string) ConditionalFunc
- func ElementsBySelectorNotEmpty(tab *Tab, elementSelector string) ConditionalFunc
- func TitleContains(tab *Tab, searchTitle string) ConditionalFunc
- func TitleEquals(tab *Tab, equalsTitle string) ConditionalFunc
- func UrlContains(tab *Tab, containsUrl string) ConditionalFunc
- func UrlEquals(tab *Tab, equalsUrl string) ConditionalFunc
- type ConsoleMessageFunc
- type DomChangeHandlerFunc
- type Element
- func (e *Element) Clear() error
- func (e *Element) Click() error
- func (e *Element) Dimensions() ([]float64, error)
- func (e *Element) DoubleClick() error
- func (e *Element) Focus() error
- func (e *Element) FrameId() (string, error)
- func (e *Element) GetAttribute(name string) string
- func (e *Element) GetAttributes() (map[string]string, error)
- func (e *Element) GetCharacterData() (string, error)
- func (e *Element) GetChildNodeIds() ([]int, error)
- func (e *Element) GetComputedCssStyle() (map[string]string, error)
- func (e *Element) GetCssInlineStyleText() (string, string, error)
- func (e *Element) GetDebuggerDOMNode() (*gcdapi.DOMNode, error)
- func (e *Element) GetEventListeners() ([]*gcdapi.DOMDebuggerEventListener, error)
- func (e *Element) GetFrameDocumentNodeId() (int, error)
- func (e *Element) GetNodeType() (int, error)
- func (e *Element) GetSource() (string, error)
- func (e *Element) GetTagName() (string, error)
- func (e *Element) HasAttribute(name string) bool
- func (e *Element) IsDocument() (bool, error)
- func (e *Element) IsEnabled() (bool, error)
- func (e *Element) IsInvalid() bool
- func (e *Element) IsReady() bool
- func (e *Element) IsReadyInvalid() bool
- func (e *Element) IsSelected() (bool, error)
- func (e *Element) MouseOver() error
- func (e *Element) NodeId() int
- func (e *Element) SendKeys(text string) error
- func (e *Element) SetAttributeValue(name, value string) error
- func (e *Element) String() string
- func (e *Element) WaitForReady() error
- type ElementHasNoChildrenErr
- type ElementNotFoundErr
- type ElementNotReadyErr
- type GcdResponseFunc
- type IncorrectElementTypeErr
- type InvalidDimensionsErr
- type InvalidElementErr
- type InvalidNavigationErr
- type InvalidTabErr
- type NetworkFinishedHandlerFunc
- type NetworkRequest
- type NetworkRequestHandlerFunc
- type NetworkResponse
- type NetworkResponseHandlerFunc
- type NodeChangeEvent
- type NodeType
- type PromptHandlerFunc
- type ScriptEvaluationErr
- type Settings
- func (s *Settings) AddEnvironmentVars(env []string)
- func (s *Settings) AddExtension(paths []string)
- func (s *Settings) AddStartupFlags(flags []string)
- func (s *Settings) RemoveUserDir(shouldRemove bool)
- func (s *Settings) SetChromeHost(host string)
- func (s *Settings) SetDebuggerPort(chromePort string)
- func (s *Settings) SetInstance(host, port string)
- func (s *Settings) SetStartTimeout(timeout time.Duration)
- type StorageEvent
- type StorageEventType
- type StorageFunc
- type Tab
- func (t *Tab) Back() error
- func (t *Tab) BackEntry() (*gcdapi.PageNavigationEntry, error)
- func (t *Tab) Click(x, y float64) error
- func (t *Tab) Debug(enabled bool)
- func (t *Tab) DeleteCookie(cookieName, url string) error
- func (t *Tab) DidNavigationFail() (bool, string)
- func (t *Tab) DoubleClick(x, y float64) error
- func (t *Tab) EvaluatePromiseScript(scriptSource string) (*gcdapi.RuntimeRemoteObject, error)
- func (t *Tab) EvaluateScript(scriptSource string) (*gcdapi.RuntimeRemoteObject, error)
- func (t *Tab) Forward() error
- func (t *Tab) ForwardEntry() (*gcdapi.PageNavigationEntry, error)
- func (t *Tab) GetAllElements() map[int]*Element
- func (t *Tab) GetChildElements(element *Element) []*Element
- func (t *Tab) GetChildElementsOfType(element *Element, tagType string) []*Element
- func (t *Tab) GetChildrensCharacterData(element *Element) string
- func (t *Tab) GetConsoleMessages(messageHandler ConsoleMessageFunc)
- func (t *Tab) GetCookies() ([]*gcdapi.NetworkCookie, error)
- func (t *Tab) GetCurrentUrl() (string, error)
- func (t *Tab) GetDOMChanges(domHandlerFn DomChangeHandlerFunc)
- func (t *Tab) GetDocument() (*Element, error)
- func (t *Tab) GetDocumentCurrentUrl(docNodeId int) (string, error)
- func (t *Tab) GetDocumentElementById(docNodeId int, attributeId string) (*Element, bool, error)
- func (t *Tab) GetDocumentElementsBySelector(docNodeId int, selector string) ([]*Element, error)
- func (t *Tab) GetElementById(attributeId string) (*Element, bool, error)
- func (t *Tab) GetElementByLocation(x, y int) (*Element, error)
- func (t *Tab) GetElementByNodeId(nodeId int) (*Element, bool)
- func (t *Tab) GetElementsBySearch(selector string, includeUserAgentShadowDOM bool) ([]*Element, error)
- func (t *Tab) GetElementsBySelector(selector string) ([]*Element, error)
- func (t *Tab) GetFrameDocuments() []*Element
- func (t *Tab) GetFrameResources() (map[string]string, error)
- func (t *Tab) GetFrameSource(frameId, url string) (string, bool, error)
- func (t *Tab) GetFullPageScreenShot() ([]byte, error)
- func (t *Tab) GetNetworkTraffic(requestHandlerFn NetworkRequestHandlerFunc, ...) error
- func (t *Tab) GetPageSource(docNodeId int) (string, error)
- func (t *Tab) GetScreenShot() ([]byte, error)
- func (t *Tab) GetScriptSource(scriptId string) (string, error)
- func (t *Tab) GetStorageEvents(storageFn StorageFunc) error
- func (t *Tab) GetTitle() (string, error)
- func (t *Tab) GetTopFrameId() string
- func (t *Tab) GetTopNodeId() int
- func (t *Tab) InjectScriptOnLoad(scriptSource string) (string, error)
- func (t *Tab) IsNavigating() bool
- func (t *Tab) IsShuttingDown() bool
- func (t *Tab) IsTransitioning() bool
- func (t *Tab) MoveMouse(x, y float64) error
- func (t *Tab) Navigate(url string) (string, string, error)
- func (t *Tab) NavigationHistory() (int, []*gcdapi.PageNavigationEntry, error)
- func (t *Tab) Reload(ignoreCache bool, evalScript string) error
- func (t *Tab) RemoveScriptFromOnLoad(scriptId string) error
- func (t *Tab) SendKeys(text string) error
- func (t *Tab) SetDisconnectedHandler(handlerFn TabDisconnectedHandler)
- func (t *Tab) SetElementWaitTimeout(timeout time.Duration)
- func (t *Tab) SetJavaScriptPromptHandler(promptHandlerFn PromptHandlerFunc)
- func (t *Tab) SetNavigationTimeout(timeout time.Duration)
- func (t *Tab) SetStabilityTime(stableAfter time.Duration)
- func (t *Tab) SetStabilityTimeout(timeout time.Duration)
- func (t *Tab) SetUserAgent(userAgent string) error
- func (t *Tab) StopConsoleMessages(shouldDisable bool) error
- func (t *Tab) StopNetworkTraffic(shouldDisable bool) error
- func (t *Tab) StopStorageEvents(shouldDisable bool) error
- func (t *Tab) WaitFor(rate, timeout time.Duration, conditionFn ConditionalFunc) error
- func (t *Tab) WaitStable() error
- type TabDisconnectedHandler
- type TimeoutErr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AutoGcd ¶
type AutoGcd struct {
// contains filtered or unexported fields
}
func NewAutoGcd ¶
Creates a new AutoGcd based off the provided settings.
func (*AutoGcd) ActivateTab ¶
Activate the tab in the chrome UI
func (*AutoGcd) ActivateTabById ¶
Activate the tab in the chrome UI, by tab id
func (*AutoGcd) CloseTabById ¶
Closes a tab based off the tab id.
func (*AutoGcd) GetAllTabs ¶
Returns a safe copy of tabs
func (*AutoGcd) GetChromeRevision ¶
func (*AutoGcd) RefreshTabList ¶
Refreshs our internal list of tabs and return all tabs
func (*AutoGcd) SetTerminationHandler ¶
func (auto *AutoGcd) SetTerminationHandler(handler gcd.TerminatedHandler)
Allow callers to handle chrome terminating.
type ChangeEventType ¶
type ChangeEventType uint16
Document/Node change event types
const ( DocumentUpdatedEvent ChangeEventType = 0x0 SetChildNodesEvent ChangeEventType = 0x1 AttributeModifiedEvent ChangeEventType = 0x2 AttributeRemovedEvent ChangeEventType = 0x3 InlineStyleInvalidatedEvent ChangeEventType = 0x4 CharacterDataModifiedEvent ChangeEventType = 0x5 ChildNodeCountUpdatedEvent ChangeEventType = 0x6 ChildNodeInsertedEvent ChangeEventType = 0x7 ChildNodeRemovedEvent ChangeEventType = 0x8 )
func (ChangeEventType) String ¶
func (evt ChangeEventType) String() string
type ConditionalFunc ¶
ConditionalFunc function to iteratively call until returns without error
func ElementAttributeEquals ¶
func ElementAttributeEquals(tab *Tab, element *Element, name, value string) ConditionalFunc
Returns true when the element's attribute of name equals value.
func ElementByIdReady ¶
func ElementByIdReady(tab *Tab, elementAttributeId string) ConditionalFunc
Returns true when the element exists and is ready
func ElementsBySelectorNotEmpty ¶
func ElementsBySelectorNotEmpty(tab *Tab, elementSelector string) ConditionalFunc
Returns true when a selector returns a valid list of elements.
func TitleContains ¶
func TitleContains(tab *Tab, searchTitle string) ConditionalFunc
Returns true if the searchTitle is contained within the page title.
func TitleEquals ¶
func TitleEquals(tab *Tab, equalsTitle string) ConditionalFunc
Returns true when the page title equals the provided equalsTitle
func UrlContains ¶
func UrlContains(tab *Tab, containsUrl string) ConditionalFunc
Returns true when the current url contains the containsUrl
func UrlEquals ¶
func UrlEquals(tab *Tab, equalsUrl string) ConditionalFunc
Returns true when the current url equals the equalsUrl
type ConsoleMessageFunc ¶
type ConsoleMessageFunc func(tab *Tab, message *gcdapi.ConsoleConsoleMessage)
ConsoleMessageFunc function for handling console messages
type DomChangeHandlerFunc ¶
type DomChangeHandlerFunc func(tab *Tab, change *NodeChangeEvent)
DomChangeHandlerFunc function to listen for DOM Node Change Events
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
An abstraction over a DOM element, it can be in three modes NotReady - it's data has not been returned to us by the debugger yet. Ready - the debugger has given us the DOMNode reference. Invalidated - The Element has been destroyed. Certain actions require that the Element be populated (getting nodename/type) If you need this information, wait for IsReady() to return true
func (*Element) Clear ¶
Works like WebDriver's clear(), simply sets the attribute value for input or clears the value for textarea. This element must be ready so we can properly read the nodeName value.
func (*Element) Dimensions ¶
Returns the dimensions of the element.
func (*Element) DoubleClick ¶
Double clicks the center of the element.
func (*Element) GetAttribute ¶
Gets a single attribute by name, returns empty string if it does not exist or is empty.
func (*Element) GetAttributes ¶
Get attributes of the node returning a map of name,value pairs.
func (*Element) GetCharacterData ¶
Returns the character data if the element is in a ready state.
func (*Element) GetChildNodeIds ¶
Get child node ids, returns nil if node is not ready
func (*Element) GetComputedCssStyle ¶
Returns all of the computed css styles in form of name value map.
func (*Element) GetCssInlineStyleText ¶
Returns the CSS Style Text of the element, returns the inline style first and the attribute style second, or error.
func (*Element) GetDebuggerDOMNode ¶
Returns the underlying DOMNode for this element. Note this is potentially unsafe to access as we give up the ability to lock.
func (*Element) GetEventListeners ¶
func (e *Element) GetEventListeners() ([]*gcdapi.DOMDebuggerEventListener, error)
Returns event listeners for the element, both static and dynamically bound.
func (*Element) GetFrameDocumentNodeId ¶
If this element is a frame or iframe, return the ContentDocument node id
func (*Element) GetNodeType ¶
Returns the node type if the element is in a ready state.
func (*Element) GetTagName ¶
Returns the tag name (input, div etc) if the element is in a ready state.
func (*Element) HasAttribute ¶
Similar to above, but works for boolean properties (checked, async etc) Returns true if the attribute is set in our known list of attributes for this element.
func (*Element) IsDocument ¶
Is this Element a #document?
func (*Element) IsEnabled ¶
Returns true if the node is enabled, only makes sense for form controls. Element must be in a ready state.
func (*Element) IsReadyInvalid ¶
Has Chrome notified us, but the element is invalid?
func (*Element) IsSelected ¶
Simulate WebDrivers checked propertyname check
func (*Element) SendKeys ¶
SendKeys - sends each individual character after focusing (clicking) on the element. Extremely basic, doesn't take into account most/all system keys except enter, tab or backspace.
func (*Element) SetAttributeValue ¶
SetAttributeValue sets an element's attribute with name to value.
func (*Element) WaitForReady ¶
If we are ready, just return, if we are not, wait for the readyGate to be closed or for the timeout timer to fired.
type ElementHasNoChildrenErr ¶
type ElementHasNoChildrenErr struct { }
The element has no children
func (*ElementHasNoChildrenErr) Error ¶
func (e *ElementHasNoChildrenErr) Error() string
type ElementNotFoundErr ¶
type ElementNotFoundErr struct {
Message string
}
ElementNotFoundErr when we are unable to find an element/nodeId
func (*ElementNotFoundErr) Error ¶
func (e *ElementNotFoundErr) Error() string
type ElementNotReadyErr ¶
type ElementNotReadyErr struct { }
When we have an element that has not been populated with data yet.
func (*ElementNotReadyErr) Error ¶
func (e *ElementNotReadyErr) Error() string
type GcdResponseFunc ¶
type GcdResponseFunc func(target *gcd.ChromeTarget, payload []byte)
GcdResponseFunc internal response function type
type IncorrectElementTypeErr ¶
An attempt was made to execute a method for which the element type is incorrect
func (*IncorrectElementTypeErr) Error ¶
func (e *IncorrectElementTypeErr) Error() string
type InvalidDimensionsErr ¶
type InvalidDimensionsErr struct {
Message string
}
When the dimensions of an element are incorrect to calculate the centroid
func (*InvalidDimensionsErr) Error ¶
func (e *InvalidDimensionsErr) Error() string
type InvalidElementErr ¶
type InvalidElementErr struct { }
The element has been removed from the DOM
func (*InvalidElementErr) Error ¶
func (e *InvalidElementErr) Error() string
type InvalidNavigationErr ¶
type InvalidNavigationErr struct {
}InvalidNavigationErr when unable to navigate Forward or Back
func (*InvalidNavigationErr) Error ¶
func (e *InvalidNavigationErr) Error() string
type InvalidTabErr ¶
type InvalidTabErr struct {
Message string
}
InvalidTabErr when we are unable to access a tab
func (*InvalidTabErr) Error ¶
func (e *InvalidTabErr) Error() string
type NetworkFinishedHandlerFunc ¶
NetworkFinishedHandlerFunc function for handling network finished, meaning it's safe to call Network.GetResponseBody
type NetworkRequest ¶
type NetworkRequest struct { RequestId string // Internal chrome request id FrameId string // frame that the request went out on LoaderId string // internal chrome loader id DocumentURL string // url of the frame Request *gcdapi.NetworkRequest // underlying Request object Timestamp float64 // time the request was dispatched Initiator *gcdapi.NetworkInitiator // who initiated the request RedirectResponse *gcdapi.NetworkResponse // non-nil if it was a redirect Type string // Document, Stylesheet, Image, Media, Font, Script, TextTrack, XHR, Fetch, EventSource, WebSocket, Other }
Outbound network requests
type NetworkRequestHandlerFunc ¶
type NetworkRequestHandlerFunc func(tab *Tab, request *NetworkRequest)
NetworkRequestHandlerFunc function for handling network requests
type NetworkResponse ¶
type NetworkResponse struct { RequestId string // Internal chrome request id FrameId string // frame that the request went out on LoaderId string // internal chrome loader id Response *gcdapi.NetworkResponse // underlying Response object Timestamp float64 // time the request was received Type string // Document, Stylesheet, Image, Media, Font, Script, TextTrack, XHR, Fetch, EventSource, WebSocket, Other }
Inbound network responses
type NetworkResponseHandlerFunc ¶
type NetworkResponseHandlerFunc func(tab *Tab, response *NetworkResponse)
NetworkResponseHandlerFunc function for handling network responses
type NodeChangeEvent ¶
type NodeChangeEvent struct { EventType ChangeEventType // the type of node change event NodeId int // nodeid of change NodeIds []int // nodeid of changes for inlinestyleinvalidated ChildNodeCount int // updated childnodecount event Nodes []*gcdapi.DOMNode // Child nodes array. for setChildNodesEvent Node *gcdapi.DOMNode // node for child node inserted event Name string // attribute name Value string // attribute value CharacterData string // new text value for characterDataModified events ParentNodeId int // node id for setChildNodesEvent, childNodeInsertedEvent and childNodeRemovedEvent PreviousNodeId int // previous node id for childNodeInsertedEvent }
For handling DOM updating nodes
type PromptHandlerFunc ¶
PromptHandlerFunc function to handle javascript dialog prompts as they occur, pass to SetJavaScriptPromptHandler Internally this should call tab.Page.HandleJavaScriptDialog(accept bool, promptText string)
type ScriptEvaluationErr ¶
type ScriptEvaluationErr struct { Message string ExceptionText string ExceptionDetails *gcdapi.RuntimeExceptionDetails }
ScriptEvaluationErr returned when an injected script caused an error
func (*ScriptEvaluationErr) Error ¶
func (e *ScriptEvaluationErr) Error() string
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
func NewSettings ¶
Creates a new settings object to start Chrome and enable remote debugging
func (*Settings) AddEnvironmentVars ¶
func (*Settings) AddExtension ¶
Adds a custom extension to launch with chrome. Note this extension MAY NOT USE the chrome.debugger API since you can not attach debuggers to a Tab twice.
func (*Settings) AddStartupFlags ¶
Adds custom flags when starting the chrome process
func (*Settings) RemoveUserDir ¶
On Shutdown, deletes the userDir and files if true.
func (*Settings) SetChromeHost ¶
Can really only be localhost, but this may change in the future so support it anyways.
func (*Settings) SetDebuggerPort ¶
Sets the chrome debugger port.
func (*Settings) SetInstance ¶
Set a instance to connect to other than start a new process
func (*Settings) SetStartTimeout ¶
How long to wait for chrome to startup and allow us to connect.
type StorageEvent ¶
type StorageFunc ¶
type StorageFunc func(tab *Tab, eventType string, eventDetails *StorageEvent)
StorageFunc function for ListenStorageEvents returns the eventType of cleared, updated, removed or added.
type Tab ¶
type Tab struct { *gcd.ChromeTarget // underlying chrometarget // contains filtered or unexported fields }
Tab object for driving a specific tab and gathering elements.
func (*Tab) Back ¶
Looks up the previous navigation entry from the history and navigates to it. Returns error if we could not find the previous entry or navigation failed
func (*Tab) BackEntry ¶
func (t *Tab) BackEntry() (*gcdapi.PageNavigationEntry, error)
Returns the previous entry in our navigation history for this tab.
func (*Tab) Click ¶
Issues a left button mousePressed then mouseReleased on the x, y coords provided.
func (*Tab) DeleteCookie ¶
Deletes the cookie from the browser
func (*Tab) DidNavigationFail ¶
An undocumented method of determining if chromium failed to load a page due to DNS or connection timeouts.
func (*Tab) DoubleClick ¶
Issues a double click on the x, y coords provided.
func (*Tab) EvaluatePromiseScript ¶
func (t *Tab) EvaluatePromiseScript(scriptSource string) (*gcdapi.RuntimeRemoteObject, error)
Evaluates script in the global context.
func (*Tab) EvaluateScript ¶
func (t *Tab) EvaluateScript(scriptSource string) (*gcdapi.RuntimeRemoteObject, error)
Evaluates script in the global context.
func (*Tab) Forward ¶
Looks up the next navigation entry from the history and navigates to it. Returns error if we could not find the next entry or navigation failed
func (*Tab) ForwardEntry ¶
func (t *Tab) ForwardEntry() (*gcdapi.PageNavigationEntry, error)
Returns the next entry in our navigation history for this tab.
func (*Tab) GetAllElements ¶
Returns a copy of all currently known elements. Note that modifications to elements maybe unsafe.
func (*Tab) GetChildElements ¶
Gets all elements of a child
func (*Tab) GetChildElementsOfType ¶
Returns all elements of a specific tag type.
func (*Tab) GetChildrensCharacterData ¶
Returns the #text values of the element's children.
func (*Tab) GetConsoleMessages ¶
func (t *Tab) GetConsoleMessages(messageHandler ConsoleMessageFunc)
Registers chrome to start retrieving console messages, caller must pass in call back function to handle it.
func (*Tab) GetCookies ¶
func (t *Tab) GetCookies() ([]*gcdapi.NetworkCookie, error)
Returns the cookies from the tab.
func (*Tab) GetCurrentUrl ¶
Returns the current url of the top level document
func (*Tab) GetDOMChanges ¶
func (t *Tab) GetDOMChanges(domHandlerFn DomChangeHandlerFunc)
Allow the caller to be notified of DOM NodeChangeEvents. Simply call this with a nil function handler to stop receiving dom event changes.
func (*Tab) GetDocument ¶
Returns the top level document element for this tab.
func (*Tab) GetDocumentCurrentUrl ¶
Returns the current url of the provided docNodeId
func (*Tab) GetDocumentElementById ¶
Returns an element from a specific Document.
func (*Tab) GetDocumentElementsBySelector ¶
Same as GetChildElementsBySelector
func (*Tab) GetElementById ¶
Returns the element by searching the top level document for an element with attributeId Does not work on frames.
func (*Tab) GetElementByLocation ¶
Returns the element given the x, y coordinates on the page, or returns error.
func (*Tab) GetElementByNodeId ¶
Returns either an element from our list of ready/known nodeIds or a new un-ready element If it's not ready we return false. Note this does have a side effect of adding a potentially invalid element to our list of known elements. But it is assumed this method will be called with a valid nodeId that chrome has not informed us about yet. Once we are informed, we need to update it via our list and not some reference that could disappear.
func (*Tab) GetElementsBySearch ¶
func (t *Tab) GetElementsBySearch(selector string, includeUserAgentShadowDOM bool) ([]*Element, error)
Get all elements that match a CSS or XPath selector
func (*Tab) GetElementsBySelector ¶
Get all elements that match a selector from the top level document
func (*Tab) GetFrameDocuments ¶
Returns all documents as elements that are known.
func (*Tab) GetFrameResources ¶
Gets all frame ids and urls from the top level document.
func (*Tab) GetFrameSource ¶
Returns the raw source (non-serialized DOM) of the frame. If you want the visible source, call GetPageSource, passing in the frame's nodeId. Make sure you wait for the element's WaitForReady() to return without error first.
func (*Tab) GetFullPageScreenShot ¶
Takes a full sized screenshot of the currently loaded page
func (*Tab) GetNetworkTraffic ¶
func (t *Tab) GetNetworkTraffic(requestHandlerFn NetworkRequestHandlerFunc, responseHandlerFn NetworkResponseHandlerFunc, finishedHandlerFn NetworkFinishedHandlerFunc) error
Listens to network traffic, each handler can be nil in which case we'll only call the handlers defined.
func (*Tab) GetPageSource ¶
Returns the document's source, as visible, if docId is 0, returns top document source.
func (*Tab) GetScreenShot ¶
Takes a screenshot of the currently loaded page (only the dimensions visible in browser window)
func (*Tab) GetScriptSource ¶
Returns the source of a script by its scriptId.
func (*Tab) GetStorageEvents ¶
func (t *Tab) GetStorageEvents(storageFn StorageFunc) error
Listens for storage events, storageFn should switch on type of cleared, removed, added or updated. cleared holds IsLocalStorage and SecurityOrigin values only. removed contains above plus Key. added contains above plus NewValue. updated contains above plus OldValue.
func (*Tab) GetTopFrameId ¶
GetTopFrameId return the top frame id of this tab
func (*Tab) GetTopNodeId ¶
GetTopNodeId returns the current top node id of this Tab.
func (*Tab) InjectScriptOnLoad ¶
Injects custom javascript prior to the page loading on all frames. Returns scriptId which can be used to remove the script. If you only want the script to interact with the top document, you'll need to do checks in the injected script such as testing location.href.
Alternatively, you can use Tab.EvaluateScript to only work on the global context.
func (*Tab) IsNavigating ¶
IsNavigating answers if we currently navigating
func (*Tab) IsShuttingDown ¶
IsShuttingDown answers if we are shutting down or not
func (*Tab) IsTransitioning ¶
IsTransitioning returns true if we are transitioning to a new page. This is not set when Navigate is called.
func (*Tab) Navigate ¶
Navigate to a URL and does not return until the Page.loadEventFired event as well as all setChildNode events have completed. If successful, returns frameId. If failed, returns frameId, friendly error text, and the error.
func (*Tab) NavigationHistory ¶
func (t *Tab) NavigationHistory() (int, []*gcdapi.PageNavigationEntry, error)
Returns the current navigation index, history entries or error
func (*Tab) Reload ¶
Reloads the page injecting evalScript to run on load. set ignoreCache to true to have it act like ctrl+f5.
func (*Tab) RemoveScriptFromOnLoad ¶
Removes the script by the scriptId.
func (*Tab) SendKeys ¶
Sends keystrokes to whatever is focused, best called from Element.SendKeys which will try to focus on the element first. Use \n for Enter, \b for backspace or \t for Tab.
func (*Tab) SetDisconnectedHandler ¶
func (t *Tab) SetDisconnectedHandler(handlerFn TabDisconnectedHandler)
SetDisconnectedHandler so caller can trap when the debugger was disconnected/crashed.
func (*Tab) SetElementWaitTimeout ¶
SetElementWaitTimeout to wait in seconds for ele.WaitForReady() before giving up, default is 5 seconds
func (*Tab) SetJavaScriptPromptHandler ¶
func (t *Tab) SetJavaScriptPromptHandler(promptHandlerFn PromptHandlerFunc)
Set a handler for javascript prompts, most likely you should call tab.Page.HandleJavaScriptDialog(accept bool, msg string) to actually handle the prompt, otherwise the tab will be blocked waiting for input and never return additional events.
func (*Tab) SetNavigationTimeout ¶
SetNavigationTimeout to wait in seconds for navigations before giving up, default is 30 seconds
func (*Tab) SetStabilityTime ¶
SetStabilityTime to wait for no node changes before we consider the DOM stable. Note that stability timeout will fire if the DOM is constantly changing. The deafult stableAfter is 300 ms.
func (*Tab) SetStabilityTimeout ¶
SetStabilityTimeout to wait for WaitStable() to return, default is 2 seconds.
func (*Tab) SetUserAgent ¶
Override the user agent for requests going out.
func (*Tab) StopConsoleMessages ¶
Stops the debugger service from sending console messages and closes the channel Pass shouldDisable as true if you wish to disable Console debugger
func (*Tab) StopNetworkTraffic ¶
Unsubscribes from network request/response events and disables the Network debugger. Pass shouldDisable as true if you wish to disable the network service.
func (*Tab) StopStorageEvents ¶
Stops listening for storage events, set shouldDisable to true if you wish to disable DOMStorage debugging.
func (*Tab) WaitFor ¶
func (t *Tab) WaitFor(rate, timeout time.Duration, conditionFn ConditionalFunc) error
Calls a function every tick until conditionFn returns true or timeout occurs.
func (*Tab) WaitStable ¶
A very rudementary stability check, compare current time with lastNodeChangeTime and see if it is greater than the stableAfter duration. If it is, that means we haven't seen any activity over the minimum allowed time, in which case we consider the DOM stable. Note this will most likely not work for sites that insert and remove elements on timer/intervals as it will constantly update our lastNodeChangeTime value. However, for most cases this should be enough. This should only be necessary to call when a navigation event occurs under the page's control (not a direct tab.Navigate) call. Common examples would be submitting an XHR based form that does a history.pushState and does *not* actually load a new page but simply inserts and removes elements dynamically. Returns error only if we timed out.
type TabDisconnectedHandler ¶
TabDisconnectedHandler is called when the tab crashes or the inspector was disconnected
type TimeoutErr ¶
type TimeoutErr struct {
Message string
}
TimeoutErr when Tab.Navigate has timed out
func (*TimeoutErr) Error ¶
func (e *TimeoutErr) Error() string