Code Monkey home page Code Monkey logo

chrome-dev-tools-generator's Introduction

chrome-dev-tools-generator

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
  • Debugging JavaScript - When implementing custom editors, allow for rich debugging of executing javascript, including setting breakpoints, getting immediate values when paused, stepping through and so forth.

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:

https://www.nuget.org/packages/BaristaLabs.ChromeDevTools.Runtime/

Requirements:

  • Chrome
  • .Net Core 2.1.0

Usage:

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:

Option Short Description
-output-path <path> -o 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]
-force -f Indicates to delete the output path before files are generated (for a clean output) [Default: false]
-protocol-path <path> -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]
-settings <path> -s When specified indicates the path to a JSON file that contains code generation settings. [Default: ./Templates/settings.json]

Customizing output:

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.

Development

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:

  1. Parse command line options and specified settings file.
  2. If a protocol definition file is not found, launches a local instance of Chrome
    1. Gets the commit/version of the launched instance of Chrome
    2. Gets the corresponding Chrome Debugger Protocol definition from Google/Chromium sources
  3. 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)
  4. In memory, using the handlebars-based templates, generates .cs files
    1. Perform a pre-scan of all Types, Commands and Events.
    2. For each include file specified in settings.json, generate the corresponding file.
    3. For each Domain, generate files for each types, events and commands using the corresponding template defined in settings.
  5. Output to disk each generated file.

Thanks

Thanks to Handlebars.Net, WebSocket4Net, NJsonSchema, Humanizer

chrome-dev-tools-generator's People

Contributors

bartizan avatar oceanswave avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.