chromedp / cdproto

Package cdproto contains the generated commands, types, and events for the Chrome DevTools Protocol domains.
MIT License
145 stars 54 forks source link

UnmarshalMessage panics when encountering deprecated messages #2

Closed mvdan closed 5 years ago

mvdan commented 5 years ago

For example, 8d5e1d04ce19b7b3e61493418de25a281de3709d got rid of Page.frameScheduledNavigation and all of its types. In UnmarshalMessage, that event method now doesn't fall under any of the cases, and ends up calling json.Unmarshal(buf, v) where v == nil.

The fix here is probably to modify cdproto-gen so that UnmarshalMessage handles this case gracefully:

diff --git a/cdproto.go b/cdproto.go
index 21f111e..fb513e9 100644
--- a/cdproto.go
+++ b/cdproto.go
@@ -2243,6 +2243,9 @@ func UnmarshalMessage(msg *Message) (interface{}, error) {

        case EventTracingTracingComplete:
                v = new(tracing.EventTracingComplete)
+
+       default:
+               return nil, errors.New("unknown or deprecated event method")
        }

        var buf easyjson.RawMessage

I've worked around this in chromedp v0 by capturing these events before the function is called, which is not ideal: https://github.com/chromedp/chromedp/commit/e9aa66f87e8cea7c220822b62e1ca3b90356b9cc

/cc @kenshaw

kenshaw commented 5 years ago

Sorry; missed this a week ago. Writing a fix now.

kenshaw commented 5 years ago

Fixed.

haohanger commented 5 years ago

@kenshaw

got rid of Page.frameRequestedNavigation and all of its types. In UnmarshalMessage, that event method now doesn't fall under any of the cases, Page. FrameRequestedNavigation also need for processing,Like this:

switch msg.Method { case "Page.frameClearedScheduledNavigation", "Page.frameRequestedNavigation", "Page.frameScheduledNavigation": // These events are now deprecated, and UnmarshalMessage panics // when they are received from Chrome. For now, to avoid panics // and compile errors, and to fix chromedp v0 when installed via // 'go get -u', skip the events here. return nil }

mvdan commented 5 years ago

@haohanger please file a new issue, following the issue template.