package chrome import ( "encoding/json" "fmt" "go.digitalcircle.com.br/open/replaycli-go/api" ) type Cli struct { *api.ApiCli } //func (c *Cli) HttpCli() *httpcli.Cli { // return c.ApiCli.HttpCli() //} func (c *Cli) Start(to int) error { err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/chrome/start?to=%d", to), nil) return err } func (c *Cli) StartHeadless() error { err := c.HttpCli().JsonGet("/ipc/chrome/startHeadless", nil) return err } func (c *Cli) Stop() error { err := c.HttpCli().JsonGet("/ipc/chrome/stop", nil) return err } func (c *Cli) New(url string) (string, error) { ret := "" err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/chrome/new?url=%s", url), &ret) return ret, err } func (c *Cli) Close(id string) error { err := c.HttpCli().JsonGet("/ipc/chrome/close/"+id, nil) return err } func (c *Cli) Eval(id string, s string) (map[string]interface{}, error) { ret := make(map[string]interface{}) bs, err := c.HttpCli().RawPost("/ipc/chrome/eval/"+id, []byte(s)) json.Unmarshal(bs, &ret) return ret, err } func (c *Cli) Wait(id string, s string, to int) (string, error) { ret := "" bs, err := c.HttpCli().RawPost(fmt.Sprintf("/ipc/chrome/wait/%s?to=%d", id, to), []byte(s)) json.Unmarshal(bs, &ret) return ret, err } func (c *Cli) Send(id string, m string, ps map[string]interface{}) (string, error) { ret := "" in := map[string]interface{}{ "method": m, "params": ps, } err := c.HttpCli().JsonPost("/ipc/chrome/eval/"+id, in, &ret) return ret, err } func NewCli() *Cli { ret := &Cli{ApiCli: api.NewApiCli()} return ret }