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

Resources content is nil #1040

Closed
and0x00 opened this issue Apr 15, 2024 · 2 comments
Closed

Resources content is nil #1040

and0x00 opened this issue Apr 15, 2024 · 2 comments
Labels
question Questions related to rod

Comments

@and0x00
Copy link

and0x00 commented Apr 15, 2024

Rod Version: v0.114.8

Hello again. Guys, I would like insights / example code on how to get the entire list of resources (js and css) directly from the browser and also its content. The idea is to extract all these resources by accessing the page only once and taking advantage of everything that was loaded by the browser.

I have something similar to this:

	var e proto.NetworkResponseReceived
	wait := page.WaitEvent(&e)

	xhrURLs := make([]string, 0)
	go page.EachEvent(func(e *proto.NetworkRequestWillBeSent) {
		if e.DocumentURL != "" {
			if e.Type == proto.NetworkResourceTypeScript {
				bin, _ := page.GetResource(e.Request.URL)
				fmt.Printf("%v\n", bin)
			}
		}
	})()

	page.MustNavigate(URL).MustWaitLoad().MustWaitDOMStable().MustWaitStable()
	wait()

Complete code: https://gist.github.com/and0x00/36f2b6ec9e730fa8a3118cf61db1a3c1

Output

[]
[]
[]
[]
[]
[]
[]

I know it would also be possible using proto.PageGetResourceTree, but I would like a working example as similar as possible to the current version of my code.

@and0x00 and0x00 added the question Questions related to rod label Apr 15, 2024
@and0x00 and0x00 changed the title Get all resources content in string 🤓 Get all resources content in string format 🤓 Apr 15, 2024
@and0x00 and0x00 changed the title Get all resources content in string format 🤓 Resources content is nil Apr 16, 2024
Copy link

Please fix the format of your markdown:

23 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
28 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]

generated by check-issue

@and0x00 and0x00 closed this as completed Apr 17, 2024
@and0x00
Copy link
Author

and0x00 commented Apr 17, 2024

I solved this

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

1 participant