Chrome Debugging API

TL;DR – C# Chrome Developer Tools API

While, I was hunting for some SEO tools related to page loading performance, I stumbled on something that I heard about, but never saw with my bare eyes – the Chrome Debugger Protocol.  While the website would lead you to believe the protocol is fairly thin, think again.  The protocol is much more exhaustive.  The protocol is used by the Chrome Developer Tools.  So everything you see in this window, you can interact with.

Chrome Developer Tools - Network

 

This is available via a WebSockets endpoint over which JSON commands and events are sent.  While this is great (seriously, this is really cool stuff by Chrome), I’m a C# guy.  So, I did what any rational human would do – I wrote a parser to generate C# objects for every command and event in the protocol.  Then, I packaged that up with some classes to enable Chrome debugging and send/receive messages.  I adding in a small sample, put it up and GitHub and, well … have fun!

Here’s a small example of how to use the library in C#:

 
using MasterDevs.ChromeDevTools;
...
    chromeSession.Subscribe<Protocol.Page.DomContentEventFiredEvent>(domContentEvent =>
    {
        System.Console.WriteLine("DomContentEvent: " + domContentEvent.Timestamp);
    });

    chromeSession.SendAsync(new NavigateCommand
    {
        Url = "http://www.google.com"
    }).Wait();

The protocol is pretty extensive.  You can checkout the protocol.json file, which defines the events, commands, parameters, and more right here.  You can find a description of how the Chrome Debugger Protocol works, along with all the code, up in the MasterDevs repository ChromeDevTools.

I really hope you use it, enjoy it, let me know if there are issues, and, most importantly, let me know what you build with it!