add delay/sleep flag

This commit is contained in:
Antoni Sawicki 2022-11-29 23:59:43 -08:00
parent 6de3fad580
commit 0128b3ff8e
2 changed files with 13 additions and 9 deletions

View File

@ -50,16 +50,18 @@ Or from the [Azure Console](https://portal.azure.com/#create/Microsoft.Container
Fortunately ACI allows port 80 without encryption.
## Flags
```
-l listen address:port (default :8080)
-t image type gif or png (default gif)
-g image geometry, WxHxC, height can be 0 for unlimited (default 1152x600x256)
-h headless mode, hide browser window on the server (default true)
-d chromedp debug logging (default false)
-n do not free maps and gif images after use (default false)
```text
-l listen address:port (default :8080)
-t image type gif or png (default gif)
-g image geometry, WxHxC, height can be 0 for unlimited (default 1152x600x216)
C (number of colors) is only used for GIF
-h headless mode, hide browser window on the server (default true)
-d chromedp debug logging (default false)
-n do not free maps and gif images after use (default false)
-ui html template file (default "wrp.html")
-s delay/sleep after page is rendered before screenshot is taken (default 2s)
```
## UI explanation

4
wrp.go
View File

@ -50,6 +50,7 @@ var (
defType string
defGeom geom
htmlTmpl *template.Template
delay time.Duration
)
// go:embed *.html
@ -306,7 +307,7 @@ func (rq *wrpReq) capture() {
}
chromedp.Run(
ctx, emulation.SetDeviceMetricsOverride(int64(float64(rq.width)/rq.zoom), height, rq.zoom, false),
chromedp.Sleep(time.Second*2), // TODO(tenox): totally lame, find a better way to determine if page is rendered
chromedp.Sleep(delay), // TODO(tenox): find a better way to determine if page is rendered
)
// Capture screenshot...
err = chromedp.Run(ctx, chromedpCaptureScreenshot(&pngcap, rq.height))
@ -496,6 +497,7 @@ func main() {
flag.StringVar(&defType, "t", "gif", "Image type: gif|png")
flag.StringVar(&fgeom, "g", "1152x600x216", "Geometry: width x height x colors, height can be 0 for unlimited")
flag.StringVar(&tHTML, "ui", "wrp.html", "HTML template file for the UI")
flag.DurationVar(&delay, "s", 2*time.Second, "Delay/sleep after page is rendered and before screenshot is taken")
flag.Parse()
if len(os.Getenv("PORT")) > 0 {
addr = ":" + os.Getenv(("PORT"))