Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PDF rendering #252

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 24 additions & 2 deletions internal/report/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down