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

Get cookies json unmarshal error page.MustCookies() #1094

Open
fakis opened this issue Jul 18, 2024 · 7 comments
Open

Get cookies json unmarshal error page.MustCookies() #1094

fakis opened this issue Jul 18, 2024 · 7 comments
Labels
needs info The description is not enough to tackle the problem question Questions related to rod

Comments

@fakis
Copy link

fakis commented Jul 18, 2024

Rod Version: v0.116.2

The code to demonstrate your question

  1. Try to open youtube.com with a browser
  2. Log in with Google authorization
  3. An error occurred while getting the cookies for the youtube.com page
func TestYoutubePageGetCookies(t *testing.T) {
    u := launcher.NewUserMode().Headless(false).MustLaunch()
    browser := rod.New().ControlURL(u).MustConnect().NoDefaultDevice()
    defer browser.MustClose()
    
    page := browser.MustPage("https://www.youtube.com/")
    
    // During the waiting time, log in with Google authorization
    time.Sleep(30 * time.Second)
    
    // After authorization, get page cookies and report an error.
    cookies := page.MustCookies()
    fmt.Println(cookies)
}

Error details

panic: json: cannot unmarshal string into Go struct field NetworkCookie.cookies.partitionKey of type proto.NetworkCookiePartitionKey [recovered]
	panic: json: cannot unmarshal string into Go struct field NetworkCookie.cookies.partitionKey of type proto.NetworkCookiePartitionKey

goroutine 34 [running]:
testing.tRunner.func1.2({0x8429a0, 0xc000428140})
	C:/Users/Administrator/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1631 +0x24a
testing.tRunner.func1()
	C:/Users/Administrator/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1634 +0x377
panic({0x8429a0?, 0xc000428140?})
	C:/Users/Administrator/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x132
github.com/go-rod/rod/lib/utils.init.func2({0x8429a0?, 0xc000428140?})
	C:/Users/Administrator/go/pkg/mod/github.com/go-rod/[email protected]/lib/utils/utils.go:68 +0x1d
yt.TestYoutubePageGetCookies.New.(*Browser).WithPanic.genE.func1({0xc00008e690?, 0x0?, 0x372eda?})
	C:/Users/Administrator/go/pkg/mod/github.com/go-rod/[email protected]/must.go:36 +0x62
github.com/go-rod/rod.(*Page).MustCookies(0xc00042a000, {0x0?, 0x35ac3f?, 0xc84ad0?})
	C:/Users/Administrator/go/pkg/mod/github.com/go-rod/[email protected]/must.go:197 +0x97
yt.TestYoutubePageGetCookies(0xc0003a2340?)
	D:/www/rpa/yt/rod_test.go:25 +0x470
testing.tRunner(0xc0003a2340, 0xac4da8)
	C:/Users/Administrator/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1689 +0xfb
created by testing.(*T).Run in goroutine 1
	C:/Users/Administrator/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1742 +0x390
  • Is it possible that the PartitionKey uses the pointer type, resulting in a json parsing error?
package proto

type NetworkCookie struct {
	...

	// PartitionKey (experimental) (optional) Cookie partition key.
	PartitionKey *NetworkCookiePartitionKey `json:"partitionKey,omitempty"` 
}
@fakis fakis added the question Questions related to rod label Jul 18, 2024
Copy link

Please fix the format of your markdown:

7 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "3. An error occurred while get..."]
8 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"]
26 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
26 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
51 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- Is it possible that the `Par..."]
52 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```go"]

Please fix the golang code in your markdown:

@@ golang markdown block 1 @@
4:2: expected '}', found '...'
7:2: expected ';', found PartitionKey

generated by check-issue

@Fly-Playgroud
Copy link
Contributor

Colud you please show your browser type and version

@Fly-Playgroud Fly-Playgroud added the needs info The description is not enough to tackle the problem label Jul 20, 2024
@ysmood
Copy link
Member

ysmood commented Jul 21, 2024

It's because the latest cdp protocol has changed the data fields. If you upgrade your chrome to the latest version, the problem should be resolved. Or you can use a old version of rod to use the old protocol.

@Fly-Playgroud
Copy link
Contributor

#1097

@ysmood
Copy link
Member

ysmood commented Jul 22, 2024

@fakis
Copy link
Author

fakis commented Jul 22, 2024

ok, thank you, it is indeed such a problem, but the field such as cdp can also be changed

It's because the latest cdp protocol has changed the data fields. If you upgrade your chrome to the latest version, the problem should be resolved. Or you can use a old version of rod to use the old protocol.

@MmToon
Copy link

MmToon commented Sep 9, 2024

So what is the minimum version of browser it currently supports?

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

4 participants