chromedp/chromedp

improve the error when one uses Action.Do directly instead of Run

mvdan opened this issue · 8 comments

mvdan commented

Right now, it just errors with "invalid context", which is confusing and not helpful.

mvdan commented

If anyone encounters this error, you probably want to do:

c := chromedp.FromContext(ctx)
action.Do(cdp.WithExecutor(ctx, c.Target))

We might make this unnecessary at some point.

The following seems to work (cdp package instead of cdproto):

c := chromedp.FromContext(ctx)
action.Do(cdp.WithExecutor(ctx, c.Target))
mvdan commented

Indeed, I mixed up the package. Will edit my comment just in case.

Better errors should be propagated in the next version of chromedp, instead of context canceled. This has necessitated some major internal rework, but I'm fairly confident that when the browser dies (or closes the connection to cdp), that the changes I've made will propagate this back in a clearer fashion.

Could this be used inside a ListenTarget callback?

Could this be used inside a ListenTarget callback?

+1 on this question
i.e., Where do I get an action from inside ListenTarget?

Could this be used inside a ListenTarget callback?

+1 on this question
i.e., Where do I get an action from inside ListenTarget?

Did you solve this problem? I have the same problem as you.

Could this be used inside a ListenTarget callback?

Yes.

i.e., Where do I get an action from inside ListenTarget?

Is it a typo? The action is the one you want to execute. For example, network.GetAllCookies(), page.PrintToPDF(), etc.