Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.
Open
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
26 changes: 23 additions & 3 deletions agents/url_screenshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"strconv"
"strings"
"time"

"path"
"path/filepath"

"github.com/michenriksen/aquatone/core"
)
Expand Down Expand Up @@ -124,15 +127,32 @@ func (a *URLScreenshotter) locateChrome() {
}

func (a *URLScreenshotter) screenshotPage(page *core.Page) {
filePath := fmt.Sprintf("screenshots/%s.png", page.BaseFilename())
filename := fmt.Sprintf("%s.png", page.BaseFilename())
folder, err := filepath.Abs(a.session.GetFilePath("screenshots"))

if err != nil {
a.session.Out.Warn("Error while finding absolute path for screenshot file %s: %v", folder, err)
return
}

if _, err := os.Stat(folder); os.IsNotExist(err) {
err = os.MkdirAll(folder, 0755)
if err != nil {
a.session.Out.Fatal("Failed to create required directory %s\n", folder)
os.Exit(1)
}
}

screenshotPath := path.Join(folder, filename)

var chromeArguments = []string{
"--headless", "--disable-gpu", "--hide-scrollbars", "--mute-audio", "--disable-notifications",
"--no-first-run", "--disable-crash-reporter", "--ignore-certificate-errors", "--incognito",
"--disable-infobars", "--disable-sync", "--no-default-browser-check",
"--user-data-dir=" + a.tempUserDirPath,
"--user-agent=" + RandomUserAgent(),
"--window-size=" + *a.session.Options.Resolution,
"--screenshot=" + a.session.GetFilePath(filePath),
"--screenshot=" + screenshotPath,
}

if os.Geteuid() == 0 {
Expand Down Expand Up @@ -173,7 +193,7 @@ func (a *URLScreenshotter) screenshotPage(page *core.Page) {

a.session.Stats.IncrementScreenshotSuccessful()
a.session.Out.Info("%s: %s\n", page.URL, Green("screenshot successful"))
page.ScreenshotPath = filePath
page.ScreenshotPath = screenshotPath
page.HasScreenshot = true
a.killChromeProcessIfRunning(cmd)
}
Expand Down