Skip to content

Releases: hardkoded/puppeteer-sharp

v0.8 ElementHandle Support

28 May 12:06
e0e07a6
Compare
Choose a tag to compare
  • 0.8.0: ElementHandle
    • Features:
      • ElementHandle support
    • API Changes
      • Page.SetViewport renamed to Page.SetViewportAsync
      • JSHandle.AsElement was dropped. Use JSHandle as ElementHandle instead
      • JSHandle.JsonValue renamed to JSHandle.JsonValueAsync
    • New APIs
      • Page.WaitForNavigationAsync
      • ElementHandle.QuerySelectorAsync
      • ElementHandle.QuerySelectorAllAsync
      • ElementHandle.XPathAsync
      • ElementHandle.ScreenshotAsync
      • ElementHandle.ScreenshotStreamAsync
      • ElementHandle.ClickAsync
      • ElementHandle.HoverAsync
      • ElementHandle.BoundingBoxAsync
      • JSHandle.GetPropertyAsync
      • JSHandle.GetPropertiesAsync

v0.7 Page Improvements

09 May 00:03
de31886
Compare
Choose a tag to compare

We are shipping Puppeteer Sharp v0.7 with many cool new features: Element selectors and evaluation over elements. But our big challenge on v0.7 was one of the hard things in computer science: Naming Things.

Puppeteer has these 5 cool functions:

  • $(selector): It calls document.querySelector and returns an ElementHandle.
  • $$(selector): It calls document.querySelectorAll and returns an ElementHandle array.
  • $eval(selector, function): It calls document.querySelector and executes a function passing the element as an argument.
  • $$eval(selector, function): It calls document.querySelectorAll and executes a function passing the element array as an argument.
  • $x(xpathExpression): It calls document.evaluate and returns an ElementHandle array.

What do all these methods have in common? Hint: You can solve this using a string.Substring().
Yes, you guessed it right! They all have that $ symbol. And guess what? exactly, we can't name a method $ in C#.

So, in order to give these functions a clear and "csharpy" name, we decided to call them in this way:

  • page.$(selector) => page.QuerySelectorAsync(selector)
  • page.$$(selector) => page.QuerySelectorAllAsync(selector)
  • page.$eval(selector, function) => page.QuerySelectorAsync(selector).EvaluateFunctionAsync(function)
  • page.$$eval(selector, function) => page.QuerySelectorAllHandleAsync(selector).EvaluateFunctionAsync(function)
  • page.$(selector) => page.XPathAsync(selector)

These methods may be more verbose, but this naming convention makes them clearer and hopefully, easier to learn.

This is the complete list of new APIs we implemented in this version:
- Page.XPathAsync
- Page.QuerySelectorAsync
- Page.QuerySelectorAllAsync
- Page.QuerySelectorAllHandleAsync
- Page.SelectAsync
- Page.ExposeFunctionAsync
- Page.EvaluateOnNewDocumentAsync
- Page.AddScriptTagAsync
- Page.AddStyleTagAsync
- Page.PageError
- JSHandle.EvaluateFunctionAsync
- ElementHandle.EvaluateFunctionAsync

v0.6 Input simulation

04 May 21:50
d43f293
Compare
Choose a tag to compare
  • Features

    • Input simulation
  • New APIs

    • ElementHandle.HoverAsync
    • ElementHandle.ClickAsync
    • ElementHandle.UploadFileAsync
    • ElementHandle.TapAsync
    • ElementHandle.FocusAsync
    • ElementHandle.TypeAsync
    • ElementHandle.PressAsync
    • Keyboard.DownAsync
    • Keyboard.UpAsync
    • Keyboard.SendCharacterAsync
    • Keyboard.TypeAsync
    • Keyboard.PressAsync
    • Mouse.MoveAsync
    • Mouse.ClickAsync
    • Mouse.DownAsync
    • Mouse.UpAsync
    • TouchScreen.TapAsync
    • Page.ClickAsync
    • Page.HoverAsync
    • Page.FocusAsync
    • Page.TypeAsync

v0.5 Frames, Network Events and Tracing

30 Apr 12:50
53a9001
Compare
Choose a tag to compare

Features

  • Network Events
  • Tracing
  • Frames

Fixes

  • Fixed Browse.Close on Azure Functions

New APIs

  • Request.ContinueAsync
  • Request.RespondAsync
  • Request.AbortAsync
  • Response.BufferAsync
  • Response.TextAsync
  • Response.JsonAsync
  • Session.TracingComplete
  • Session.DetachAsync
  • Page.Tracing.StartAsync
  • Page.Tracing.StopAsync
  • Page.EvaluateOnNewDocumentAsync
  • Page.Coverage
  • Page.WaitForFunctionAsync
  • Browser.Targets
  • Browser.PagesAsync
  • Frame.WaitForSelectorAsync
  • Target.CreateCDPSession

v0.4 Pages!

21 Apr 10:41
Compare
Choose a tag to compare

v0.4 includes more than 25 Page APIs such as:
Full Page.GoToAsync/ReloadAsync support
Emulate/EmulateMedia/SetViewport/SetUserAgent
Get and Set cookies
SetContent
Evaluate javascript functions and expressions
WaitFor expressions

await page.GoToAsync("http://www.mysite.com");

//Do you need to wait for your javascript framework to load content?
//You got it!
await page.WaitForSelectorAsync("div.main-content");

///Emulate media print? Sure!
await Page.EmulateMediaAsync(MediaType.Print);

//Or an iPhone?
await Page.EmulateAsync(iPhone);

