chromedp / pdlgen

Generates templated code using Chrome DevTools PDL definitions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsonUnmarshal fail from a jsonMarshal result of *network.Cookie

bronze1man opened this issue · comments

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

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.