Thank you for the response, Pavel!
I've modified the code in the following way:
var socket = new WebSockets.WebSocket("ws://localhost:9123/
devtools/page/1");
socket.OnMessage += (sender, eventdata) =>
Console.WriteLine(">> " + eventdata);
socket.OnError += (sender, eventdata) =>
Console.WriteLine(">> ERROR: " + eventdata);
socket.OnOpen += (sender, e) => Console.WriteLine(">>>
Connected to socket");
socket.OnClose += (sender, e) => Console.WriteLine(">>>
Connection closed");
socket.Connect();
const string getDocumentRequest = "request: {\"id\": 0,
\"method\": \"DOM.getDocument\"}";
Console.WriteLine(getDocumentRequest);
socket.Send(getDocumentRequest);
Console.WriteLine(getDocumentRequest);
socket.Send(getDocumentRequest);
And it gives me the following log:
[ {
"devtoolsFrontendUrl": "/devtools/devtools.html?host=localhost:
9123&page=1",
"faviconUrl": "
https://mail.google.com/mail/images/favicon.ico",
"thumbnailUrl": "/thumb/
https://mail.google.com/mail/?shva=1***",
"title": "Gmail - Remote DOM modifications - ***",
"url": "
https://mail.google.com/mail/?shva=1***",
"webSocketDebuggerUrl": "ws://localhost:9123/devtools/page/1"
}, {
"devtoolsFrontendUrl": "/devtools/devtools.html?host=localhost:
9123&page=2",
"faviconUrl": "
http://groups.google.com/groups/img/3/favicon.ico",
"thumbnailUrl": "/thumb/
http://groups.google.com/group/google-
chrome-develope
r-tools/browse_thread/thread/3c07878f68010425/d7b75570a0881ebf?
show_docid=d7b755
70a0881ebf&pli=1",
"title": "Remote DOM modifications - Google Chrome Developer Tools
| Google G
roups",
"url": "
http://groups.google.com/group/google-chrome-developer-
tools/browse_t
hread/thread/3c07878f68010425/d7b75570a0881ebf?
show_docid=d7b75570a0881ebf&pli=1
",
"webSocketDebuggerUrl": "ws://localhost:9123/devtools/page/2"
} ]
>>> Connected to socket
request: {"id": 0, "method": "DOM.getDocument"}
request: {"id": 0, "method": "DOM.getDocument"}
>> ERROR: Unable to read data from the transport connection: An existing connect
ion was forcibly closed by the remote host.
>> ERROR: Unable to write data to the transport connection: An existing connecti
on was forcibly closed by the remote host.
Type "exit" to exit.
>>> Connection closed
>
The following happens:
1. Application gets the list of pages from the browser by sending the
HTTP request to localhost:9123
2. Then it creates WebSoket connection (sends Connection: Upgrade and
recieves response)
3. Then it sends the "request: {\"id\": 0, \"method\":
\"DOM.getDocument\"}" into the socket and the browser terminates the
connection so the send sending of the same request throws the
exception.
Thank you for the help!
Regards,
Alex