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

Problems in latest version #1123

Open
luabagg opened this issue Oct 13, 2024 · 2 comments
Open

Problems in latest version #1123

luabagg opened this issue Oct 13, 2024 · 2 comments
Labels
question Questions related to rod

Comments

@luabagg
Copy link

luabagg commented Oct 13, 2024

Rod Version: v0.116.2

The code to demonstrate your question

Works as expected

func TestRod(t *testing.T) {
	browser := rod.New().MustConnect()
	defer browser.MustClose()

	tests := []struct {
		name  string
		input *rod.Page
	}{
		{
			name:  "1",
			input: browser.MustPage("https://www.example.com"),
		},
	}
	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			tc.input.WaitLoad()
			tc.input.Screenshot(true, &proto.PageCaptureScreenshot{
				Format:                "png",
				Quality:               new(int),
				FromSurface:           false,
				CaptureBeyondViewport: false,
				OptimizeForSpeed:      false,
			})
		})
	}
}

Fails

func TestRod(t *testing.T) {
	browser := rod.New().MustConnect()
	defer browser.MustClose()

	tests := []struct {
		name  string
		input *rod.Page
	}{
		{
			name:  "1",
			input: browser.MustPage("https://www.example.com"),
		},
		{
			name:  "2",
			input: browser.MustPage("https://www.example.com"),
		},
		{
			name:  "3",
			input: browser.MustPage(),
		},
	}
	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			tc.input.WaitLoad()
			tc.input.Screenshot(true, &proto.PageCaptureScreenshot{
				Format:                "png",
				Quality:               new(int),
				FromSurface:           false,
				CaptureBeyondViewport: false,
				OptimizeForSpeed:      false,
			})
		})
	}
}

What you got

Second case

image

What you expect to see

 ok  	github.com/go-rod/rod

What have you tried to solve the question

Didn't look the problem yet. I'm opening the issue to inform you about the problem.
Tested in 0.112.x, 0.115.x, 0.116.0 - all works as expected.

@janpfeifer
Copy link

janpfeifer commented Oct 16, 2024

Same issue here, have anyone figured out a work around ?

Also, the instrumented chrome goes to 100% CPU usage, not sure why.

@janpfeifer
Copy link

Ok, I just had to relearn how to debug go-rod and chrome.

It seems google-chrome and the more recent chromium version fails if trying to use the GPU.

I fixed by adding the disable-gpu and disable-software-rasterizer flags in my instrumented code:

	...
	var controlURL string
	chromePath, err := exec.LookPath("google-chrome")
	var l *launcher.Launcher
	if err == nil {
		klog.V(1).Infof("Using system's Google Chrome")
		l = launcher.New().Bin(chromePath)
	} else {
		klog.Warningf("Using rod downloaded chromium, with --no-sandbox")
		l = launcher.New().NoSandbox(true)
	}
	controlURL = l.
		Set("disable-gpu", "true").
		Set("disable-software-rasterizer", "true").
		Logger(os.Stderr).
		MustLaunch()
	...

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