Commit Graph

29 Commits

Author SHA1 Message Date
Daniel Martí
f606ca9e73 fix a couple of crashes with premature cancels
The first would fail as we'd decrement the WaitGroup before adding to
it, and the escond would fail with a nil pointer dereference panic.

Add tests to reproduce both, and fix them.
2019-04-18 15:07:33 +09:00
Daniel Martí
958088f83b clarify NewContext's inheritance and cancellation
We have been developing this behavior over the past few weeks, but it
wasn't properly documented anywhere.

Fixes #303.
2019-04-17 13:25:09 +09:00
Daniel Martí
e4c16681d0 expose the default allocator options
For example, this can be useful if a user wants to simply add one flag
of their own, without otherwise messing with the default flags. In the
old codebase, they'd either have to build their own list from scratch,
or copy ours from source, needing to keep it in sync.
2019-04-17 13:23:43 +09:00
Daniel Martí
71ae9f7bbc clarify that Run won't work with an allocator context
We made the function error with ErrInvalidContext in that case, but the
godoc was still a bit ambiguous. Make it clearer to avoid confusion.

For #299.
2019-04-16 14:26:36 +09:00
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í
46982a1cac rework CancelError into Cancel
That way, cancelling a context while checking the error is much simpler.
The context data already holds onto the cancel func, so this requires no
internal changes.

This renders the Browser.Shutdown API obsolete, even though it doesn't
do exactly the same. If we want Cancel to do a proper shutdown action
before cancelling a browser context and killing the process, we could do
that change within the cancel logic.
2019-04-09 13:06:34 +02:00
Kenneth Shaw
e8122e4a26 Add WithDebugf() context option
Adds the high level WithDebugf() context option, and associated lower
level browser and dial options for setting a protocol wire debugger.
Additionally changes the conn.Conn.Read/Write implementations to be more
efficient, using direct easyjson.{Marshal,Unmarshal} calls and logging
to debug func when available.
2019-04-09 10:22:11 +02:00
Daniel Martí
b481eeac51 support fetching errors from cancellation
The API isn't very shiny, but it works. It doesn't matter that much, as
most users won't care about these errors.

Fixes #295.
2019-04-08 18:52:14 +02:00
Daniel Martí
b8efcf0691 support using BrowserOption in NewContext
While at it, remove the error return from BrowserOption, to make it
consistent with all the other option func types.

We don't have a good test for this feature yet, but at least we check
that it doesn't crash or error via an example.

Fixes #292.
2019-04-08 13:03:55 +02:00
Daniel Martí
11b3a5dc8f rename context.go to chromedp.go
And merge context_test.go with chromedp_test.go.

While at it, move the package godoc to chromedp.go, as that's now the
file named after the package.
2019-04-08 12:33:08 +02: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
Bob Potter
85ecf4f31f chromedp: fix SetHandlerByID
Don't fall through and return an error if we found a handler with a
matching ID.
2019-02-20 13:01:21 +01:00
Kenneth Shaw
53015e7d81 Changing Debugging => DevTools 2018-07-13 12:46:30 +07:00
Kenneth Shaw
622c90c82c Cleaning up runner API prior to package rewrite 2018-07-13 10:57:20 +07:00
Kenneth Shaw
5bf6a0e59d Additional With* options for calls to chromedp.New() 2018-05-19 10:17:19 +07:00
Kenneth Shaw
1e1a3ace12 General code cleanup 2018-05-19 05:06:19 +07:00
Kenneth Shaw
b0c2445e67 Splitting repositories 2017-12-28 11:17:14 +07:00
Kenneth Shaw
9424dc57d6 Removing empty doc.go file 2017-12-22 10:14:21 +07:00
Daniel Martí
335d22d376 all: simplify some error variables
There's no need to put the error variables in a larger scope, nor define
them earlier than necessary. If anything, it makes the code harder to
follow, such as figuring out when nil errors are returned.
2017-12-18 10:51:37 +07:00
Daniel Martí
7ed029cf24 all: remove unnecessary loop labels
All of them are used for a single return, so use the return instead.
2017-12-18 10:51:37 +07:00
Kenneth Shaw
148e24a615 Fixing issues with unit tests
1. Changes travis configuration to use the chrome addon
2. Adds more command line options to runner package
3. Removes grab-headless_shell.sh script
4. Cleans up and adds some environment variables for controlling how
   unit tests are ran
5. Fixes a minor issue in chromedp-gen on comment output (for working
   with latest protocol definition)
2017-12-18 07:11:42 +07:00
Kenneth Shaw
ddaa7bc4e7 Adding safeguards around Shutdown and AddTarget 2017-03-13 09:09:57 +07:00
Kenneth Shaw
4c16faa34d Minor code cleanup/maintenance on generated cdp protocol 2017-02-18 15:36:24 +07:00
Randy Cahyana
0db7a9ee72 Increasing unit test coverage on query.go 2017-02-18 10:50:33 +07:00
Kenneth Shaw
7326b390a0 Initial changes to provide configurable logging options 2017-02-13 16:00:39 +07:00
Kenneth Shaw
f73c429109 Renaming FrameHandler, updating to latest protocol.json, and code fixes 2017-02-12 12:50:46 +07:00
Kenneth Shaw
42c6cca7ed Initial commit of pool and unit tests 2017-02-09 22:01:40 +07:00
Kenneth Shaw
58283934b9 Fixing issues with code generation 2017-01-26 14:28:34 +07:00
Kenneth Shaw
20d575fece Initial import 2017-01-24 22:09:23 +07:00