From 0cb5122e33711f4c98946b671c2e6ac0e41e8c53 Mon Sep 17 00:00:00 2001 From: Daniel Lauzon Date: Thu, 2 Jan 2020 05:37:20 -0500 Subject: [PATCH] headless flag usage tweak --- main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 5dfb309..c8ee25a 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,10 @@ func main() { log.Print("-start only allowed in dev mode") return } + if !*devFlag && *headlessFlag { + log.Print("-headless only allowed in dev mode") + return + } s, err := NewSession() if err != nil { log.Print(err) @@ -225,6 +229,9 @@ func (s *Session) login(ctx context.Context) error { if location == "https://photos.google.com/" { return nil } + if *headlessFlag { + return errors.New("You cannot authenticate in -headless mode") + } if *verboseFlag { log.Printf("Not yet authenticated, at: %v", location) } @@ -260,7 +267,6 @@ func (s *Session) firstNav(ctx context.Context) error { if err := navToEnd(ctx); err != nil { return err } - log.Printf("Nav to end- DONE") if err := navToLast(ctx); err != nil { return err @@ -321,11 +327,9 @@ func navToEnd(ctx context.Context) error { // new page. It then sends the right arrow key event until we've reached the very // last item. func navToLast(ctx context.Context) error { - log.Printf("Nav to last- START") var location, prevLocation string ready := false for { - log.Printf("Nav to last...") chromedp.KeyEvent(kb.ArrowRight).Do(ctx) time.Sleep(tick) if !ready { @@ -368,7 +372,9 @@ func doRun(filePath string) error { // navLeft navigates to the next item to the left func navLeft(ctx context.Context) error { chromedp.KeyEvent(kb.ArrowLeft).Do(ctx) - chromedp.WaitReady("body", chromedp.ByQuery) + // Could wait for the location to change instead of this Sleep. + time.Sleep(200 * time.Millisecond) + return nil }