...
 
Commits (2)
......@@ -8,16 +8,20 @@ import (
"flag"
"github.com/chromedp/cdproto/cdp"
"github.com/chromedp/cdproto/runtime"
cdr "github.com/chromedp/cdproto/runtime"
"github.com/chromedp/chromedp"
"github.com/chromedp/chromedp/runner"
"os"
"runtime"
"strconv"
)
func main() {
var folderPath string
var headless bool
flag.StringVar(&folderPath, "output", "./result", "Folder where the images should go to")
flag.BoolVar(&headless, "headless", false, "Use Headless chrome")
flag.Parse()
var err error
......@@ -36,10 +40,50 @@ func main() {
defer cancel()
// create chrome instance
// Windows fix ;)
userDataDir := runner.UserDataDir("./tmp")
size := runner.WindowSize(1920, 1080)
c, err := chromedp.New(ctxt, chromedp.WithLog(log.Printf), chromedp.WithRunnerOptions(userDataDir, size))
var opts chromedp.Option
if headless {
if runtime.GOOS == "windows" {
opts = chromedp.WithRunnerOptions(
runner.Flag("no-sandbox", true),
runner.Flag("headless", true),
runner.Flag("disable-gpu", true),
runner.Flag("no-first-run", true),
runner.Flag("no-default-browser-check", true),
runner.WindowSize(1920, 1080),
runner.UserDataDir("./tmp"),
runner.Port(9222),
)
} else {
opts = chromedp.WithRunnerOptions(
runner.Flag("no-sandbox", true),
runner.Flag("headless", true),
runner.Flag("disable-gpu", true),
runner.Flag("no-first-run", true),
runner.Flag("no-default-browser-check", true),
runner.WindowSize(1920, 1080),
runner.Port(9222),
)
}
} else {
if runtime.GOOS == "windows" {
opts = chromedp.WithRunnerOptions(
runner.Flag("no-first-run", true),
runner.Flag("no-default-browser-check", true),
runner.WindowSize(1920, 1080),
runner.UserDataDir("./tmp"),
runner.Port(9222),
)
} else {
opts = chromedp.WithRunnerOptions(
runner.Flag("no-first-run", true),
runner.Flag("no-default-browser-check", true),
runner.WindowSize(1920, 1080),
runner.Port(9222),
)
}
}
c, err := chromedp.New(ctxt, chromedp.WithLog(log.Printf), opts)
if err != nil {
log.Fatal(err)
}
......@@ -55,7 +99,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
log.Println("waiting for headless_shell to exit...")
// wait for chrome to finish
err = c.Wait()
if err != nil {
......@@ -65,7 +109,7 @@ func main() {
func screenshot(urlstr, folderPath string) chromedp.Tasks {
var buf []byte
var res *runtime.RemoteObject
var res *cdr.RemoteObject
currentTime := time.Now().Local()
......@@ -87,7 +131,7 @@ func screenshot(urlstr, folderPath string) chromedp.Tasks {
chromedp.Navigate(urlstr),
chromedp.Sleep(2 * time.Second),
chromedp.WaitVisible(`.map`, chromedp.ByQuery),
chromedp.Evaluate(addTimeandDateScript, &res),
chromedp.EvaluateAsDevTools(addTimeandDateScript, &res),
chromedp.WaitVisible(`.timeDate`, chromedp.ByQuery),
chromedp.Screenshot(`.map`, &buf, chromedp.ByQuery),
chromedp.ActionFunc(func(context.Context, cdp.Executor) error {
......