4 Commits
v0.1.3 ... v0.1

Author SHA1 Message Date
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
4 changed files with 40 additions and 19 deletions

4
go.mod
View File

@@ -1,9 +1,9 @@
module github.com/chromedp/chromedp module github.com/chromedp/chromedp
require ( require (
github.com/chromedp/cdproto v0.0.0-20190217000753-2d8e8962ceb2 github.com/chromedp/cdproto v0.0.0-20190327003620-8d5e1d04ce19
github.com/disintegration/imaging v1.6.0 github.com/disintegration/imaging v1.6.0
github.com/gorilla/websocket v1.4.0 github.com/gorilla/websocket v1.4.0
github.com/mailru/easyjson v0.0.0-20190221075403-6243d8e04c3f github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe
golang.org/x/image v0.0.0-20190220214146-31aff87c08e9 // indirect golang.org/x/image v0.0.0-20190220214146-31aff87c08e9 // indirect
) )

8
go.sum
View File

@@ -1,5 +1,5 @@
github.com/chromedp/cdproto v0.0.0-20190217000753-2d8e8962ceb2 h1:4Ck8YOuS0G3+0xMb80cDSff7QpUolhSc0PGyfagbcdA= github.com/chromedp/cdproto v0.0.0-20190327003620-8d5e1d04ce19 h1:KOdZXVcB8L3zR4ZsMAnviYJFIgfRP/iYSEzXl7rYXhc=
github.com/chromedp/cdproto v0.0.0-20190217000753-2d8e8962ceb2/go.mod h1:xquOK9dIGFlLaIGI4c6IyfLI/Gz0LiYYuJtzhsUODgI= github.com/chromedp/cdproto v0.0.0-20190327003620-8d5e1d04ce19/go.mod h1:xquOK9dIGFlLaIGI4c6IyfLI/Gz0LiYYuJtzhsUODgI=
github.com/disintegration/imaging v1.6.0 h1:nVPXRUUQ36Z7MNf0O77UzgnOb1mkMMor7lmJMJXc/mA= github.com/disintegration/imaging v1.6.0 h1:nVPXRUUQ36Z7MNf0O77UzgnOb1mkMMor7lmJMJXc/mA=
github.com/disintegration/imaging v1.6.0/go.mod h1:xuIt+sRxDFrHS0drzXUlCJthkJ8k7lkkUojDSR247MQ= github.com/disintegration/imaging v1.6.0/go.mod h1:xuIt+sRxDFrHS0drzXUlCJthkJ8k7lkkUojDSR247MQ=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
@@ -7,8 +7,8 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
github.com/knq/sysutil v0.0.0-20181215143952-f05b59f0f307 h1:vl4eIlySbjertFaNwiMjXsGrFVK25aOWLq7n+3gh2ls= github.com/knq/sysutil v0.0.0-20181215143952-f05b59f0f307 h1:vl4eIlySbjertFaNwiMjXsGrFVK25aOWLq7n+3gh2ls=
github.com/knq/sysutil v0.0.0-20181215143952-f05b59f0f307/go.mod h1:BjPj+aVjl9FW/cCGiF3nGh5v+9Gd3VCgBQbod/GlMaQ= github.com/knq/sysutil v0.0.0-20181215143952-f05b59f0f307/go.mod h1:BjPj+aVjl9FW/cCGiF3nGh5v+9Gd3VCgBQbod/GlMaQ=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190221075403-6243d8e04c3f h1:B6PQkurxGG1rqEX96oE14gbj8bqvYC5dtks9r5uGmlE= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe h1:W/GaMY0y69G4cFlmsC6B9sbuo2fP8OFP1ABjt4kPz+w=
github.com/mailru/easyjson v0.0.0-20190221075403-6243d8e04c3f/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 h1:00VmoueYNlNz/aHIilyyQz/MHSqGoWJzpFv/HW8xpzI= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 h1:00VmoueYNlNz/aHIilyyQz/MHSqGoWJzpFv/HW8xpzI=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190220214146-31aff87c08e9 h1:+vH8qNweCrORN49012OX3h0oWEXO3p+rRnpAGQinddk= golang.org/x/image v0.0.0-20190220214146-31aff87c08e9 h1:+vH8qNweCrORN49012OX3h0oWEXO3p+rRnpAGQinddk=

