From 5bf6a0e59d002d448cb63ff49cb13702e6d8d8f7 Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Sat, 19 May 2018 10:17:19 +0700 Subject: [PATCH] Additional With* options for calls to chromedp.New() --- chromedp.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/chromedp.go b/chromedp.go index e6182ba..3ae31ff 100644 --- a/chromedp.go +++ b/chromedp.go @@ -360,6 +360,20 @@ func WithTargets(watch <-chan client.Target) Option { } } +// WithClient is a CDP option to use the incoming targets from a client. +func WithClient(ctxt context.Context, cl *client.Client) Option { + return func(c *CDP) error { + return WithTargets(cl.WatchPageTargets(ctxt))(c) + } +} + +// WithURL is a CDP option to use a client with the specified URL. +func WithURL(ctxt context.Context, urlstr string) Option { + return func(c *CDP) error { + return WithClient(ctxt, client.New(client.URL(urlstr)))(c) + } +} + // WithRunnerOptions is a CDP option to specify the options to pass to a newly // created Chrome process runner. func WithRunnerOptions(opts ...runner.CommandLineOption) Option {