2020-06-29 13:58:06 +10:00
|
|
|
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 IWebBrowser chromiumWebBrowser)
|
|
|
|
|
{
|
|
|
|
|
//Make sure to dispose of our observer registration when done
|
2021-08-26 15:57:56 +10:00
|
|
|
//If you need to make multiple calls then reuse the devtools client
|
|
|
|
|
//and Dispose when done.
|
|
|
|
|
using (var devToolsClient = chromiumWebBrowser.GetDevToolsClient())
|
2020-06-29 13:58:06 +10:00
|
|
|
{
|
2021-08-26 15:57:56 +10:00
|
|
|
var result = await devToolsClient.Page.CaptureScreenshotAsync();
|
2020-06-29 13:58:06 +10:00
|
|
|
|
2021-08-26 15:57:56 +10:00
|
|
|
return result.Data;
|
2020-06-29 13:58:06 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|