View File

@@ -155,10 +155,18 @@ func (h *TargetHandler) run(ctxt context.Context) {
switch { switch {
case msg.Method != "": case msg.Method != "":
h.qevents <- msg select {
case h.qevents <- msg:
case <-ctxt.Done():
return
}
case msg.ID != 0: case msg.ID != 0:
h.qres <- msg select {
case h.qres <- msg:
case <-ctxt.Done():
return
}
default: default:
h.errf("ignoring malformed incoming message (missing id or method): %#v", msg) h.errf("ignoring malformed incoming message (missing id or method): %#v", msg)
@@ -226,6 +234,15 @@ func (h *TargetHandler) processEvent(ctxt context.Context, msg *cdproto.Message)
if msg == nil { if msg == nil {
return ErrChannelClosed return ErrChannelClosed
} }
switch msg.Method {
case "Page.frameClearedScheduledNavigation",
"Page.frameScheduledNavigation":
// These events are now deprecated, and UnmarshalMessage panics
// when they are received from Chrome. For now, to avoid panics
// and compile errors, and to fix chromedp v0 when installed via
// 'go get -u', skip the events here.
return nil
}
// unmarshal // unmarshal
ev, err := cdproto.UnmarshalMessage(msg) ev, err := cdproto.UnmarshalMessage(msg)
@@ -346,10 +363,14 @@ func (h *TargetHandler) Execute(ctxt context.Context, methodType string, params
h.resrw.Unlock() h.resrw.Unlock()
// queue message // queue message
h.qcmd <- &cdproto.Message{ select {
case h.qcmd <- &cdproto.Message{
ID: id, ID: id,
Method: cdproto.MethodType(methodType), Method: cdproto.MethodType(methodType),
Params: paramsBuf, Params: paramsBuf,
}:
case <- ctxt.Done():
return ctxt.Err()
} }
errch := make(chan error, 1) errch := make(chan error, 1)
@@ -530,13 +551,9 @@ func (h *TargetHandler) pageEvent(ctxt context.Context, ev interface{}) {
case *page.EventFrameStoppedLoading: case *page.EventFrameStoppedLoading:
id, op = e.FrameID, frameStoppedLoading id, op = e.FrameID, frameStoppedLoading
case *page.EventFrameScheduledNavigation:
id, op = e.FrameID, frameScheduledNavigation
case *page.EventFrameClearedScheduledNavigation:
id, op = e.FrameID, frameClearedScheduledNavigation
// ignored events // ignored events
case *page.EventFrameRequestedNavigation:
return
case *page.EventDomContentEventFired: case *page.EventDomContentEventFired:
return return
case *page.EventLoadEventFired: case *page.EventLoadEventFired:

View File

@@ -213,7 +213,8 @@ func (r *Runner) Start(ctxt context.Context, opts ...string) error {
return nil return nil
} }
// Shutdown shuts down the Chrome process. // Shutdown shuts down the Chrome process. Currently only has support for
// SIGTERM in darwin and linux systems
func (r *Runner) Shutdown(ctxt context.Context, opts ...client.Option) error { func (r *Runner) Shutdown(ctxt context.Context, opts ...client.Option) error {
var err error var err error
@@ -241,12 +242,15 @@ func (r *Runner) Shutdown(ctxt context.Context, opts ...client.Option) error {
} }
} }
// osx applications do not automatically exit when all windows (ie, tabs) // osx and linux applications do not automatically exit when all windows (ie, tabs)
// closed, so send SIGTERM. // closed, so send SIGTERM.
// //
// TODO: add other behavior here for more process options on shutdown? // TODO: add other behavior here for more process options on shutdown?
if runtime.GOOS == "darwin" && r.cmd != nil && r.cmd.Process != nil { if r.cmd != nil && r.cmd.Process != nil {
return r.cmd.Process.Signal(syscall.SIGTERM) switch runtime.GOOS {
case "darwin", "linux":
return r.cmd.Process.Signal(syscall.SIGTERM)
}
} }
return nil return nil