Skip to content

Commit

Permalink
add a way to connect to instance
Browse files Browse the repository at this point in the history
  • Loading branch information
davyzhang committed Apr 18, 2017
1 parent 36df25a commit aed20bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
10 changes: 8 additions & 2 deletions autogcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ package autogcd
import (
"errors"
"fmt"
"github.com/wirepair/gcd"
"os"
"sync"

"github.com/wirepair/gcd"
)

type AutoGcd struct {
Expand Down Expand Up @@ -99,7 +100,12 @@ func (auto *AutoGcd) SetTerminationHandler(handler gcd.TerminatedHandler) {

// Starts Google Chrome with debugging enabled.
func (auto *AutoGcd) Start() error {
auto.debugger.StartProcess(auto.settings.chromePath, auto.settings.userDir, auto.settings.chromePort)
if auto.settings.connectToInstance {
auto.debugger.ConnectToInstance(auto.settings.chromeHost, auto.settings.chromePort)
} else {
auto.debugger.StartProcess(auto.settings.chromePath, auto.settings.userDir, auto.settings.chromePort)
}

tabs, err := auto.debugger.GetTargets()
if err != nil {
return err
Expand Down
26 changes: 17 additions & 9 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ import (
)

type Settings struct {
timeout time.Duration // timeout for giving up on chrome starting and connecting to the debugger service
chromePath string // path to chrome
chromeHost string // can really only be localhost
chromePort string // port to chrome debugger
userDir string // the user directory to use
removeUserDir bool // should we delete the user directory on shutdown?
extensions []string // custom extensions to load
flags []string // custom os.Environ flags to use to start the chrome process
env []string // custom env vars for launching the process
connectToInstance bool
timeout time.Duration // timeout for giving up on chrome starting and connecting to the debugger service
chromePath string // path to chrome
chromeHost string // can really only be localhost
chromePort string // port to chrome debugger
userDir string // the user directory to use
removeUserDir bool // should we delete the user directory on shutdown?
extensions []string // custom extensions to load
flags []string // custom os.Environ flags to use to start the chrome process
env []string // custom env vars for launching the process
}

// Creates a new settings object to start Chrome and enable remote debugging
Expand All @@ -54,6 +55,13 @@ func NewSettings(chromePath, userDir string) *Settings {
return s
}

//Set a instance to connect to other than start a new process
func (s *Settings) SetInstance(host, port string) {
s.chromeHost = host
s.chromePort = port
s.connectToInstance = true
}

// Can really only be localhost, but this may change in the future so support it anyways.
func (s *Settings) SetChromeHost(host string) {
s.chromeHost = host
Expand Down

0 comments on commit aed20bc

Please sign in to comment.