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

jsonUnmarshal fail from a jsonMarshal result of *network.Cookie #4

Closed
bronze1man opened this issue Apr 1, 2020 · 1 comment
Closed

Comments

@bronze1man
Copy link

follow code will panic:

package main

import (
   	"github.com/chromedp/cdproto/network"
	"encoding/json"
)
func main() {
	b,err:=json.Marshal(&network.Cookie{})
	if err!=nil{
		panic(err)
	}
	var c *network.Cookie
	err=json.Unmarshal(b,&c)
	if err!=nil{
		panic(err)
	}
	return
}

same issue from chromedp/cdproto#7

@ZekeLu
Copy link
Member

ZekeLu commented May 18, 2021

The aim of the generated package github.com/chromedp/cdproto is to drive Chrome through the CDP. According to Network.Cookie, the priority field is mandatory. And according to Network.CookiePriority, the allowed values are: Low, Medium, High. So it's reasonable to return an error when the json does not contain the priority field. Regarding the marshaling part, the browser passed network.Cookie to a CDP client, and it's the browser's responsibility to make sure the value is valid (according to the protocol). So it's working as intended.

I'm not sure why you use it in this way. Closing the issue for now. Let me know if you think differently.

@ZekeLu ZekeLu closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants