func main() { var wg sync.WaitGroup wg.Add(1) debugger := gcd.NewChromeDebugger() // start process, specify a tmp profile path so we get a fresh profiled browser // set port 9222 as the debug port debugger.StartProcess("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "C:\\tmp\\", "9222") defer debugger.ExitProcess() // exit when done targets, err := debugger.GetTargets() // get the 'targets' or tabs/background processes if err != nil { log.Fatalf("error getting targets: %s\n", err) } target := targets[0] // take the first one //subscribe to page load target.Subscribe("Page.loadEventFired", func(targ *gcd.ChromeTarget, v []byte) { wg.Done() // page loaded, we can exit now // if you wanted to inspect the full response data, you could do that here }) // get the Page API and enable it if _, err := target.Page.Enable(); err != nil { log.Fatalf("error getting page: %s\n", err) } ret, err := target.Page.Navigate("http://www.veracode.com") // navigate if err != nil { log.Fatalf("Error navigating: %s\n", err) } log.Printf("ret: %#v\n", ret) wg.Wait() // wait for page load }
func main() { debugger := gcd.NewChromeDebugger() debugger.StartProcess("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "C:\\tmp\\", "9222") defer debugger.ExitProcess() target, err := debugger.NewTab() if err != nil { log.Fatalf("error getting new tab: %s\n", err) } dom := target.DOM r, err := dom.GetDocument() if err != nil { log.Fatalf("error: %s\n", err) } log.Printf("NodeID: %d Node Name: %s, URL: %s\n", r.NodeId, r.NodeName, r.DocumentURL) }
// Creates a new AutoGcd based off the provided settings. func NewAutoGcd(settings *Settings) *AutoGcd { auto := &AutoGcd{settings: settings} auto.tabLock = &sync.RWMutex{} auto.tabs = make(map[string]*Tab) auto.debugger = gcd.NewChromeDebugger() auto.debugger.SetTerminationHandler(auto.defaultTerminationHandler) if len(settings.extensions) > 0 { auto.debugger.AddFlags(settings.extensions) } if len(settings.flags) > 0 { auto.debugger.AddFlags(settings.flags) } if settings.timeout > 0 { auto.debugger.SetTimeout(settings.timeout) } if len(settings.env) > 0 { auto.debugger.AddEnvironmentVars(settings.env) } return auto }
func main() { var err error urls := []string{"http://www.google.com", "http://www.veracode.com", "http://www.microsoft.com", "http://bbc.co.uk", "http://www.reddit.com/r/golang"} debugger = gcd.NewChromeDebugger() debugger.StartProcess("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "C:\\tmp\\", "9222") defer debugger.ExitProcess() targets := make([]*gcd.ChromeTarget, numTabs) for i := 0; i < numTabs; i++ { wg.Add(1) targets[i], err = debugger.NewTab() if err != nil { log.Fatalf("error getting targets") } page := targets[i].Page page.Enable() targets[i].Subscribe("Page.loadEventFired", PageLoaded) page.Navigate(urls[i]) } wg.Wait() for i := 0; i < numTabs; i++ { TakeScreenShot(targets[i]) } }