Skip to content

Enhancement - Add DevToolsClient (Direct Devtools Protocol) #3165

Closed

Description

@amaitland

Follow up to #3158

A nicer API build on top of the CEF API to make it easier to send/receive messages from DevTools.

The API is generated on top of the DevTools protocol to create a set of model classes to simplify executing DevTools commands.

  • Add Strongly typed DevTools Domain classes
  • Deprecated methods are not generated
  • Only methods (no strongly typed events yet, a new issue should be created for that.)

The CefSharp.DevTools.DevToolsClient class is the primary method of accessing the different domains. Each DevTools Domain has it's own namespace that contains enums and strongly typed return classes.

Network Domain is part of the CefSharp.DevTools.Network namespace. The methods are accessibly though the DevToolsClient class.

Some basic examples look like (extract from the unit tests)

using (var browser = new ChromiumWebBrowser("www.google.com"))
{
	await browser.WaitForInitialLoadAsync();

	using (var devToolsClient = browser.GetDevToolsClient())
	{
		var response = await devToolsClient.Network.SetCookieAsync(name, value, domain: domain, sameSite: sameSite);
	}
}

using (var browser = new ChromiumWebBrowser("www.google.com"))
{
	await browser.WaitForInitialLoadAsync();

	using (var devToolsClient = browser.GetDevToolsClient())
	{
		var response = await devToolsClient.Browser.GetVersionAsync();
		var jsVersion = response.JsVersion;
		var revision = response.Revision;
	}
}

Activity

  1. added this to the 85.4.x milestone on Jul 2, 2020
  2. changed the title [-]Enhancement - Add DevToolsManager (Direct Devtools Protocol)[/-] [+]Enhancement - Add DevToolsClient (Direct Devtools Protocol)[/+] on Aug 19, 2020
  3. added a commit that references this issue on Aug 26, 2020
  4. self-assigned this
    on Sep 16, 2020
  5. linked a pull request that will close this issueEnhancement - Add DevToolsClient #3229on Oct 6, 2020
  6. amaitland commented on Oct 6, 2020

    @amaitland
    MemberAuthor

    CEF doesn't support every aspect of DevTools, the generated API is based of the protocol definition which can be downloaded from the browser at runtime and is used for code generation. If you find a method that CEF doesn't support please post here and I will at some point update the generator to remove those methods.

    TO BE REMOVED:

    • Page.printToPdf is only accessibly when using Headless Chromium and not supported.
  7. amaitland commented on Oct 6, 2020

    @amaitland
    MemberAuthor

    Developing features like this takes considerably time and effort, if you use CefSharp in a commercial application then please consider sponsoring me https://github.com/cefsharp/CefSharp#financial-support

  8. amaitland commented on Oct 26, 2020

    @amaitland
    MemberAuthor

    Example of changing User Agent at runtime at https://stackoverflow.com/a/64543667/4583726

  9. totti240282 commented on Oct 29, 2020

    @totti240282

    With GetDevToolsClient is possible capture traffic in network tab ?

  10. amaitland commented on Oct 29, 2020

    @amaitland
    MemberAuthor

    Yes. You can subscribe to http://cefsharp.github.io/api/85.3.x/html/F_CefSharp_DevTools_DevToolsClient_DevToolsEvent.htm

    As per #3158 (comment) you must call enable/disable for the specific domain.

  11. amaitland commented on Nov 17, 2020

    @amaitland
    MemberAuthor

    For .Net core it might be worth generating some nicer code in relation to the JSON parsing involved here. Using https://docs.microsoft.com/en-us/dotnet/api/system.text.json?view=net-5.0 should be feasible.

  12. amaitland commented on Jan 5, 2021

    @amaitland
    MemberAuthor

    See https://gist.github.com/amaitland/eabb42a191c4943610f2407196b0e03a for an example of changing tge user agent at runtime using the DevTools protocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions