Skip to content

Commit

Permalink
add environment vars to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
wirepair committed Nov 10, 2015
1 parent 1641610 commit a8b0c94
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions autogcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func NewAutoGcd(settings *Settings) *AutoGcd {
auto.debugger.SetTimeout(settings.timeout)
}

if len(settings.env) > 0 {
auto.debugger.AddEnvironmentVars(settings.env)
}
return auto
}

Expand Down
8 changes: 5 additions & 3 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,14 @@ func (e *Element) addChild(child *gcdapi.DOMNode) {
// adds the children to our DOMNode
func (e *Element) addChildren(childNodes []*gcdapi.DOMNode) {
for _, child := range childNodes {
e.addChild(child)
if child != nil {
e.addChild(child)
}
}
}

// removes the child from our DOMNode
func (e *Element) removeChild(removedNode *gcdapi.DOMNode) {
func (e *Element) removeChild(removedNodeId int) {
var idx int
var child *gcdapi.DOMNode

Expand All @@ -335,7 +337,7 @@ func (e *Element) removeChild(removedNode *gcdapi.DOMNode) {
}

for idx, child = range e.node.Children {
if child.NodeId == removedNode.NodeId {
if child != nil && child.NodeId == removedNodeId {
e.node.Children = append(e.node.Children[:idx], e.node.Children[idx+1:]...)
e.node.ChildNodeCount = e.node.ChildNodeCount - 1
break
Expand Down
6 changes: 6 additions & 0 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Settings struct {
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 @@ -49,6 +50,7 @@ func NewSettings(chromePath, userDir string) *Settings {
s.removeUserDir = false
s.extensions = make([]string, 0)
s.flags = make([]string, 0)
s.env = make([]string, 0)
return s
}

Expand All @@ -57,6 +59,10 @@ func (s *Settings) SetChromeHost(host string) {
s.chromeHost = host
}

func (s *Settings) AddEnvironmentVars(env []string) {
s.env = append(s.env, env...)
}

// Sets the chrome debugger port.
func (s *Settings) SetDebuggerPort(chromePort string) {
s.chromePort = chromePort
Expand Down
8 changes: 6 additions & 2 deletions tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -1134,10 +1134,14 @@ func (t *Tab) handleChildNodeRemoved(parentNodeId, nodeId int) {

if ok {
if err := parent.WaitForReady(); err == nil {
parent.removeChild(ele.node)
parent.removeChild(ele.NodeId())
}
}
t.invalidateChildren(ele.node)

// if nots not ready, node will be nil
if ele.IsReady() {
t.invalidateChildren(ele.node)
}

t.eleMutex.Lock()
delete(t.elements, nodeId)
Expand Down

0 comments on commit a8b0c94

Please sign in to comment.