From b54ebbf9e56fcf06f51d85eb4c596c3ff3083ac4 Mon Sep 17 00:00:00 2001 From: Antoni Sawicki Date: Tue, 27 Oct 2020 04:05:17 -0700 Subject: [PATCH] move chromedp.Sleep to just before screenshot to fix render issue --- wrp.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wrp.go b/wrp.go index 475ef96..fe3298d 100644 --- a/wrp.go +++ b/wrp.go @@ -314,7 +314,6 @@ func (w wrpReq) capture() { var pngcap []byte chromedp.Run(ctx, emulation.SetDeviceMetricsOverride(int64(float64(w.width)/w.scale), 10, w.scale, false), - chromedp.Sleep(time.Second*2), chromedp.Location(&w.url), chromedp.ComputedStyle("body", &styles, chromedp.ByQuery), chromedp.ActionFunc(func(ctx context.Context) error { @@ -338,7 +337,10 @@ func (w wrpReq) capture() { } chromedp.Run(ctx, emulation.SetDeviceMetricsOverride(int64(float64(w.width)/w.scale), height, w.scale, false)) // Capture screenshot... - err = chromedp.Run(ctx, chromedp.CaptureScreenshot(&pngcap)) + err = chromedp.Run(ctx, + chromedp.Sleep(time.Second*2), + chromedp.CaptureScreenshot(&pngcap), + ) if err != nil { if err.Error() == "context canceled" { log.Printf("%s Contex cancelled, try again", w.req.RemoteAddr)