From ddaa7bc4e77f7c8b35b9754548eaa49635cf9ade Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Mon, 13 Mar 2017 09:09:57 +0700 Subject: [PATCH] Adding safeguards around Shutdown and AddTarget --- .gitignore | 4 ++++ chromedp.go | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 26f203e..976848e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,8 @@ massif.out # binaries /chromedp-gen +/chromedp-proxy +/chromedp-cli /cmd/chromedp-gen/chromedp-gen +/cmd/chromedp-gen/chromedp-proxy +/cmd/chromedp-gen/chromedp-cli diff --git a/chromedp.go b/chromedp.go index c197e3c..98b5f80 100644 --- a/chromedp.go +++ b/chromedp.go @@ -75,6 +75,9 @@ func New(ctxt context.Context, opts ...Option) (*CDP, error) { go func() { for t := range c.watch { + if t == nil { + return + } go c.AddTarget(ctxt, t) } }() @@ -153,7 +156,11 @@ func (c *CDP) Shutdown(ctxt context.Context, opts ...client.Option) error { c.RLock() defer c.RUnlock() - return c.r.Shutdown(ctxt, opts...) + if c.r != nil { + return c.r.Shutdown(ctxt, opts...) + } + + return nil } // ListTargets returns the target IDs of the managed targets.