Coder Social home page Coder Social logo

puppeteer-sharp's Introduction

Puppeteer Sharp

NuGet Build status

Puppeteer Sharp is a .NET port of the official Node.JS Puppeteer API.

Usage

Take screenshots

await Downloader.CreateDefault().DownloadRevisionAsync(chromiumRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Headless = true
}, chromiumRevision);
var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com");
await page.ScreenshotAsync(outputFile));

You can also change the view port before generating the screenshot

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

Generate PDF files

await Downloader.CreateDefault().DownloadRevisionAsync(chromiumRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Headless = true
}, chromiumRevision);
var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com");
await page.PdfAsync(outputFile));

Inject HTML

using(var page = await Browser.NewPageAsync())
{
    await page.SetContentAsync("<div>My Receipt</div>");
    var result = await page.GetContentAsync();
    await page.PdfAsync(outputFile);
    SaveHtmlToDB(result);
}

Evaluate Javascript

using (var page = await Browser.NewPageAsync())
{
    var seven = await page.EvaluateFunctionAsync<int>(4 + 3);
    var someObject = await page.EvaluateFunctionAsync<dynamic>("(value) => ({a: value})", 5);
    Console.WriteLine(someObject.a);
}

Wait For Selector

using (var page = await Browser.NewPageAsync())
{
    await page.GoToAsync("http://www.spapage.com");
    await page.WaitForSelectorAsync("div.main-content")
    await page.PdfAsync(outputFile));
}

Wait For Function

using (var page = await Browser.NewPageAsync())
{
    await page.GoToAsync("http://www.spapage.com");
    var watchDog = page.WaitForFunctionAsync("window.innerWidth < 100");
    await Page.SetViewport(new ViewPortOptions { Width = 50, Height = 50 });
    await watchDog;
}

Connect to a remote browser

var options = new ConnectOptions()
{
    BrowserWSEndpoint = $"wss://www.externalbrowser.io?token={apikey}"
};

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");
    }
}

Monthly reports

Roadmap

Getting to all the 523 tests Puppeteer has, will be a long and fun journey. So, this will be the roadmap for Puppeteer Sharp 1.0:

0.1 First Minimum Viable Product

The first 0.1 will include:

  • Browser download
  • Basic browser operations: create a browser, a page and navigate a page.
  • Take screenshots.
  • Print to PDF.

0.2 Repository cleanup

This version won't include a new version. It will be about improving the repository:

  • Setup CI.
  • Create basic documentation (Readme, contributing, code of conduct).

0.3 Puppeteer

It will implement all Puppeteer related tests.

0.4 Page

It will implement all Page tests except the ones testing the evaluate method. As this will be quite a big version, I think we will publish many 0.3.X versions before 0.4.

0.5 Frames

It will implement all Frame tests.

0.6 Simple interactions

It will implement all tests related to setting values to inputs and clicking on elements.

0.7 Page Improvements

It will implement all missing Page tests.

0.8 Element Handle and JS Handle

It will implement all tests releated to Element handles and JS handles.

0.X Intermediate versions

At this point, We will have implemented most features, except the ones which are javascript related. I believe there will be many versions between 0.6 and 1.0.

1.0 Puppeteer the world!

The 1.0 version will have all (or most) Puppeteer features implemented. I don't know if we'll be able to cover 100% of Puppeteer features, due to differences between both technologies, but we'll do our best.

Progress

  • Tests on Google's Puppeteer: 405.
  • Tests on Puppeteer Sharp: 171.
  • Passing tests: 168.

puppeteer-sharp's People

Contributors

kblok avatar meir017 avatar cdroulers avatar phenx avatar

Watchers

John avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.