Type safe go bindings to interact with chrome remote interface.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
accessibility
animation
applicationcache
audits
browser
cachestorage
cmd
console
css
database
debugger
deviceorientation
dom
domdebugger
domsnapshot
domstorage
emulation
headlessexperimental
heapprofiler
indexeddb
input
inspector
io
layertree
log
memory
network
overlay
page
performance
profiler
runtime
schema
security
serviceworker
storage
systeminfo
target
tethering
tracing
types
.gitignore
.travis.yml
LICENSE
README.md
connection.go
connection_test.go
connector.go
doc.go
example_screenshot_test.go
version.go

README.md

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 by cmd/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.com/SKatiyar/cri

Usage

Taking a screenshot.

package main

import (
	"encoding/base64"
	"fmt"
	"io/ioutil"
  
	"github.com/SKatiyar/cri"
	"github.com/SKatiyar/cri/browser"
	"github.com/SKatiyar/cri/page"
)

func main() {
	conn, connErr := cri.NewConnection()
	if connErr != nil {
		fmt.Println(connErr)
		return
	}

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

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

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

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

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

	if writeErr := 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 for connection.go
  • Add tests for domain packages.
  • Simplify On function.
  • Add timeout to On function.