-
Notifications
You must be signed in to change notification settings - Fork 17
chrome.socket.AddEventHandler
Michael Kenney edited this page Sep 29, 2018
·
1 revision
Event handlers are code that executes when a particular event is returned by the websocket listening to a Page (Tab). Event handlers are executed as goroutines and do not return data. To capture data from a handler the best strategy is to create a channel and use that to capture any output.
package main
import (
chrome "github.com/mkenney/go-chrome/tot"
"github.com/mkenney/go-chrome/tot/socket"
)
func main() {
var err error
// ... snip ... //
// Create an event handler for the Page.loadEventFired event
loadEventHandler := socket.NewEventHandler(
"Page.loadEventFired",
func(response *socket.Response) {
// ... Code here will execute when the event fires ... //
},
)
// Add the handler to the stack for this tab. Multiple handlers can
// listen to the same event.
tab.AddEventHandler(loadEventHandler)
}
"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!"