Skip to content

Commit f1fcc1a

Browse files
committed
(chore) reduce default window size and make jpg quality configurable
1 parent 3ba65d7 commit f1fcc1a

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

cmd/scan.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func init() {
142142
scanCmd.PersistentFlags().StringSliceVar(&opts.Scan.UriFilter, "uri-filter", []string{"http", "https"}, "Valid URIs to pass to the scanning process")
143143
scanCmd.PersistentFlags().StringVarP(&opts.Scan.ScreenshotPath, "screenshot-path", "s", "./screenshots", "Path to store screenshots")
144144
scanCmd.PersistentFlags().StringVar(&opts.Scan.ScreenshotFormat, "screenshot-format", "jpeg", "Format to save screenshots as. Valid formats are: jpeg, png")
145+
scanCmd.PersistentFlags().IntVar(&opts.Scan.ScreenshotJpegQuality, "screenshot-jpeg-quality", 60, "The quality of JPEG screenshots (1-100)")
145146
scanCmd.PersistentFlags().BoolVar(&opts.Scan.ScreenshotFullPage, "screenshot-fullpage", false, "Do full-page screenshots, instead of just the viewport")
146147
scanCmd.PersistentFlags().BoolVar(&opts.Scan.ScreenshotSkipSave, "screenshot-skip-save", false, "Do not save screenshots to the screenshot-path (useful together with --write-screenshots)")
147148
scanCmd.PersistentFlags().StringVar(&opts.Scan.JavaScript, "javascript", "", "A JavaScript function to evaluate on every page, before a screenshot. Note: It must be a JavaScript function! e.g., () => console.log('gowitness');")
@@ -156,8 +157,8 @@ func init() {
156157
scanCmd.PersistentFlags().StringVar(&opts.Chrome.Proxy, "chrome-proxy", "", "An HTTP/SOCKS5 proxy server to use. Specify the proxy using this format: proto://address:port")
157158
scanCmd.PersistentFlags().StringVar(&opts.Chrome.WSS, "chrome-wss-url", "", "A websocket URL to connect to a remote, already running Chrome DevTools instance (i.e., Chrome started with --remote-debugging-port)")
158159
scanCmd.PersistentFlags().StringVar(&opts.Chrome.UserAgent, "chrome-user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36", "The user-agent string to use")
159-
scanCmd.PersistentFlags().IntVar(&opts.Chrome.WindowX, "chrome-window-x", 1920, "The Chrome browser window width, in pixels")
160-
scanCmd.PersistentFlags().IntVar(&opts.Chrome.WindowY, "chrome-window-y", 1080, "The Chrome browser window height, in pixels")
160+
scanCmd.PersistentFlags().IntVar(&opts.Chrome.WindowX, "chrome-window-x", 1280, "The Chrome browser window width, in pixels")
161+
scanCmd.PersistentFlags().IntVar(&opts.Chrome.WindowY, "chrome-window-y", 720, "The Chrome browser window height, in pixels")
161162
scanCmd.PersistentFlags().StringSliceVar(&opts.Chrome.Headers, "chrome-header", []string{}, "Extra headers to add to requests. Supports multiple --header flags")
162163

163164
// Write options for scan subcommands

pkg/runner/drivers/chromedp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func (run *Chromedp) Witness(target string, thisRunner *runner.Runner) (*models.
429429
chromedp.ActionFunc(func(ctx context.Context) error {
430430
var err error
431431
params := page.CaptureScreenshot().
432-
WithQuality(80).
432+
WithQuality(int64(run.options.Scan.ScreenshotJpegQuality)).
433433
WithFormat(page.CaptureScreenshotFormat(run.options.Scan.ScreenshotFormat))
434434

435435
// if fullpage

pkg/runner/drivers/go-rod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func (run *Gorod) Witness(target string, runner *runner.Runner) (*models.Result,
424424
switch run.options.Scan.ScreenshotFormat {
425425
case "jpeg":
426426
screenshotOptions.Format = proto.PageCaptureScreenshotFormatJpeg
427-
screenshotOptions.Quality = gson.Int(80)
427+
screenshotOptions.Quality = gson.Int(run.options.Scan.ScreenshotJpegQuality)
428428
case "png":
429429
screenshotOptions.Format = proto.PageCaptureScreenshotFormatPng
430430
}

pkg/runner/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ type Scan struct {
7777
ScreenshotPath string
7878
// ScreenshotFormat to save as
7979
ScreenshotFormat string
80+
// ScreenshotJpegQuality is the quality of the JPEG screenshot (1-100)
81+
ScreenshotJpegQuality int
8082
// ScreenshotFullPage saves full, scrolled web pages
8183
ScreenshotFullPage bool
8284
// ScreenshotToWriter passes screenshots as a model property to writers

0 commit comments

Comments
 (0)