From 21eaa2deaa700e7795a2f28a780d750237e826d7 Mon Sep 17 00:00:00 2001 From: Simon Kirillov Date: Mon, 29 Jul 2024 16:53:19 +0200 Subject: [PATCH] Fix PDF rendering (#252) * Fix pdf rendering issues * Fix pdf rendering issues * Update README.md --- README.md | 19 +------------------ internal/report/render.go | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d04ad235..10d39b18 100644 --- a/README.md +++ b/README.md @@ -404,24 +404,7 @@ Options: --workers int The number of workers to scan (default 5) ``` -The listed options can be passed to GoTestWAF as follows: - -* If running the GoTestWAF Docker container, pass the configuration options in the `docker run` command after the Docker image name. - - For example, to run GoTestWAF with WebSocket check, you can specify the WebSocket URL via the `wsURL` option: - - ```sh - docker run --rm --network="host" -it -v ${PWD}/reports:/app/reports \ - wallarm/gotestwaf --url=http://127.0.0.1:8080/ --wsURL=ws://127.0.0.1:8080/api/ws - ``` - -* If running GoTestWAF with `go run`, pass the configuration options and its values as the parameters for the main script. - - For example, to run GoTestWAF with WebSocket check, you can specify the WebSocket URL via the `wsURL` option: - - ```sh - go run ./cmd --url=http://127.0.0.1:8080/ --wsURL=ws://127.0.0.1:8080/api/ws - ``` +GoTestWAF supports two HTTP clients for performing requests, selectable via the `--httpClient` option. The default client is the standard Golang HTTP client. The second option is Chrome, which can be used with the `--httpClient=chrome` CLI argument. Note that on Linux systems, you must add the `--cap-add=SYS_ADMIN` argument to the Docker arguments to run GoTestWAF with Chrome as the request performer. ### Report name diff --git a/internal/report/render.go b/internal/report/render.go index 715f2a06..b533a2d6 100644 --- a/internal/report/render.go +++ b/internal/report/render.go @@ -9,9 +9,31 @@ import ( "github.com/pkg/errors" ) +// chromium-browser \ +// --headless \ +// --no-zygote \ +// --single-process \ +// --no-sandbox \ +// --disable-gpu \ +// --run-all-compositor-stages-before-draw \ +// --no-pdf-header-footer \ +// --print-to-pdf=test.pdf \ +// report.html + +var chromeDPExecAllocatorOptions = append( + chromedp.DefaultExecAllocatorOptions[:], + chromedp.Flag("no-zygote", true), + chromedp.Flag("no-sandbox", true), + chromedp.Flag("disable-gpu", true), + chromedp.Flag("run-all-compositor-stages-before-draw", true), +) + func renderToPDF(ctx context.Context, fileToRenderURL string, pathToResultPDF string) error { - chromeCtx, cancel := chromedp.NewContext(ctx) - defer cancel() + allocCtx, allocCtxCancel := chromedp.NewExecAllocator(ctx, chromeDPExecAllocatorOptions...) + defer allocCtxCancel() + + chromeCtx, chromeCtxCancel := chromedp.NewContext(allocCtx) + defer chromeCtxCancel() var buf []byte