go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.
https://go-rod.github.io
MIT License
5.25k stars 345 forks source link

Google Login not working when browser is started with Rod #1033

Open arjendevos opened 6 months ago

arjendevos commented 6 months ago

Rod Version: v0.114.8

This is my startup code:

path, hasPath := launcher.LookPath()
    if !hasPath {
        panic("chrome not found")
    }
    fmt.Println("path found", path)

    l := launcher.New().
        Bin(path).
        Headless(false).
        Devtools(false).
        NoSandbox(true)
    defer l.Cleanup()

    url := l.MustLaunch()

    browser := rod.New().
        ControlURL(url).
        NoDefaultDevice().
        Trace(true).
        SlowMotion(1 * time.Second).
        MustConnect()

    defer browser.MustClose()

This sees the right chrome instance but when it starts it somehow starts unsecure.

Whenever I start the normal browser and add the websocket url in the Go program, it does work.

arjendevos commented 6 months ago

Update: seems like google is detecting if the browser is run in debug-mode -> https://stackoverflow.com/a/59673634/13008147

arjendevos commented 6 months ago

Update: generated my own JS from the puppeteer stealth plugin with these 2 options:

const stealth = StealthPlugin()
stealth.enabledEvasions.delete('iframe.contentWindow')
stealth.enabledEvasions.delete('media.codecs')
puppeteer.use(stealth)

as mentioned here: https://github.com/berstend/puppeteer-extra/issues/822#issuecomment-2021850431

Doesn't help

arjendevos commented 6 months ago

Update: if I use .NewUserMode() with headless=false, it seems to work. However when I run it headlessly it fails, I thought due user-agent (includes headless) but overriding the user-agent doesn't work either

ysmood commented 5 months ago

You can use the FormatArgs to debug which cli arg is affecting it:

https://github.com/go-rod/rod/blob/ab8740f76fca9fbcc138abab51afaead37f38e4a/lib/launcher/example_test.go#L26-L46

arjendevos commented 5 months ago

Th only difference between running headless and running not headless is the user-data-dir. But that one is different on each run.

Not headless:

args [--disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-features=site-per-process,TranslateUI --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --enable-automation --enable-features=NetworkService,NetworkServiceInProcess --force-color-profile=srgb --headless --metrics-recording-only --no-first-run --no-startup-window --remote-debugging-port=0 --use-mock-keychain --user-data-dir=/var/folders/sz/n6cyhc1x1qjd7m1wl04tn8mr0000gn/T/rod/user-data/9699488a8a9c9dc3]

Headless:

args [--disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-features=site-per-process,TranslateUI --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --enable-automation --enable-features=NetworkService,NetworkServiceInProcess --force-color-profile=srgb --headless --metrics-recording-only --no-first-run --no-startup-window --remote-debugging-port=0 --use-mock-keychain --user-data-dir=/var/folders/sz/n6cyhc1x1qjd7m1wl04tn8mr0000gn/T/rod/user-data/2af72e923ad51328]

Also how is it possible that they both have the --headless flag?

ysmood commented 5 months ago

Could you try the v0.115.0

arjendevos commented 5 months ago

@ysmood same problem

ysmood commented 5 months ago

Works fine to me:

package main

import (
    "github.com/go-rod/rod"
    "github.com/go-rod/rod/lib/utils"
)

func main() {
    browser := rod.New().NoDefaultDevice().MustConnect()

    page := browser.MustPage("https://google.com")

    page.MustElement(".gb_Ld").MustClick() // Click login

    utils.Pause()
}
arjendevos commented 5 months ago

@ysmood fill out details until you are at the password input page. That's where it says that the browser is not secure.

ysmood commented 4 months ago

Still works fine to me after enter the mail address.

cplasfwst commented 4 months ago

我也是同样的问题,请问有解决办法吗?

fakis commented 2 months ago

I have the same problem

Google Tips:

Couldn't sign you in This browser or app may not be secure. Learn more Try using a different browser. If you’re already using a supported browser, you can try again to sign in.

https://support.google.com/accounts/answer/7675428?hl=zh-Hans&sjid=10578618853013669016-AP

hafiihzafarhana commented 2 months ago

Same problem

image

Google will not process user logins cause the browser is not secure

ysmood commented 2 months ago

Puppeteer has the same issue: https://github.com/berstend/puppeteer-extra/issues/822

I think it's more like an upstream issue of chromium or the google website's false positive. Rod can't do much about it.

Maybe remove stealth and add NoDefaultDevice will make it work.

rssinghji commented 1 week ago

Same problem and it idn't work with NoDefaultDevice. ROD works great except logging into google account.