///Inject a cookie
await page.SetCookieAsync(new CookieParam
{
    Name = "gridcookie",
    Value = "GRID",
    Path = "/grid.html"
});

//Or even HTML!
await page.SetContentAsync("<div>hello</div>");

//How about executing javascript functions?
await page.EvaluateFunctionAsync<int>("(a) => 5 + a", myValueForA);

Extra goodies

We added support for remote browser connections. This will allow Puppeteer Sharp to be used in docker containers or Azure Functions.

var options = new ConnectOptions()
{
    BrowserWSEndpoint = $"wss://browserproviderwhomightwanttosponsortheproject.io"
};

var url = "https://www.google.com/";

using (var browser = await PuppeteerSharp.Puppeteer.ConnectAsync(options))
{
    using (var page = await browser.NewPageAsync())
    {
        await page.GoToAsync(url);
        await page.PdfAsync("wot.pdf");
    }
}

These are the new available APIs:

- Page.GoToAsync
- Page.ReloadAsync
- Page.EmulateMediaAsync
- Page.SetViewport
- Page.EmulateAsync
- Page.SetUserAgentAsync
- Page.MetricsAsync
- Page.Dialog
- Page.Error
- Page.RequestCreated
- Page.GetCookiesAsync
- Page.SetCookieAsync
- Page.SetExtraHttpHeadersAsync
- Page.AuthenticateAsync
- Page.SetJavaScriptEnabledAsync
- Page.SetContentAsync
- Page.EvaluateFunctionAsync
- Page.EvaluateExpressionAsync
- Page.GetTitleAsync
- Page.SetOfflineModeAsync
- Page.CloseAsync
- Page.Console
- Page.WaitForTimeoutAsync
- Page.WaitForFunctionAsync
- Puppeteer.ConnectAsync
- Browser.Disconnect();

Bug Fixes

29 Mar 11:13
Compare
Choose a tag to compare

Several real-world bug fixes.

v0.3 Launcher Improvements

18 Mar 15:23
d98f9c6
Compare
Choose a tag to compare
  • Fixed Process leak.
  • User data dir support.
var userDataDir = Launcher.GetTemporaryDirectory();
var options = TestConstants.DefaultBrowserOptions();
options.UserDataDir = userDataDir;

var launcher = new Launcher();
var browser = await launcher.LaunchAsync(options, TestConstants.ChromiumRevision);
  • Browser and Page now implements IDisposable.
var options = TestConstants.DefaultBrowserOptions();

using (var browser = await PuppeteerSharp.Puppeteer.LaunchAsync(options, TestConstants.ChromiumRevision))
using (var page = await browser.NewPageAsync())
{
    var response = await page.GoToAsync("https://www.google.com");
}

v0.1 Screenshots and PDF generation

01 Mar 11:48
e7f4ff4
Compare
Choose a tag to compare

The first milestone on the roadmap is completed.

PDF support

You can export any page to PDF file.

var browser = await PuppeteerSharp.Puppeteer.LaunchAsync(options, chromiumRevision);
var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.google.com");
await page.PdfAsync(outputFile);

You can also get a PDF in a stream.

var browser = await PuppeteerSharp.Puppeteer.LaunchAsync(options, chromiumRevision);
var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.google.com");
var stream = await page.PdfStreamAsync();
await UploadToAzure(stream);

PdfAsync supports the following options:

  • Scale <decimal> Scale of the webpage rendering. Defaults to 1.
  • DisplayHeaderFooter <bool> Display header and footer. Defaults to false.
  • HeaderTemplate <string> HTML template for the print header.
  • FooterTemplate <string> HTML template for the print footer. Should use the same format as the HeaderTemplate.
  • PrintBackground <bool> Print background graphics. Defaults to false.
  • Landscape <boolean> Paper orientation. Defaults to false.
  • PageRanges <string> Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
  • Format <string> Paper format. If set, takes priority over width or height options. Defaults to 'Letter'.
  • Width <string> Paper width, accepts values labeled with units.
  • Height <string> Paper height, accepts values labeled with units.
  • Margin <MarginOptions> Paper margins, defaults to none.
  • Top <string> Top margin, accepts values labeled with units.
  • Right <string> Right margin, accepts values labeled with units.
  • Bottom <string> Bottom margin accepts values labeled with units.
  • Left <string> Left margin, accepts values labeled with units.

Documentation adapted from the original Puppeteer repo.

Screenshot support

You can take a screenshot of a page (the visible part based on the viewport), a full page or a part of it.

var browser = await PuppeteerSharp.Puppeteer.LaunchAsync(options, chromiumRevision);
var page = await browser.NewPageAsync();

await page.SetViewport(new ViewPortOptions
    {
        Width = 500,
        Height = 500
    });

await page.GoToAsync("https://www.google.com");
await page.ScreenshotAsync(outputFile);

You can also use ScreenshotStreamAsync to get a stream instead of a file.

The ScreenshotAsync method supports the following options:

  • Type <string> Specify screenshot type, can be either jpeg or png. Defaults to 'png'.
  • Quality <decimal?> The quality of the image, between 0-100. Not applicable to png images.
  • FullPage <bool> When true, takes a screenshot of the full scrollable page. Defaults to false.
  • Clip <Clip> An object which specifies clipping region of the page. Should have the following fields:
    • X <int> x-coordinate of top-left corner of clip area.
    • Y <int> y-coordinate of top-left corner of clip area.
    • Width <int> width of clipping area.
    • Height <number> height of clipping area.
  • OmitBackground <bool> Hides default white background and allows capturing screenshots with transparency. Defaults to false.

Documentation adapted from the original Puppeteer repo.