This project generates a wrapper based on the current version of the Chrome Developer Protocol Definition. The supplied template targets .Net Core and creates a .csproj and corresponding class files that provide the connection and a strongly-typed interface to allow one to develop applictions that use the debugger protocol for fun and profit.
Why use the Chrome Debugger Protocol?
Some use cases for using the Chrome Debugger Protocol to automate Chrome are:
- Information Gathering - Use the web as a data source by creating structured data out of unstructured data
- Testing - Ensure sites are up and behave according to a pre-determined notion
- Automation - Do things like perform automated password resets, enter online contests, notify when sites change, etc...
- Artifact Generation - Use Chrome as a tool to generate PDFs, Images, json/xml/txt/csv/... from web and locally supplied data sources
The protocol itself is defined by Google via a JSON-based definition of a websocket interface, allowing for tools to generate the required interface implementation in the language of choice.
A number of other Browsers have started implementing the Chrome Debugger Protocol, including Edge, Safari (iOS), Firefox and possibly more, which makes developing a common interface to one of these browsers highly attractive.
Why a generator instead of a concrete implementation or library?
The protocol is changing rapidly and some have varying opinions on what the wrapper library should look like, by rerunning this generator one can easily update a wrapper to the latest protocol definition.
Also, while this project has a prebuilt template targeting .Net, it's also possible to customize the template to generate wrappers in other languages.
If you just don't care and want a chrome developer tools runtime library for C#/dotnet, grab the runtime library from this repository.
The runtime library is also available on nuget:
- .Net Core 2.1.0
Clone the project and run ChromeDevToolsGeneratorCLI
$ git clone https://github.com/BaristaLabs/chrome-dev-tools $ cd chrome-dev-tools\src\ChromeDevToolsGeneratorCLI $ dotnet run ChromeDevToolsGeneratorCLI -o "C:\\temp\\ChromeDevToolsRuntime"
In C:\Temp\ChromeDevToolsRuntime you'll have a .csproj that you can build directly or include as part of a solution.
See http://github.com/BaristaLabs/chrome-dev-tools-sample for a sample of generated output usage.
Command line options:
||Specifies the path to where the .csproj and code files will be generated (Usually contained in a subfolder of a solution that will utilize it) [Default: ./OutputProtocol]|
||Indicates to delete the output path before files are generated (for a clean output) [Default: false]|
||-p||When specified, indicates the path to a JSON file that contains the chrome debugging protocol definition to use. If not found, one will be generated using the current installed version of chrome. [Default: chrome-debugging-protocol.json]|
||-s||When specified indicates the path to a JSON file that contains code generation settings. [Default: ./Templates/settings.json]|
The output that is generated is highly configurable through the use of mustache/handlebars templates.
The base set of templates is included in /chrome-dev-tools/src/ChromeDevToolsGeneratorCLI/Templates and can be customized to your liking by editing the .hbs files (Handlebars-based templates) and modifying settings.json.
Unfortunately, MS has not decided to go forward with .csproj support in VS2015, so VS2017 or higher is required.
Feel free to submit pull requests
General Application Flow
A general rundown of the flow of this generator is the following:
- Parse command line options and specified settings file.
- If a protocol definition file is not found, launches a local instance of Chrome
- Gets the commit/version of the launched instance of Chrome
- Gets the corresponding Chrome Debugger Protocol definition from Google/Chromium sources
- Validates the protocol definition against the schema of the generator classes (to ensure the protocol definition schema hasn't evolved - which would require improving this project)
- In memory, using the handlebars-based templates, generates .cs files
- Perform a pre-scan of all Types, Commands and Events.
- For each include file specified in settings.json, generate the corresponding file.
- For each Domain, generate files for each types, events and commands using the corresponding template defined in settings.
- Output to disk each generated file.