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!

This entry was posted in .NET, C# by Kevin. Bookmark the permalink.

About Kevin

I'm a software engineer who loves a good challenge. I've developed software in Prolog, Java, .NET, JavaScript, etc. and continually increase my language knowledge in order to be able to develop solutions that are efficient, effective, and scalable. I'm currently focused on developing web applications utilizing the .NET platform, including Windows Azure, SQL Server, ASP.NET to name a few. I used to play little league baseball and I was horrible.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>