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

Blocking resources with SetBlockedURLs/MustSetBlockedURLs #1168

Closed
jmojon opened this issue Jan 17, 2025 · 3 comments
Closed

Blocking resources with SetBlockedURLs/MustSetBlockedURLs #1168

jmojon opened this issue Jan 17, 2025 · 3 comments
Labels
needs info The description is not enough to tackle the problem question Questions related to rod

Comments

@jmojon
Copy link

jmojon commented Jan 17, 2025

Rod Version: v0.116.2

First of all, thanks for all the work you're putting into the library!

The code to demonstrate your question

  1. Clone Rod to your local and cd to the repository:
var blocked = []string{
	"play.google.com",
	"/log",
	"play.google.com*", // a bit of desperation
	"/log*", // more so
}

func main() {
 		u := launcher.New().Headless(false).Bin("/usr/bin/google-chrome").MustLaunch()
		browser := rod.New().ControlURL(u).MustConnect()
		page1 := browser.MustPage().MustSetBlockedURLs(blocked...) // trying 3 different ways because none works for me
		page1.SetBlockedURLs(blocked)
		page1.MustSetBlockedURLs(blocked...)
		time.Sleep(10 * time.Second) // give me time to open the inspector in the launched browser
		page1.MustNavigate("https://google.com")
		page1.SetBlockedURLs(blocked) // trying both before and after navigate if that's the issue
		page1.MustSetBlockedURLs(blocked...)
		time.Sleep(60 * time.Minute) // give me time to look at the network tab in the inspector
}

What you got

Looking in the inspector I can see a request to https://play.google.com/log?format=json&hasfast=true happening. There are no URLs blocked if I look at them in the inspector.

What you expect to see

The request being blocked since I've done SetBlockedURLs. I know I can use HijackRequests and implement the blocking by myself, and that's the route I'm going for.

I'm assuming I'm misunderstanding how to use the function as for me it seems to do nothing

What have you tried to solve the question

Reading the source code and looking at https://github.com/go-rod/rod/pull/778/files

@jmojon jmojon added the question Questions related to rod label Jan 17, 2025
Copy link

Please fix the format of your markdown:

36 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## What you expect to see"]
37:164 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
43:84 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]

generated by check-issue

@Fly-Playgroud Fly-Playgroud added the needs info The description is not enough to tackle the problem label Jan 18, 2025
@Fly-Playgroud
Copy link
Contributor

Rod Version: v0.116.2

First of all, thanks for all the work you're putting into the library!

The code to demonstrate your question

  1. Clone Rod to your local and cd to the repository:

var blocked = []string{
"play.google.com",
"/log",
"play.google.com*", // a bit of desperation
"/log*", // more so
}

func main() {
u := launcher.New().Headless(false).Bin("/usr/bin/google-chrome").MustLaunch()
browser := rod.New().ControlURL(u).MustConnect()
page1 := browser.MustPage().MustSetBlockedURLs(blocked...) // trying 3 different ways because none works for me
page1.SetBlockedURLs(blocked)
page1.MustSetBlockedURLs(blocked...)
time.Sleep(10 * time.Second) // give me time to open the inspector in the launched browser
page1.MustNavigate("https://google.com")
page1.SetBlockedURLs(blocked) // trying both before and after navigate if that's the issue
page1.MustSetBlockedURLs(blocked...)
time.Sleep(60 * time.Minute) // give me time to look at the network tab in the inspector
}

What you got

Looking in the inspector I can see a request to https://play.google.com/log?format=json&hasfast=true happening. There are no URLs blocked if I look at them in the inspector.

What you expect to see

The request being blocked since I've done SetBlockedURLs. I know I can use HijackRequests and implement the blocking by myself, and that's the route I'm going for.

I'm assuming I'm misunderstanding how to use the function as for me it seems to do nothing

What have you tried to solve the question

Reading the source code and looking at https://github.com/go-rod/rod/pull/778/files

Could you please provide the screeshoot of inspector?

@jmojon
Copy link
Author

jmojon commented Jan 19, 2025

Could you please provide the screeshoot of inspector?

I tried again and looked at the test in the PR, there I spotted something I failed to do: page1.EnableDomain(proto.NetworkEnable{})

With that call before Block it works, so it was indeed on my side. I'm not sure what that call does but my issue seems solved.

@jmojon jmojon closed this as completed Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info The description is not enough to tackle the problem question Questions related to rod
Projects
None yet
Development

No branches or pull requests

2 participants