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

Recaptcha not load properly when hijack #672

Closed
musicyin opened this issue Aug 4, 2022 · 4 comments
Closed

Recaptcha not load properly when hijack #672

musicyin opened this issue Aug 4, 2022 · 4 comments
Labels
question Questions related to rod

Comments

@musicyin
Copy link

musicyin commented Aug 4, 2022

Rod Version: v0.108.1

browser := rod.New().ControlURL(launcher.New().Delete("headless").MustLaunch()).MustConnect()
router := browser.HijackRequests()
router.MustAdd("*", func(ctx *rod.Hijack) {
	ctx.MustLoadResponse()
})
go router.Run()
page := browser.MustPage("")
page.MustNavigate("https://www.google.com/recaptcha/api2/demo")
time.Sleep(50000 * time.Second)

What you got
The recaptcha got error
What you expected to see
The recaptcha can normally solve

@musicyin musicyin added the question Questions related to rod label Aug 4, 2022
@musicyin musicyin changed the title In the case of intercepting requests, some links cannot be redirected normally Recaptcha not load properly Aug 4, 2022
@musicyin musicyin changed the title Recaptcha not load properly Recaptcha not load properly when hijack Aug 4, 2022
@ysmood
Copy link
Member

ysmood commented Aug 4, 2022

If you want to transparently handle requests, you should code like this:

router.MustAdd("*", func(ctx *rod.Hijack) {
	ctx.ContinueRequest(&proto.FetchContinueRequest{})
})

@ysmood
Copy link
Member

ysmood commented Aug 4, 2022

Also check #395

@ysmood ysmood closed this as completed Aug 4, 2022
@musicyin
Copy link
Author

musicyin commented Aug 4, 2022

If you want to transparently handle requests, you should code like this:

router.MustAdd("*", func(ctx *rod.Hijack) {
	ctx.ContinueRequest(&proto.FetchContinueRequest{})
})

How can I get the response of it ?

I have try
ctx.ContinueRequest(&proto.FetchContinueRequest{})
fmt.Println(&proto.FetchGetResponseBody{})
fmt.Println(ctx.Response.Body())
but it only have empty response

Thank you.

@ysmood
Copy link
Member

ysmood commented Aug 5, 2022

The cdp protocol is not designed to use hijacking every request, you have to filter specific URLs.
This is an upstream issue of chromium, you can ask the chromium team to fix it.

You can do either this:

	router.MustAdd("*index.js", func(ctx *rod.Hijack) {
		ctx.MustLoadResponse()
		fmt.Println(ctx.Response.Body())
	})

or this:

	router.MustAdd("*", func(ctx *rod.Hijack) {
		if strings.HasSuffix(ctx.Request.URL().String(), "index.js") {
			ctx.MustLoadResponse()
			fmt.Println(ctx.Response.Body())
		} else {
			ctx.ContinueRequest(&proto.FetchContinueRequest{})
		}
	})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

2 participants