# puppeteer-sharp **Repository Path**: workingbird/puppeteer-sharp ## Basic Information - **Project Name**: puppeteer-sharp - **Description**: 一个浏览器自动化操作的.net开源库 - **Primary Language**: C# - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-12-10 - **Last Updated**: 2023-12-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Puppeteer Sharp [][NugetUrl] [][BuildUrl] [][BuildDemoUrl] [][CodeFactorUrl] [][Backers] [NugetUrl]: https://www.nuget.org/packages/PuppeteerSharp/ [BuildUrl]: https://github.com/hardkoded/puppeteer-sharp/actions/workflows/dotnet.yml [BuildDemoUrl]: https://github.com/hardkoded/puppeteer-sharp/actions/workflows/demo.yml [CodeFactorUrl]: https://www.codefactor.io/repository/github/hardkoded/puppeteer-sharp [Backers]: https://opencollective.com/hardkoded-projects Puppeteer Sharp is a .NET port of the official [Node.JS Puppeteer API](https://github.com/puppeteer/puppeteer). ## Useful links * [API Documentation](http://www.puppeteersharp.com/api/index.html) * Slack channel [#puppeteer-sharp](https://www.hardkoded.com/goto/pptr-slack) * [StackOverflow](https://stackoverflow.com/search?q=puppeteer-sharp) * [Issues](https://github.com/hardkoded/puppeteer-sharp/issues?utf8=%E2%9C%93&q=is%3Aissue) * [Blog](https://www.hardkoded.com/) ## Prerequisites * As Puppeteer-Sharp is a NetStandard 2.0 library, the minimum platform versions are .NET Framework 4.6.1 and .NET Core 2.0. [Read more](https://docs.microsoft.com/en-us/dotnet/standard/net-standard). * If you have issues running Chrome on Linux, the Puppeteer repo has a [great troubleshooting guide](https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md). * X-server is required on Linux. ## How to Contribute and Provide Feedback Some of the best ways to contribute are to try things out file bugs and fix issues. If you have an issue or a question: * Ask a question on [Stack Overflow](https://stackoverflow.com/search?q=puppeteer-sharp). * File a [new issue](https://github.com/hardkoded/puppeteer-sharp/issues/new). ## Contributing Guide See [this document](https://github.com/hardkoded/puppeteer-sharp/blob/master/CONTRIBUTING.md) for information on how to contribute. ## Usage ## Take screenshots ```cs using var browserFetcher = new BrowserFetcher(); await browserFetcher.DownloadAsync(); await using var browser = await Puppeteer.LaunchAsync( new LaunchOptions { Headless = true }); await using var page = await browser.NewPageAsync(); await page.GoToAsync("http://www.google.com"); await page.ScreenshotAsync(outputFile); ``` snippet source | anchor You can also change the view port before generating the screenshot ```cs await Page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 }); ``` snippet source | anchor ### Generate PDF files ```cs using var browserFetcher = new BrowserFetcher(); await browserFetcher.DownloadAsync(); await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions {Headless = true}); await using var page = await browser.NewPageAsync(); await page.GoToAsync("http://www.google.com"); // In case of fonts being loaded from a CDN, use WaitUntilNavigation.Networkidle0 as a second param. await page.EvaluateExpressionHandleAsync("document.fonts.ready"); // Wait for fonts to be loaded. Omitting this might result in no text rendered in pdf. await page.PdfAsync(outputFile); ``` snippet source | anchor ### Inject HTML ```cs await using var page = await browser.NewPageAsync(); await page.SetContentAsync("