From a733b57f8dca92058636a1cc1b23a15ccdbf8928 Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Tue, 24 Jan 2017 22:21:23 +0700 Subject: [PATCH] Updating to latest chrome protocol.json --- cdp/network/easyjson.go | 70 ++++++++++++++++++++++++++-------- cdp/network/network.go | 20 +++++++++- cdp/network/types.go | 9 +++-- cmd/chromedp-gen/protocol.json | 12 ++++++ 4 files changed, 90 insertions(+), 21 deletions(-) diff --git a/cdp/network/easyjson.go b/cdp/network/easyjson.go index 2b3e6c9..15c1b5a 100644 --- a/cdp/network/easyjson.go +++ b/cdp/network/easyjson.go @@ -2588,6 +2588,25 @@ func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpNetwork23(in *jlexer.Lexer, ou continue } switch key { + case "urls": + if in.IsNull() { + in.Skip() + out.Urls = nil + } else { + in.Delim('[') + if !in.IsDelim(']') { + out.Urls = make([]string, 0, 4) + } else { + out.Urls = []string{} + } + for !in.IsDelim(']') { + var v10 string + v10 = string(in.String()) + out.Urls = append(out.Urls, v10) + in.WantComma() + } + in.Delim(']') + } default: in.SkipRecursive() } @@ -2602,6 +2621,25 @@ func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpNetwork23(out *jwriter.Writer, out.RawByte('{') first := true _ = first + if len(in.Urls) != 0 { + if !first { + out.RawByte(',') + } + first = false + out.RawString("\"urls\":") + if in.Urls == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v11, v12 := range in.Urls { + if v11 > 0 { + out.RawByte(',') + } + out.String(string(v12)) + } + out.RawByte(']') + } + } out.RawByte('}') } @@ -2659,9 +2697,9 @@ func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpNetwork24(in *jlexer.Lexer, ou out.TableNames = []string{} } for !in.IsDelim(']') { - var v10 string - v10 = string(in.String()) - out.TableNames = append(out.TableNames, v10) + var v13 string + v13 = string(in.String()) + out.TableNames = append(out.TableNames, v13) in.WantComma() } in.Delim(']') @@ -2690,11 +2728,11 @@ func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpNetwork24(out *jwriter.Writer, out.RawString("null") } else { out.RawByte('[') - for v11, v12 := range in.TableNames { - if v11 > 0 { + for v14, v15 := range in.TableNames { + if v14 > 0 { out.RawByte(',') } - out.String(string(v12)) + out.String(string(v15)) } out.RawByte(']') } @@ -2823,17 +2861,17 @@ func easyjsonC5a4559bDecodeGithubComKnqChromedpCdpNetwork26(in *jlexer.Lexer, ou out.Cookies = []*Cookie{} } for !in.IsDelim(']') { - var v13 *Cookie + var v16 *Cookie if in.IsNull() { in.Skip() - v13 = nil + v16 = nil } else { - if v13 == nil { - v13 = new(Cookie) + if v16 == nil { + v16 = new(Cookie) } - (*v13).UnmarshalEasyJSON(in) + (*v16).UnmarshalEasyJSON(in) } - out.Cookies = append(out.Cookies, v13) + out.Cookies = append(out.Cookies, v16) in.WantComma() } in.Delim(']') @@ -2862,14 +2900,14 @@ func easyjsonC5a4559bEncodeGithubComKnqChromedpCdpNetwork26(out *jwriter.Writer, out.RawString("null") } else { out.RawByte('[') - for v14, v15 := range in.Cookies { - if v14 > 0 { + for v17, v18 := range in.Cookies { + if v17 > 0 { out.RawByte(',') } - if v15 == nil { + if v18 == nil { out.RawString("null") } else { - (*v15).MarshalEasyJSON(out) + (*v18).MarshalEasyJSON(out) } } out.RawByte(']') diff --git a/cdp/network/network.go b/cdp/network/network.go index 9a4cc69..3e79f56 100644 --- a/cdp/network/network.go +++ b/cdp/network/network.go @@ -739,15 +739,25 @@ func (p *ClearBrowserCookiesParams) Do(ctxt context.Context, h FrameHandler) (er // GetCookiesParams returns all browser cookies for the current URL. // Depending on the backend support, will return detailed cookie information in // the cookies field. -type GetCookiesParams struct{} +type GetCookiesParams struct { + Urls []string `json:"urls,omitempty"` // The list of URLs for which applicable cookies will be fetched +} // GetCookies returns all browser cookies for the current URL. Depending on // the backend support, will return detailed cookie information in the cookies // field. +// +// parameters: func GetCookies() *GetCookiesParams { return &GetCookiesParams{} } +// WithUrls the list of URLs for which applicable cookies will be fetched. +func (p GetCookiesParams) WithUrls(urls []string) *GetCookiesParams { + p.Urls = urls + return &p +} + // GetCookiesReturns return values. type GetCookiesReturns struct { Cookies []*Cookie `json:"cookies,omitempty"` // Array of cookie objects. @@ -762,8 +772,14 @@ func (p *GetCookiesParams) Do(ctxt context.Context, h FrameHandler) (cookies []* ctxt = context.Background() } + // marshal + buf, err := easyjson.Marshal(p) + if err != nil { + return nil, err + } + // execute - ch := h.Execute(ctxt, CommandNetworkGetCookies, Empty) + ch := h.Execute(ctxt, CommandNetworkGetCookies, easyjson.RawMessage(buf)) // read response select { diff --git a/cdp/network/types.go b/cdp/network/types.go index cc13d32..be5b499 100644 --- a/cdp/network/types.go +++ b/cdp/network/types.go @@ -502,9 +502,10 @@ func (t InitiatorType) String() string { // InitiatorType values. const ( - InitiatorTypeParser InitiatorType = "parser" - InitiatorTypeScript InitiatorType = "script" - InitiatorTypeOther InitiatorType = "other" + InitiatorTypeParser InitiatorType = "parser" + InitiatorTypeScript InitiatorType = "script" + InitiatorTypePreload InitiatorType = "preload" + InitiatorTypeOther InitiatorType = "other" ) // MarshalEasyJSON satisfies easyjson.Marshaler. @@ -524,6 +525,8 @@ func (t *InitiatorType) UnmarshalEasyJSON(in *jlexer.Lexer) { *t = InitiatorTypeParser case InitiatorTypeScript: *t = InitiatorTypeScript + case InitiatorTypePreload: + *t = InitiatorTypePreload case InitiatorTypeOther: *t = InitiatorTypeOther diff --git a/cmd/chromedp-gen/protocol.json b/cmd/chromedp-gen/protocol.json index 8e38593..1b99e71 100644 --- a/cmd/chromedp-gen/protocol.json +++ b/cmd/chromedp-gen/protocol.json @@ -2387,6 +2387,7 @@ "enum": [ "parser", "script", + "preload", "other" ], "description": "Type of this initiator." @@ -2621,6 +2622,17 @@ }, { "name": "getCookies", + "parameters": [ + { + "name": "urls", + "type": "array", + "items": { + "type": "string" + }, + "optional": true, + "description": "The list of URLs for which applicable cookies will be fetched" + } + ], "returns": [ { "name": "cookies",