Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy issue #703

Closed
seal opened this issue Aug 26, 2022 · 6 comments
Closed

Proxy issue #703

seal opened this issue Aug 26, 2022 · 6 comments
Labels
duplicate This issue or pull request already exists question Questions related to rod

Comments

@seal
Copy link

seal commented Aug 26, 2022

Currently can't use a socks5 proxy with example code provided
Errors:
panic: write tcp 127.0.0.1:54724->127.0.0.1:54722: use of closed network connection
or sometimes:
panic: navigation failed: net::ERR_SOCKS_CONNECTION_FAILED

Rod Version: v0.109.3

Proxy works as:
image

Go version: go version
go version go1.18.1 windows/amd64
package version: run git rev-parse HEAD inside the repo
660bb46677a59d9964b2967e926a313f04ae1b1b

func PlaySong(account Account) {
	url := launcher.New().
		Headless(false).
		Set(flags.ProxyServer, "socks5://"+account.Proxy).
		//Proxy(). Have tried Set and Proxy, neither work 
		Delete("use-mock-keychain"). // delete flag "--use-mock-keychain"
		MustLaunch()
	browser := rod.New().ControlURL(url).MustConnect()
	browser.MustIgnoreCertErrors(true)
	defer browser.MustClose()
	go browser.MustHandleAuth(account.ProxyUser, account.ProxyPass)()

	browser.MustPage("http://ip-api.com/json")
	time.Sleep(100 * time.Second)

}
@seal seal added the question Questions related to rod label Aug 26, 2022
@ysmood
Copy link
Collaborator

ysmood commented Aug 27, 2022

Please fix your markdown #322

@ysmood ysmood closed this as completed Aug 27, 2022
@seal
Copy link
Author

seal commented Aug 29, 2022

@go-rod @everyone

@seal
Copy link
Author

seal commented Aug 29, 2022

@ysmood Please open

@ysmood ysmood reopened this Aug 30, 2022
@ysmood
Copy link
Collaborator

ysmood commented Aug 30, 2022

Check the chromium doc:

https://chromium.googlesource.com/chromium/src/+/HEAD/net/docs/proxy.md#SOCKSv5-proxy-scheme

No authentication methods are supported for SOCKSv5 in Chrome (although some do exist for the protocol).

Works fine to me if you don't use go browser.MustHandleAuth(account.ProxyUser, account.ProxyPass)().

The example proxy is something like this mitmproxy --mode socks5.

@ysmood
Copy link
Collaborator

ysmood commented Aug 30, 2022

A potential solution can be found here: #305

@ysmood ysmood closed this as not planned Won't fix, can't repro, duplicate, stale Aug 30, 2022
@ysmood ysmood added the duplicate This issue or pull request already exists label Aug 30, 2022
@seal
Copy link
Author

seal commented Aug 30, 2022

	defer func() {
		if cerr := recover(); cerr != nil {
			fmt.Println(cerr)
			fmt.Println(string(debug.Stack()))
		}
	}()

	fmt.Printf("Proxy: %s", account.Proxy)
	px, _ := url.Parse("socks5://" + account.ProxyUser + ":" + account.ProxyPass + "@" + account.Proxy) // auth
	//px, _ := url.Parse("socks5://" + account.Proxy)
	u := launcher.New().RemoteDebuggingPort(9222).Headless(false).MustLaunch()
	browser := rod.New().ControlURL(u).MustConnect()
	defer browser.MustClose()
	page := stealth.MustPage(browser)

	client := &http.Client{
		Timeout:   1 * time.Minute,
		Transport: &http.Transport{Proxy: http.ProxyURL(px)},
	}
	router := browser.HijackRequests()
	router.MustAdd("*", func(ctx *rod.Hijack) {
		err := ctx.LoadResponse(client, true)
		if err != nil {
			fmt.Println(err)
		} else {
			// You can get the response body and all from here
		}
	})

	go router.Run()
	page.HijackRequests()
	page = browser.MustPage("http://www.httpbin.org/ip")
	page.MustWaitIdle()
	time.Sleep(500 * time.Second)

Sorted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Questions related to rod
Projects
None yet
Development

No branches or pull requests

2 participants