From 416490289db4c7c97a4300ba9e83a3d1f7dd8120 Mon Sep 17 00:00:00 2001 From: Antoni Sawicki Date: Fri, 31 May 2019 00:41:46 -0700 Subject: [PATCH] chromedp.run error handling --- wrp.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wrp.go b/wrp.go index 196b3cb..5e75af1 100644 --- a/wrp.go +++ b/wrp.go @@ -106,7 +106,7 @@ func capture(gourl string, w int64, h int64, s float64, y int64, out http.Respon log.Printf("Processing Caputure Request for %s\n", gourl) // Run ChromeDP Magic - chromedp.Run(ctx, + err := chromedp.Run(ctx, emulation.SetDeviceMetricsOverride(w, h, s, false), chromedp.Navigate(gourl), chromedp.Evaluate(fmt.Sprintf("window.scrollTo(0, %d);", y), &res), @@ -115,6 +115,12 @@ func capture(gourl string, w int64, h int64, s float64, y int64, out http.Respon chromedp.Location(&loc), chromedp.Nodes("a", &nodes, chromedp.ByQueryAll)) + if err != nil { + log.Printf("%s", err) + fmt.Fprintf(out, "
%s
", err) + return + } + log.Printf("Landed on: %s, Nodes: %d\n", loc, len(nodes)) // Process Screenshot Image