mirror of
https://github.com/tenox7/wrp.git
synced 2024-11-22 10:31:21 +00:00
fix for #40 hang on page with no nodes, added timeout for cdp.Nodes
This commit is contained in:
parent
ce51eb6226
commit
1e58c94263
6
wrp.go
6
wrp.go
@ -177,8 +177,7 @@ func capture(gourl string, w int64, h int64, s float64, co int, p int64, i bool,
|
|||||||
chromedp.Evaluate(fmt.Sprintf("window.scrollTo(0, %d);", p*int64(float64(h)*float64(0.9))), &res),
|
chromedp.Evaluate(fmt.Sprintf("window.scrollTo(0, %d);", p*int64(float64(h)*float64(0.9))), &res),
|
||||||
chromedp.Sleep(time.Second*1),
|
chromedp.Sleep(time.Second*1),
|
||||||
chromedp.CaptureScreenshot(&pngbuf),
|
chromedp.CaptureScreenshot(&pngbuf),
|
||||||
chromedp.Location(&loc),
|
chromedp.Location(&loc))
|
||||||
chromedp.Nodes("a", &nodes, chromedp.ByQueryAll))
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "context canceled" {
|
if err.Error() == "context canceled" {
|
||||||
@ -216,6 +215,9 @@ func capture(gourl string, w int64, h int64, s float64, co int, p int64, i bool,
|
|||||||
gifmap[imgpath] = gifbuf
|
gifmap[imgpath] = gifbuf
|
||||||
|
|
||||||
// Process Nodes
|
// Process Nodes
|
||||||
|
tctx, cancel := context.WithTimeout(ctx, time.Second*2) // a context with timeout is needed for pages without nodes
|
||||||
|
defer cancel()
|
||||||
|
chromedp.Run(tctx, chromedp.Nodes("a", &nodes, chromedp.ByQueryAll))
|
||||||
base, _ := url.Parse(loc)
|
base, _ := url.Parse(loc)
|
||||||
if i {
|
if i {
|
||||||
fmt.Fprintf(out, "<A HREF=\"%s\"><IMG SRC=\"%s\" ALT=\"wrp\" BORDER=\"0\" ISMAP></A>", mappath, imgpath)
|
fmt.Fprintf(out, "<A HREF=\"%s\"><IMG SRC=\"%s\" ALT=\"wrp\" BORDER=\"0\" ISMAP></A>", mappath, imgpath)
|
||||||
|
Loading…
Reference in New Issue
Block a user