go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.
https://go-rod.github.io
MIT License
5.39k stars 354 forks source link

Problems in latest version #1123

Open luabagg opened 1 month ago

luabagg commented 1 month ago

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 commented 4 weeks ago

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

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

janpfeifer commented 4 weeks ago

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()
    ...