Commit Graph

220 Commits

Author SHA1 Message Date
Daniel Martí
81a48280ef route all communication via the browser
Use a single websocket connection per browser, removing the need for an
extra websocket connection per target.

This is thanks to the Target.sendMessageToTarget command to send
messages to each target, and the Target.receivedMessageFromTarget event
to receive messages back.

The browser handles activity via a single worker goroutine, and the same
technique is used for each target. This means that commands and events
are dealt with in order, and we can do away with some complexity like
mutexes and extra go statements.
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
xinglong
5aca12cc3e send messages with select to avoid deadlocks
Fixes #287.
2019-04-01 10:35:07 +01:00
Daniel Martí
e9aa66f87e fix build breakage with newer cdproto versions
This isn't strictly necessary, as one can always build with the earlier
cdproto version specified in go.mod. However, many people still install
chromedp in GOPATH via 'go get -u', so this workaround makes life easier
for a lot of developers.

Fixes #285.
2019-03-28 21:45:27 +00:00
Killian Brackey
39bd95c850 Clarified SIGTERM in shutdown comments 2019-03-02 14:20:46 +00:00
Killian Brackey
b61de69d62 Added SIGTERM to linux systems on shutdown
Closes https://github.com/chromedp/chromedp/issues/274
2019-03-02 14:20:46 +00:00
Daniel Martí
4cc9890745 add a simple issue template
For now, all it asks for is a few versions, and the typical three
questions to understand a bug.
2019-02-22 00:13:27 +01:00
Daniel Martí
37d13f2933 update all mod dependencies 2019-02-21 23:43:53 +01:00
Daniel Martí
26c9acb5b1 avoid ctx.Done() goroutine leak in Selector.run
As spotted in #162 by a contributor, if the context is done before the
Selector.run caller has received from the channel, the spawned goroutine
may leak if blocked on a send.
2019-02-21 17:58:08 +01:00
Daniel Martí
811d6d54d3 don't run TestFileUpload subtests in parallel
Turns out that these subtests are the only pair which cannot run in
parallel with each other. Undo that change and add a TODO. This should
fix the CI failures.

While at it, remove an unnecessary testAllocate line.
2019-02-21 17:22:40 +01:00
Daniel Martí
4c16288502 skip the error log in TestAllocatePortInUse
We know we're going to see an error, so don't log it too:

	$ go test -run TestAllocatePortInUse
	2019/02/21 17:11:34 ERROR: pool could not allocate runner ...
	PASS
	ok      github.com/chromedp/chromedp    0.004s
2019-02-21 17:13:38 +01:00
Daniel Martí
da4f783362 make all tests run in parallel
The subtests were almost all marked as parallel, but that's not enough.
That only makes the subtests run in parallel with other subtests within
the same tests, not with any other test.

Since none of the tests make use of globals nor require the entire
program to themselves, properly run all the tests in parallel.

Speeds up 'go test' on my 8-core laptop from an average of ~130s to an
average of ~50s. Many tests hit timeouts and have sleeps, so we want to
avoid running those sequentially whenever possible.
2019-02-21 13:56:54 +01:00
Daniel Martí
5ca52f3e1b use runner.LookChromeNames in TestMain
It supports alternative names for Chrome such as chromium, as well as
extra names to look for like headless-shell.

Also swap the os.Getenv logic, so that we only do the exec.LookPath work
if the env var is unset.
2019-02-21 13:53:05 +01:00
zhongjiajia
5dc1e0f3af use buffered chan for h.detached 2019-02-20 13:12:41 +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
Daniel Martí
7f54f3f93c CI: test on 1.11.x instead of tip
tip is rather unstable, so we shouldn't block PRs if it happens to break
our build or tests.

While at it, run 'go mod tidy' with the latest tip version.
2019-01-14 10:38:19 +00:00
Daniel Martí
98d4b0de6e pool: error quickly if we find a port in use
Before the fix, the added test would give a Pool.Allocate error like:

	pool could not connect to 9000: timeout waiting for initial target

The actual underlying error, which can only be seen if one inspects
chrome's stderr, is that it failed to bind to the debugging protocol
port if it was already in use.

