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

Modifying the headers in the Request seems to have no effect. #1151

Closed
moxcomic opened this issue Nov 25, 2024 · 4 comments
Closed

Modifying the headers in the Request seems to have no effect. #1151

moxcomic opened this issue Nov 25, 2024 · 4 comments
Labels
question Questions related to rod

Comments

@moxcomic
Copy link

Rod Version: v0.116.2

When I tried using the method from this example, it didn’t work. The new header attribute does not appear in the Chrome network panel.

	browser := rod.New().ControlURL(launcher.New().Headless(false).Bin("/Applications/Google Chrome.app/Contents/MacOS/Google Chrom").MustConnect()
	defer browser.MustClose()

	router := browser.HijackRequests()
	defer router.MustStop()

	router.MustAdd("*.js", func(ctx *rod.Hijack) {
		// Here we update the request's header. Rod gives functionality to
		// change or update all parts of the request. Refer to the documentation
		// for more information.
		ctx.Request.Req().Header.Set("My-Header", "test")

		// LoadResponse runs the default request to the destination of the request.
		// Not calling this will require you to mock the entire response.
		// This can be done with the SetXxx (Status, Header, Body) functions on the
		// ctx.Response struct.
		_ = ctx.LoadResponse(http.DefaultClient, true)

		// Here we append some code to every js file.
		// The code will update the document title to "hi"
		ctx.Response.SetBody(ctx.Response.Body() + "\n document.title = 'hi' ")
	})

	go router.Run()

	browser.MustPage("https://go-rod.github.io").MustWait(`() => document.title === 'hi'`)
@moxcomic moxcomic added the question Questions related to rod label Nov 25, 2024
@moxcomic
Copy link
Author

After analyzing with a packet capture tool, the modifications are indeed present.

@yuxingfei
Copy link

"新的标头属性未出现在 Chrome 网络面板中" 我也遇到了这个问题,为什么修改后的header没有显示在面板中

@moxcomic
Copy link
Author

"新的标头属性未出现在 Chrome 网络面板中" 我也遇到了这个问题,为什么修改后的header没有显示在面板中

我也不知道为什么,但是通过抓包软件显示是生效的。

@yuxingfei
Copy link

"新的标头属性未出现在 Chrome 网络面板中" 我也遇到了这个问题,为什么修改后的header没有显示在面板中

我也不知道为什么,但是通过抓包软件显示是生效的。

QQ_1732757804779
作者这样回复了,说chrome调试窗口监测不到发生时变化,实际是生效了的

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