From f886c404e948669b0bd134f441541dcf381919f4 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Wed, 2 Apr 2025 20:01:09 +0200 Subject: [PATCH] reverse logic --- .gitignore | 3 ++- README.md | 1 + runner/headless.go | 2 +- runner/options.go | 36 ++++++++++++++++++++---------------- runner/runner.go | 4 ++-- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index caba3a5..da58538 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ cmd/functional-test/*.cfg .devcontainer /httpx /dist -/resume.cfg \ No newline at end of file +/resume.cfg +vendor/ \ No newline at end of file diff --git a/README.md b/README.md index 69e1b5b..d01f05c 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ HEADLESS: -system-chrome enable using local installed chrome for screenshot -ho, -headless-options string[] start headless chrome with additional options -esb, -exclude-screenshot-bytes enable excluding screenshot bytes from json output + -no-screenshot-full-page disable saving full page screenshot -ehb, -exclude-headless-body enable excluding headless header from json output -sfp, -screenshot-full-page enable saving full page screenshot -st, -screenshot-timeout value set timeout for screenshot in seconds (default 10s) diff --git a/runner/headless.go b/runner/headless.go index a69aa7b..6c56b73 100644 --- a/runner/headless.go +++ b/runner/headless.go @@ -99,7 +99,7 @@ func NewBrowser(proxy string, useLocal bool, optionalArgs map[string]string) (*B return engine, nil } -func (b *Browser) ScreenshotWithBody(url string, fullPage bool, timeout time.Duration, idle time.Duration, headers []string) ([]byte, string, error) { +func (b *Browser) ScreenshotWithBody(url string, timeout time.Duration, idle time.Duration, headers []string, fullPage bool) ([]byte, string, error) { page, err := b.engine.Page(proto.TargetCreateTarget{}) if err != nil { return nil, "", err diff --git a/runner/options.go b/runner/options.go index e66d186..bbadb40 100644 --- a/runner/options.go +++ b/runner/options.go @@ -104,11 +104,15 @@ type ScanOptions struct { DisableStdin bool NoScreenshotBytes bool NoHeadlessBody bool - ScreenshotFullPage bool + NoScreenshotFullPage bool ScreenshotTimeout time.Duration ScreenshotIdle time.Duration } +func (s *ScanOptions) IsScreenshotFullPage() bool { + return !s.NoScreenshotFullPage +} + func (s *ScanOptions) Clone() *ScanOptions { return &ScanOptions{ Methods: s.Methods, @@ -159,7 +163,7 @@ func (s *ScanOptions) Clone() *ScanOptions { UseInstalledChrome: s.UseInstalledChrome, NoScreenshotBytes: s.NoScreenshotBytes, NoHeadlessBody: s.NoHeadlessBody, - ScreenshotFullPage: s.ScreenshotFullPage, + NoScreenshotFullPage: s.NoScreenshotFullPage, ScreenshotTimeout: s.ScreenshotTimeout, ScreenshotIdle: s.ScreenshotIdle, } @@ -307,19 +311,19 @@ type Options struct { OutputMatchCondition string StripFilter string //The OnResult callback function is invoked for each result. It is important to check for errors in the result before using Result.Err. - OnResult OnResultCallback - DisableUpdateCheck bool - NoDecode bool - Screenshot bool - UseInstalledChrome bool - TlsImpersonate bool - DisableStdin bool - HttpApiEndpoint string - NoScreenshotBytes bool - NoHeadlessBody bool - ScreenshotFullPage bool - ScreenshotTimeout time.Duration - ScreenshotIdle time.Duration + OnResult OnResultCallback + DisableUpdateCheck bool + NoDecode bool + Screenshot bool + UseInstalledChrome bool + TlsImpersonate bool + DisableStdin bool + HttpApiEndpoint string + NoScreenshotBytes bool + NoHeadlessBody bool + NoScreenshotFullPage bool + ScreenshotTimeout time.Duration + ScreenshotIdle time.Duration // HeadlessOptionalArguments specifies optional arguments to pass to Chrome HeadlessOptionalArguments goflags.StringSlice Protocol string @@ -391,7 +395,7 @@ func ParseOptions() *Options { flagSet.StringSliceVarP(&options.HeadlessOptionalArguments, "headless-options", "ho", nil, "start headless chrome with additional options", goflags.FileCommaSeparatedStringSliceOptions), flagSet.BoolVarP(&options.NoScreenshotBytes, "exclude-screenshot-bytes", "esb", false, "enable excluding screenshot bytes from json output"), flagSet.BoolVarP(&options.NoHeadlessBody, "exclude-headless-body", "ehb", false, "enable excluding headless header from json output"), - flagSet.BoolVarP(&options.ScreenshotFullPage, "screenshot-full-page", "sfp", true, "enable saving full page screenshot"), + flagSet.BoolVar(&options.NoScreenshotFullPage, "no-screenshot-full-page", false, "disable saving full page screenshot"), flagSet.DurationVarP(&options.ScreenshotTimeout, "screenshot-timeout", "st", 10*time.Second, "set timeout for screenshot in seconds"), flagSet.DurationVarP(&options.ScreenshotIdle, "screenshot-idle", "sid", 1*time.Second, "set idle time before taking screenshot in seconds"), ) diff --git a/runner/runner.go b/runner/runner.go index bd7befe..1ec9bb2 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -296,7 +296,7 @@ func New(options *Options) (*Runner, error) { scanopts.Screenshot = options.Screenshot scanopts.NoScreenshotBytes = options.NoScreenshotBytes scanopts.NoHeadlessBody = options.NoHeadlessBody - scanopts.ScreenshotFullPage = options.ScreenshotFullPage + scanopts.NoScreenshotFullPage = options.NoScreenshotFullPage scanopts.UseInstalledChrome = options.UseInstalledChrome scanopts.ScreenshotTimeout = options.ScreenshotTimeout scanopts.ScreenshotIdle = options.ScreenshotIdle @@ -2188,7 +2188,7 @@ retry: var pHash uint64 if scanopts.Screenshot { var err error - screenshotBytes, headlessBody, err = r.browser.ScreenshotWithBody(fullURL, scanopts.ScreenshotFullPage, scanopts.ScreenshotTimeout, scanopts.ScreenshotIdle, r.options.CustomHeaders) + screenshotBytes, headlessBody, err = r.browser.ScreenshotWithBody(fullURL, scanopts.ScreenshotTimeout, scanopts.ScreenshotIdle, r.options.CustomHeaders, scanopts.IsScreenshotFullPage()) if err != nil { gologger.Warning().Msgf("Could not take screenshot '%s': %s", fullURL, err) } else {