This is of course an issue with the environment that chromedp is being
run under, since it was given a port range that wasn't available.
However, the confusing error can lead to developers wasting their time
instead of spotting the error quickly.

Unfortunately, there doesn't seem to be a way to have Chrome exit
immediately if it can't bind to the given port. So, instead of relying
on it, check if the current process can bind to the port first.

Add a test too, where we grab the first port in the pool range, and
check that we get an error that's not confusing.

Fixes #253.
2018-12-01 11:54:16 +00:00
Kenneth Shaw
bf52fed0d3 Fixing windows build issue 2018-07-18 06:19:22 +07:00
Kenneth Shaw
34591780d9 Updating dependencies 2018-07-13 12:49:42 +07:00
Kenneth Shaw
53015e7d81 Changing Debugging => DevTools 2018-07-13 12:46:30 +07:00
Kenneth Shaw
74e379587b Minor code cleanup to client package before rewrite 2018-07-13 11:35:03 +07:00
Kenneth Shaw
4ae10864e4 Adding client API changes prior to package rewrite 2018-07-13 11:24:37 +07:00
Kenneth Shaw
d413f67302 Minor cleanup to client/gen.go 2018-07-13 11:00:35 +07:00
Kenneth Shaw
622c90c82c Cleaning up runner API prior to package rewrite 2018-07-13 10:57:20 +07:00
Kenneth Shaw
e051c4a982 Removing errors dependency in client and runner packages 2018-07-13 09:28:45 +07:00
Kenneth Shaw
0406fa8a8a Fixing issue with kb 2018-07-10 19:51:58 +07:00
Kenneth Shaw
db9a873141 Updating dependencies 2018-07-04 05:23:33 +07:00
Kenneth Shaw
68c34da207 Initial vgo support 2018-05-26 14:05:58 +07:00
ljun20160606
e57a331e5c fix: windows tempfile path in %USERPROFILE%\AppData\Local
#13
2018-05-23 15:53:19 +08:00
Kenneth Shaw
5bf6a0e59d Additional With* options for calls to chromedp.New() 2018-05-19 10:17:19 +07:00
Kenneth Shaw
b389c03ae7 Adding workaround for non-localhost client connections 2018-05-19 10:16:23 +07:00
Kenneth Shaw
1e1a3ace12 General code cleanup 2018-05-19 05:06:19 +07:00
Kenneth Shaw
310d213f6f Fixing path in kb/gen.go 2018-05-07 14:11:23 +07:00
Kenneth Shaw
f683cfc4c1 Minor code cleanup 2018-03-27 04:31:09 +07:00
Kenneth Shaw
117d42c3dd Minor change to client (supporting 1.3) 2018-03-20 19:07:54 +07:00
Kenneth Shaw
097f1903e5 Bumping travis-ci config to go1.10.x series 2018-03-02 09:02:06 +07:00
Kenneth Shaw
54f529fc51 Changing chromedp-gen => cdproto-gen 2018-02-16 07:23:02 +07:00
Kenneth Shaw
46a6388474 Fixing broken links in README.md 2017-12-28 11:38:11 +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
Kenneth Shaw
0faecc62db Updating to latest protocol.json 2017-12-22 10:07:54 +07:00
Kenneth Shaw
69e069d131 Fixing issue with missing target_type values in client package 2017-12-22 10:01:21 +07:00
Kenneth Shaw
dd8119a9c5 Updating eval example 2017-12-22 09:01:51 +07:00
Kenneth Shaw
f9f17190d9 Removing edge-simple example 2017-12-22 09:00:50 +07:00
Kenneth Shaw
514f86f131 Minor change to documentation on runner.DefaultChromePath consts 2017-12-22 08:43:51 +07:00
Kenneth Shaw
dde782082b Minor documentation change to CaptureScreenshot 2017-12-19 12:14:35 +07:00
Kenneth Shaw
6d2e39b47b Minor change to chromedp-proxy to remove non-identifier characters in log names 2017-12-19 11:24:22 +07:00
Kenneth Shaw
6afa874714 Add empty *page.EventLifecycleEvent handler
Fixes #154
2017-12-18 11:03:22 +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