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

illegal formated jsonrpc ? #133

Open
DiSToAGe opened this issue Aug 23, 2021 · 2 comments
Open

illegal formated jsonrpc ? #133

DiSToAGe opened this issue Aug 23, 2021 · 2 comments

Comments

@DiSToAGe
Copy link

It seems there is an illegal formatting of data through jsonrpc:
(the test is made through output of debug of chrome browser via websocket as in the doc example)

  1. launch chrome in debug (google-chrome-stable --remote-debugging-port=9222)
  2. get browser version parsed via jsonrpc
    echo '{"method":"Browser.getVersion","params":{}, "id":1}' | websocat -n1 --text - jsonrpc:ws://127.0.0.1:9222/devtools/page/<youridofwebsocket> and you will get
    {"jsonrpc":"2.0","id":1, "method":"{"id":1,"result":...
    !! on value of method you have "{"id"... which seems illegal json, you must have "method":{"id"... without double quote before {
    (if you parse data through "jq" command (...| jq '.'), it gets errors

another problem, UserAgent value is split after Mozilla value, the rest is in the "params".

other problem, on the params there is an Array with no open double quote, but ending double quote.

On the end there is too inverted "]" and "}"

see complete line :
{"jsonrpc":"2.0","id":1, "method":"{"id":1,"result":{"protocolVersion":"1.3","product":"Chrome/92.0.4515.159","revision":"@0185b8a19c88c5dfd3e6c0da6686d799e9bc3b52","userAgent":"Mozilla/5.0", "params":[(X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36","jsVersion":"9.2.230.29"}}]}

if you get data without jsonrpc:, so via
echo '{"method":"Browser.getVersion","params":{}, "id":1}' | websocat -n1 --text - ws://127.0.0.1:9222/devtools/page/<youridofwebsocket>

the data is correctly formatted as
{"id":1,"result":{"protocolVersion":"1.3","product":"Chrome/92.0.4515.159","revision":"@0185b8a19c88c5dfd3e6c0da6686d799e9bc3b52","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36","jsVersion":"9.2.230.29"}}
and parsing it through ...| jq '.' is correct.

If you get other chrome debug command, you get same errors of formatting via jsonrpc: (added double quote, wrong of array ending/beggin ...)

@DiSToAGe
Copy link
Author

ps: nice software :-)

@vi
Copy link
Owner

vi commented Aug 23, 2021

Why do you both specify jsonrpc: and type the JSON manually?

It is supposed to be used like this:

echo Browser.getVersion '{}' | websocat -n1 --text jsonrpc:- ws://127.0.0.1:9222/devtools/page/...

It would convert Browser.getVersion {} into {"jsonrpc":"2.0","id":1, "method":"Browser.getVersion", "params":{}}

jsonrpc: overlay (or --jsonrpc option) is not required for doing JSON RPC over Websocat, it's just a helper to type JSON RPC requests interactively. The overlay is rather simplistic and does not use any actual JSON library. Recommended command line for this is:

rlwrap websocat --jsonrpc ws://127.0.0.1:9222/devtools/page/...

This way you would get line editing and history and also avoid typing a lot of {"":""}-s.

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