Skip to content

Commit

Permalink
(feat) add an option to wait between navigation and screenshotting
Browse files Browse the repository at this point in the history
fixes #85
  • Loading branch information
leonjza committed Dec 9, 2020
1 parent 6471cbf commit c67b522
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chrome/chrome.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Chrome struct {
ResolutionY int
UserAgent string
Timeout int64
Delay int
FullPage bool
ChromePath string
Proxy string
Expand Down Expand Up @@ -154,6 +155,7 @@ func (chrome *Chrome) Screenshot(url *url.URL) ([]byte, error) {
// straight from: https://github.com/chromedp/examples/blob/255873ca0d76b00e0af8a951a689df3eb4f224c3/screenshot/main.go#L54
if err := chromedp.Run(ctx, chromedp.Tasks{
chromedp.Navigate(url.String()),
chromedp.Sleep(time.Duration(chrome.Delay) * time.Second),
chromedp.ActionFunc(func(ctx context.Context) error {
// get layout metrics
_, _, contentSize, err := page.GetLayoutMetrics().Do(ctx)
Expand Down Expand Up @@ -197,6 +199,7 @@ func (chrome *Chrome) Screenshot(url *url.URL) ([]byte, error) {
// normal viewport screenshot
if err := chromedp.Run(ctx, chromedp.Tasks{
chromedp.Navigate(url.String()),
chromedp.Sleep(time.Duration(chrome.Delay) * time.Second),
chromedp.CaptureScreenshot(&buf),
}); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&db.Path, "db-path", "D", "gowitness.sqlite3", "destination for the gowitness database")
rootCmd.PersistentFlags().IntVarP(&chrm.ResolutionX, "resolution-x", "X", 1440, "screenshot resolution x")
rootCmd.PersistentFlags().IntVarP(&chrm.ResolutionY, "resolution-y", "Y", 900, "screenshot resolution y")
rootCmd.PersistentFlags().IntVar(&chrm.Delay, "delay", 0, "delay in seconds between navigation and screenshot")
rootCmd.PersistentFlags().StringVar(&chrm.UserAgent, "user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36", "user agent string to use")
rootCmd.PersistentFlags().StringVarP(&options.ScreenshotPath, "screenshot-path", "P", "screenshots", "store path for screenshots (use . for pwd)")
rootCmd.PersistentFlags().BoolVarP(&chrm.FullPage, "fullpage", "F", false, "take fullpage screenshots")
Expand Down

0 comments on commit c67b522

Please sign in to comment.