Skip to content
/ cri Public

Type safe go bindings to interact with chrome remote interface.

License

Notifications You must be signed in to change notification settings

skatiyar/cri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

60 Commits

Repository files navigation

cri - chrome remote interface

GoDoc Go Report Card Go Report Card

Package cri provides type-safe bindings for devtools protocol. It can be used with Chrome or any other target that implements the interface.

Protocol is generated bycmd/generate.sh.Script fetches latest version of protocol and generates types and domain (accessibility, domdebugger, performance etc.) packages. Master branch reflects tip of tree.

Tested with go1.4 and above.

Install

go get -u github /SKatiyar/cri

Usage

Taking a screenshot.

packagemain

import(
"encoding/base64"
"fmt"
"io/ioutil"

"github /SKatiyar/cri"
"github /SKatiyar/cri/browser"
"github /SKatiyar/cri/page"
)

funcmain() {
conn,connErr:=cri.NewConnection()
ifconnErr!=nil{
fmt.Println(connErr)
return
}

res,resErr:=browser.New(conn).GetVersion()
ifresErr!=nil{
fmt.Println(resErr)
return
}

pi:=page.New(conn)
ifenableErr:=pi.Enable();enableErr!=nil{
fmt.Println(enableErr)
return
}

nav,navErr:=pi.Navigate(&page.NavigateRequest{
Url:"https:// example",
})
ifnavErr!=nil{
fmt.Println(navErr)
return
}

pic,picErr:=pi.CaptureScreenshot(nil)
ifpicErr!=nil{
fmt.Println(picErr)
return
}

img,imgErr:=base64.StdEncoding.DecodeString(pic.Data)
ifimgErr!=nil{
fmt.Println(imgErr)
return
}

ifwriteErr:=ioutil.WriteFile("img.png",img,0700);writeErr!=nil{
fmt.Println(writeErr)
return
}

fmt.Println(res.JsVersion,nav.FrameId)
}

TODO

  • Add go get support to version 1.2 of protocol.
  • Add tests forconnection.go
  • Add tests for domain packages.
  • SimplifyOnfunction.
  • Add timeout toOnfunction.

About

Type safe go bindings to interact with chrome remote interface.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages