Skip to content

jefersonsv/ChromeRemoteSharp

Repository files navigation

ChromeRemoteSharp

License NuGet version (ChromeRemoteSharp)

Low level implementation of Chrome DevTools Protocol. This project implements the last version of protocol (https://chromedevtools.github.io/devtools-protocol/tot/)

1.1. Table of contents

1.2. Drivers

The library has two drivers

  • RawDriver. Send and receive custom commands using ws protocol
  • LowLevelDriver. Use any available command of domain list

1.3. Domains available

  • Accessibility
  • ​Animation
  • ​ApplicationCache
  • ​Audits
  • ​Browser
  • ​CacheStorage
  • ​Console
  • ​CSS
  • ​Database
  • ​Debugger
  • ​DeviceOrientation
  • ​DOM
  • ​DOMDebugger
  • ​DOMSnapshot
  • ​DOMStorage
  • ​Emulation
  • ​HeadlessExperimental
  • ​HeapProfiler
  • ​IndexedDB
  • ​Input
  • ​Inspector
  • ​IO
  • ​LayerTree
  • ​Log
  • ​Memory
  • ​Network
  • ​Overlay
  • ​Page
  • ​Performance
  • ​Profiler
  • ​Runtime
  • ​Schema
  • ​Security
  • ​ServiceWorker
  • ​Storage
  • ​SystemInfo
  • ​Target
  • ​Tethering
  • ​Tracing

1.4. Sample

Helper.KillAllChromeInstances(); // kill all opened instances of google chrome
Helper.StartChromeDevTools(); // start new chrome browser instance point to http://localhost:9222

if (!await Helper.CheckWebSocketAsync()) // check if remote debugging url it's available
    Helper.StartChromeHeadless(); // start a headless instance of google chrome

var url = await Helper.FirstWebSocketDebuggerUrlAsync(); // get the first ws remote url
driver = new LowLevelDriver(url); // instance driver

// navigate
await driver.Page.NavigateAsync("https://www.msn.com"); // navigate
System.Threading.Thread.Sleep(2000);

// screenshot
var screenShotJson = await driver.Page.CaptureScreenshotAsync(); // capture image and return base64 json image
Console.WriteLine(screenShotJson);

// get version
Console.WriteLine(await driver.Browser.GetVersionAsync()); // get browser version

// get browser command line
Console.WriteLine(await driver.Browser.GetBrowserCommandLineAsync()); // get all command lines of headless instance

// page cookies
Console.WriteLine(await driver.Page.GetCookiesAsync()); // get all cookies

// get document
var docJson = await driver.Dom.GetDocumentAsync(); // get document in raw format devtools protocol
var nodeId = docJson["root"]["nodeId"].ToObject<int>();

// get html
var htmlJson = await driver.Dom.GetOuterHTMLAsync(nodeId); // get source code of page
var html = htmlJson["outerHTML"].ToString();
Console.WriteLine(html);

About

Low level implementation of Chrome DevTools Protocol

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages