vi / websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
MIT License
7.16k stars 279 forks source link

Chromium example does not work #136

Open prRZ5F4LXZ opened 3 years ago

prRZ5F4LXZ commented 3 years ago

I am trying to follow the example under "Open a tab in Chromium using remote debugging" on https://github.com/vi/websocat

But it does not work.

$ /Applications/Chromium.app/Contents/MacOS/Chromium  --remote-debugging-port=9222

DevTools listening on ws://127.0.0.1:9222/devtools/browser/0f4307c7-e38b-4721-8054-b4354e5d6da2
[34888:259:1021/085842.682687:ERROR:device_event_log_impl.cc(214)] [08:58:42.682] FIDO: touch_id_context.mm:127 Touch ID authenticator unavailable because keychain-access-group entitlement is missing or incorrect

Does anybody know what is wrong?

$ curl -sg http://127.0.0.1:9222/json/new
{
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=127.0.0.1:9222/devtools/page/FC28287234A1C005E927770F55793B1B",
   "id": "FC28287234A1C005E927770F55793B1B",
   "title": "",
   "type": "page",
   "url": "about:blank",
   "webSocketDebuggerUrl": "ws://127.0.0.1:9222/devtools/page/FC28287234A1C005E927770F55793B1B"
}
$ echo 'Page.navigate {"url":"https://example.com"}' | websocat -n1 --jsonrpc ws://127.0.0.1:9222/devtools/page/FC28287234A1C005E927770F55793B1B
{"error":{"code":-32600,"message":"Message has property other than 'id', 'method', 'sessionId', 'params'"}}
vi commented 3 years ago

Maybe Chromium stopped accepting jsonrpc keys in input messages?

--jsonrpc switch converts Page.navigate {"url":"https://example.com"} to {"jsonrpc":"2.0","id":1, "method":"Page.navigate", "params":{"url":"https://example.com"}}. Error message suggests that it does not like jsonrpc field.

Try to supply direct json input without the help of --jsonrpc option. It may need readjustment.

yonas commented 2 years ago

This works for me:

url=$(curl -sg http://127.0.0.1:9222/json/new | grep webSocketDebuggerUrl | cut -d'"' -f4 | head -1)
echo '{ "id":2, "method":"Page.navigate", "params":{"url": "https://example.com"} }' | websocat -t - $url
vi commented 2 years ago
url=$(curl -sg http://127.0.0.1:9222/json/new | grep webSocketDebuggerUrl | cut -d'"' -f4 | head -1)
echo '{ "id":2, "method":"Page.navigate", "params":{"url": "https://example.com"} }' | websocat -t - $url

Tried these two commands myself on "Chromium 103.0.5060.53 (Official Build) built on Debian 11.3" - first line opened a new tab in the Chromium and second line navigated it to example.com.

What does fail for you? Creating tab or navigating it?

yonas commented 2 years ago
url=$(curl -sg http://127.0.0.1:9222/json/new | grep webSocketDebuggerUrl | cut -d'"' -f4 | head -1)
echo '{ "id":2, "method":"Page.navigate", "params":{"url": "https://example.com"} }' | websocat -t - $url

Tried these two commands myself on "Chromium 103.0.5060.53 (Official Build) built on Debian 11.3" - first line opened a new tab in the Chromium and second line navigated it to example.com.

What does fail for you? Creating tab or navigating it?

Works for me as well.