From f3f5e80160d6c01d3b6bcac6b27fa5539db6733c Mon Sep 17 00:00:00 2001 From: Leonardo Domingues Date: Mon, 29 Nov 2021 12:02:23 -0300 Subject: [PATCH] Methods: Get chrome tabs (all, by url, by title) --- api/chrome/cli.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/api/chrome/cli.go b/api/chrome/cli.go index a20aa03..ae59b75 100644 --- a/api/chrome/cli.go +++ b/api/chrome/cli.go @@ -3,6 +3,7 @@ package chrome import ( "encoding/json" "fmt" + "go.digitalcircle.com.br/open/replaycli-go/api" ) @@ -10,9 +11,15 @@ type Cli struct { *api.ApiCli } -//func (c *Cli) HttpCli() *httpcli.Cli { -// return c.ApiCli.HttpCli() -//} +type TabMetadata struct { + Description string `json:"description"` + DevtoolsFrontendUrl string `json:"devtoolsFrontendUrl"` + Id string `json:"id"` + Title string `json:"title"` + Type string `json:"type"` + Url string `json:"url"` + WebSocketDebuggerUrl string `json:"webSocketDebuggerUrl"` +} func (c *Cli) Start(to int) error { err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/chrome/start?to=%d", to), nil) @@ -57,6 +64,21 @@ func (c *Cli) Send(id string, m string, ps map[string]interface{}) (string, erro return ret, err } +func (c *Cli) OpenTabs() (ret interface{}, err error) { + err = c.HttpCli().JsonGet("/ipc/chrome/opentabs", &ret) + return ret, err +} + +func (c *Cli) FindTabByUrl(url string) (ret interface{}, err error) { + err = c.HttpCli().JsonGet("/ipc/chrome/findtabbyurl/"+url, &ret) + return ret, err +} + +func (c *Cli) FindTabByTitle(title string) (ret interface{}, err error) { + err = c.HttpCli().JsonGet("/ipc/chrome/findtabbytitle/"+title, &ret) + return ret, err +} + func NewCli() *Cli { ret := &Cli{ApiCli: api.NewApiCli()} return ret