-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathDevToolsExtensions.cs
More file actions
28 lines (26 loc) · 1.06 KB
/
DevToolsExtensions.cs
File metadata and controls
28 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Threading.Tasks;
namespace CefSharp.Example.DevTools
{
public static class DevToolsExtensions
{
/// <summary>
/// Calls Page.captureScreenshot without any optional params
/// (Results in PNG image of default viewport)
/// https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-captureScreenshot
/// </summary>
/// <param name="browser">the ChromiumWebBrowser</param>
/// <returns>png encoded image as byte[]</returns>
public static async Task<byte[]> CaptureScreenShotAsPng(this IChromiumWebBrowserBase chromiumWebBrowser)
{
//Make sure to dispose of our observer registration when done
//If you need to make multiple calls then reuse the devtools client
//and Dispose when done.
using (var devToolsClient = chromiumWebBrowser.GetDevToolsClient())
{
var result = await devToolsClient.Page.CaptureScreenshotAsync();
return result.Data;
}
}
}
}