From a8b0c94cc01c3063caeda6bdddfc2188b4d4b3f2 Mon Sep 17 00:00:00 2001 From: Isaac Dawson Date: Mon, 9 Nov 2015 18:07:29 -0800 Subject: [PATCH] add environment vars to settings --- autogcd.go | 3 +++ element.go | 8 +++++--- settings.go | 6 ++++++ tab.go | 8 ++++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/autogcd.go b/autogcd.go index 24a6b57..982d5d7 100644 --- a/autogcd.go +++ b/autogcd.go @@ -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 } diff --git a/element.go b/element.go index f76effc..0fd166d 100644 --- a/element.go +++ b/element.go @@ -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 @@ -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 diff --git a/settings.go b/settings.go index d02416f..cda53b1 100644 --- a/settings.go +++ b/settings.go @@ -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 @@ -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 } @@ -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 diff --git a/tab.go b/tab.go index 1bfc3a5..369685a 100644 --- a/tab.go +++ b/tab.go @@ -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)