This project has moved and is read-only. For the latest updates, please go here.

Header format for V8 debugger

May 10, 2016 at 3:08 PM
Dear ClearScript team,

I've been dabbling latey with node-inspector to see what would be needed to adapt ClearScript to work with it - aside from some global services, it looks like the header format as defined in ( does not match what is usually coming from Node.

Specifically, the node debugger (as seen in, line 72) expects a whitespace after the colon, while ClearScript is not sending one. Is this intended?

Just by changing that (plus a couple of mocked services) I am able to connect with node-inspector and inspect global variables as defined in ClearScript, so I'm hopeful about getting it to work.

May 10, 2016 at 10:26 PM

We'll be happy to adjust the header as long as it doesn't break the Eclipse debugger. Can you detail the changes you made to enable node-inspector?

May 11, 2016 at 6:46 AM

for the moment I haven't changed anything in ClearScript, opting to modify che node debugger instead (that would be, just removing the whitespace in the regular expression here at line 72) - I will take time in the next couple of days to play around with the ClearScript source code and see if just modifying the V8DebugAgent.cs gets us all the way.

Regarding the engine itself, all I've done is exposing a mock of the process and global objects with just the bare minimum fields to avoid having an exception in the inspector itself. So far I was able to inspect global variables while the engine is running and perform step-by-step debugging on compiled script(s) - although so far I was not able to have the inspector react to the "debugger symbol reached" event automatically; that is still under investigation.

Since it is of interest for you, I will try and provide an out of the box solution starting from a fork of ClearScript in the next few days. Thanks!
May 16, 2016 at 8:17 AM
Hi guys,

so, I can confirm that it is possible to connect with node-inspector by adding a space after the colons in the header transmission message, and providing (very simple) "process" and "global" objects. From the ClearScript point of view, two lines of code need to change in (

SendStringAsync(tcpClient, "Type:connect\r\nV8-Version:" + version + "\r\nProtocol-Version:1\r\nEmbedding-Host:" + name + "\r\nContent-Length:0\r\n\r\n", OnConnectionMessageSent);
SendStringAsync(tcpClient, "Type:connect\r\nV8-Version: " + version + "\r\nProtocol-Version: 1\r\nEmbedding-Host: " + name + "\r\nContent-Length: 0\r\n\r\n", OnConnectionMessageSent);
and (2)
var headerBytes = Encoding.UTF8.GetBytes(MiscHelpers.FormatInvariant("Content-Length:{0}\r\n\r\n", contentBytes.Length));
var headerBytes = Encoding.UTF8.GetBytes(MiscHelpers.FormatInvariant("Content-Length: {0}\r\n\r\n", contentBytes.Length));
Unfortunately I have no easy way to test if such changes break the Eclipse debugger (although I think that's unlikely, as the Eclipse debugger already works with node). Let me know if you need more information!
May 16, 2016 at 8:41 PM
Thank you very much for the details! We'll test these changes with Eclipse, and if all goes well, we'll include them in the next point release. Thanks again!
Jul 26, 2016 at 3:36 PM

just a quick note - since you modified the headers for the debugger protocol, it is now also possible to connect to a ClearScript instance by using the base node.js debugger (e.g. node debug localhost:9999) without any additional setup!

Now all it takes is a graphical wrapper for that :-)
Jul 27, 2016 at 1:18 PM
Great! Thanks for confirming the fix!