go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.

Home Page:https://go-rod.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google Login not working when browser is started with Rod

arjendevos opened this issue · comments

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.

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

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: berstend/puppeteer-extra#822 (comment)

Doesn't help

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

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

func Example_custom_launch() {
// get the browser executable path
path := launcher.NewBrowser().MustGet()
// use the FormatArgs to construct args, this line is optional, you can construct the args manually
args := launcher.New().FormatArgs()
var cmd *exec.Cmd
if true { // decide whether to use leakless or not
cmd = leakless.New().Command(path, args...)
} else {
cmd = exec.Command(path, args...)
}
parser := launcher.NewURLParser()
cmd.Stderr = parser
utils.E(cmd.Start())
u := launcher.MustResolveURL(<-parser.URL)
rod.New().ControlURL(u).MustConnect()
}

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?

Could you try the v0.115.0

@ysmood same problem

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()
}

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

Still works fine to me after enter the mail address.

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