Commit Graph

8 Commits

Author SHA1 Message Date
Daniel Martí
ac47d6ba0e error in Run if passed an allocator context
The correct way to use Run is after NewContext. Using NewExecAllocator
only, which also gives a context, almost worked. This confused some
users into thinking it was a bug in chromedp.

Instead, error immediately with an invalid context error.

Fixes #299.
2019-04-14 19:56:09 +09:00
Daniel Martí
d0484ed1c5 simplify the allocator API
Exposing NewAllocator and AllocatorOption was unnecessary, and it made
the API more complex to use and understand.

Instead, have users call NewExecAllocator directly. This removes some
code, and simplifies the examples and tests.
2019-04-08 12:10:59 +02:00
Daniel Martí
687cf6d766 wait for cleanup when cancelling the first context
We were doing this for extra open tabs, since NewContext was taking care
of detaching and closing the respective target.

And cancelling an entire allocator also properly waited for all the
resources, such as processes and temporary directories, to be cleaned
up.

However, this didn't work for a browser's first context; cancelling it
should wait for that one browser's resources to be cleaned up, but that
wasn't implemented. Do that, fixing the TODO in TestExecAllocator.
2019-04-07 23:40:29 +02:00
Daniel Martí
97e80a00d5 make NewAllocator's cancel func block on Wait
This way, the simple examples and tests don't need to do that
separately. Practically all users will want this cleanup work to be
synchronous, and practically all Go APIs are synchronous by default, so
this makes chromedp easier to use.
2019-04-06 22:13:40 +02:00
Daniel Martí
0d568ec2a4 change Run to allow many actions
This can simplify some common use cases, like running a few actions
directly, or running no actions at all. It's also an almost entirely
backwards compatible change, as all Run call sites should continue to
compile and work.

Leave Tasks, as it can still be useful for functions to return complex
sequences of actions as a single Action.
2019-04-01 16:59:23 +01:00
Daniel Martí
8ff2971fc5 test cancelling an entire Allocator directly
To ensure that it propagates to each browser correctly.
2019-04-01 12:18:16 +01:00
Daniel Martí
32d4bae280 clean up various pieces of the API
First, collapse Browser.Start with NewBrowser. There's no reason to
split them up.

Second, unexport Browser.userDataDir, since it's only needed for a test.
It's also a bad precedent, as only the ExecAllocator will control the
user data directory.

Third, export Context.Browser, since we were already exporting
Context.Allocator.

Finally, remove the Executor interface, a duplicate of cdp.Executor.
2019-04-01 12:18:16 +01:00
Daniel Martí
3d3bf22ccc start the chromedp v2 refactor
First, we want all of the functionality in a single package; this means
collapsing whatever is useful into the root chromedp package.

The runner package is being replaced by the Allocator interface, with a
default implementation which starts browser processes.

The client package doesn't really have a place in the new design. The
context, allocator, and browser types will handle the connection with
each browser.

Finally, the new API is context-based, hence the addition of context.go.
The tests have been modified to build and run against the new API.
2019-04-01 12:17:28 +01:00