Skip to main content

Go (chromedp)

Go library chromedp is supported. All you need to do is to use the RemoteAllocator to connect to BrowserCloud API, so it's just the same like your any local application launch.

To begin with, go over the example of navigating to the Example.com site and getting the title that are given below:

Example

package main

import (
"context"
"flag"
"github.com/chromedp/chromedp"
"log"
)

func main() {
var devToolWsUrl string
var title string

flag.StringVar(&devToolWsUrl, "devtools-ws-url", "wss://chrome.browsercloud.io?token=API-TOKEN", "DevTools Websocket URL")
flag.Parse()

actxt, cancelActxt := chromedp.NewRemoteAllocator(context.Background(), devToolWsUrl)
defer cancelActxt()

ctxt, cancelCtxt := chromedp.NewContext(actxt) // create new tab
defer cancelCtxt() // close tab afterwards

if err := chromedp.Run(ctxt,
chromedp.Navigate("https://golang.org"),
chromedp.Title(&title),
); err != nil {
log.Fatalf("Failed getting body of golang.org: %v", err)
}

log.Println("Got title of:", title)
}

You can use Go along with BrowserCloud despite the Title logoff from the Example website.

In case of any questions feel free to contact us: support@browsercloud.io