Methods: Get chrome tabs (all, by url, by title)

master
Leonardo Domingues 2021-11-29 12:02:23 -03:00
parent 571810c476
commit f3f5e80160
1 changed files with 25 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package chrome
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"go.digitalcircle.com.br/open/replaycli-go/api" "go.digitalcircle.com.br/open/replaycli-go/api"
) )
@ -10,9 +11,15 @@ type Cli struct {
*api.ApiCli *api.ApiCli
} }
//func (c *Cli) HttpCli() *httpcli.Cli { type TabMetadata struct {
// return c.ApiCli.HttpCli() 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 { func (c *Cli) Start(to int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/chrome/start?to=%d", to), nil) 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 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 { func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()} ret := &Cli{ApiCli: api.NewApiCli()}
return ret return ret