go-rod / rod

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

Infinite page loading while hijacking (Failed to deserialize params.body - BINDINGS: binary value expected at position 59) #1118

Closed KernelPryanic closed 1 month ago

KernelPryanic commented 1 month ago

Rod Version: v0.116.2

The code to demonstrate your question

func main() {
    l := launcher.New().
        Headless(false).
        Devtools(true).
        UserDataDir("tmp-data")
    url := l.MustLaunch()
    browser := rod.New().NoDefaultDevice().ControlURL(url).MustConnect()
    defer browser.MustClose()
    router := browser.HijackRequests()
    err := router.Add("*", proto.NetworkResourceTypeDocument, func(ctx *rod.Hijack) {
        ctx.Request.Req().Header.Set("x-test-header", "indeed")
        ctx.OnError = func(e error) { panic(e) }
    })
    if err != nil {
        fmt.Println("Error adding hijack: ", err)
        return
    }
    go router.Run()

    page, err = browser.Page(proto.TargetCreateTarget{})
    if err != nil {
        fmt.Println("Error creating new page: ", err)
        return
    }

    err = page.Navigate("https://nl.indeed.com/jobs?fromage=1&l=Nederland&q=&sort=date&start=0")
    if err != nil {
        fmt.Println("Error navigating to page: ", err)
        return
    }

    time.Sleep(10 * time.Minute)
}

What you got

panic: {-32602 Invalid parameters Failed to deserialize params.body - BINDINGS: binary value expected at position 59}

What you expect to see

Expected to see the destination page loaded.

What have you tried to solve the question

Tried to use different versions, seems to get it everywhere down to v0.112.9, didn't go to the older versions.

Also when change to proto.NetworkResourceTypeFetch for example, the page gets loaded, but no headers added to the fetch resource types requests.

github-actions[bot] commented 1 month ago

Please fix the format of your markdown:

43 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]

generated by check-issue

ysmood commented 1 month ago

You forget to call the continue, check the usage example here:

https://github.com/go-rod/rod/blob/c42b414fffbd412dddac4903e5bc9355c6bb786c/hijack_test.go#L108-L129

KernelPryanic commented 1 month ago

@ysmood thank you, that helped!