HyperionGray/python-chrome-devtools-protocol

Responses have changed.

Ghxst opened this issue · 2 comments

Ghxst commented

The contents of the JSON responses returned by chrome need to be accessed via the result key.

Currently the return statements created by the generator (example: return Node.from_json(json['root'])) will raise a KeyError.
To fix this, return statements should be changed to Node.from_json(json['result']['root'])

Can you point me to what part of the generator code handles this? I can fix it and create a pull request.

This actually hasn't changed. The result key is part of the JSON RPC-ish protocol that Chrome speaks. This project assumes that you implement the RPC framing in a higher level library (but see #12 as a potential change there), so at that higher level you would unpack the response, check for errors, and if everything was okay, then you'd convert the json['result'] to a native Python CDP type.

For example, see https://github.com/HyperionGray/trio-chrome-devtools-protocol/blob/0.5.0/trio_cdp/__init__.py#L139.

I don't think we could add the ['result'] in this project right now even if we wanted to, because from_json() is used recursively, i.e. objects will call this to create objects out of subdictionaries, and those subdictionaries won't have a result key in them.

Ghxst commented

Oo ok that makes sense now, thank you for the detailed explanation!
I will close this issue. :)