forked fromhardkoded/puppeteer-sharp
- Notifications
You must be signed in to change notification settings - Fork0
andrewgee/puppeteer-sharp
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Puppeteer Sharp is a .NET port of the officialNode.JS Puppeteer API.
PuppeteerSharp now supports AOT compilation! Check thePuppeteerSharp 19 release notes!.
- Puppeteer-Sharp comes in two flavors: a NetStandard 2.0 library for .NET Framework 4.6.1 and .NET Core 2.0 or greater and a .NET 8 version.
- If you have issues running Chrome on Linux, the Puppeteer repo has agreat troubleshooting guide.
- X-server is required on Linux.
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 onStack Overflow.
- File anew issue.
Seethis document for information on how to contribute.
varbrowserFetcher=newBrowserFetcher();awaitbrowserFetcher.DownloadAsync();awaitusingvarbrowser=awaitPuppeteer.LaunchAsync(newLaunchOptions{Headless=true});awaitusingvarpage=awaitbrowser.NewPageAsync();awaitpage.GoToAsync("http://www.google.com");awaitpage.ScreenshotAsync(outputFile);
You can also change the view port before generating the screenshot
awaitPage.SetViewportAsync(newViewPortOptions{Width=500,Height=500});
varbrowserFetcher=newBrowserFetcher();awaitbrowserFetcher.DownloadAsync();awaitusingvarbrowser=awaitPuppeteer.LaunchAsync(newLaunchOptions{Headless=true});awaitusingvarpage=awaitbrowser.NewPageAsync();awaitpage.GoToAsync("http://www.google.com");// In case of fonts being loaded from a CDN, use WaitUntilNavigation.Networkidle0 as a second param.awaitpage.EvaluateExpressionHandleAsync("document.fonts.ready");// Wait for fonts to be loaded. Omitting this might result in no text rendered in pdf.awaitpage.PdfAsync(outputFile);
awaitusingvarpage=awaitbrowser.NewPageAsync();awaitpage.SetContentAsync("<div>My Receipt</div>");varresult=awaitpage.GetContentAsync();
awaitusingvarpage=awaitbrowser.NewPageAsync();varseven=awaitpage.EvaluateExpressionAsync<int>("4 + 3");varsomeObject=awaitpage.EvaluateFunctionAsync<JsonElement>("(value) => ({a: value})",5);Console.WriteLine(someObject.GetProperty("a").GetString());
using(varpage=awaitbrowser.NewPageAsync()){awaitpage.GoToAsync("http://www.spapage.com");awaitpage.WaitForSelectorAsync("div.main-content") await page.PdfAsync(outputFile));}
using(varpage=awaitbrowser.NewPageAsync()){awaitpage.GoToAsync("http://www.spapage.com");varwatchDog=page.WaitForFunctionAsync("()=> window.innerWidth < 100");awaitpage.SetViewportAsync(newViewPortOptions{Width=50,Height=50});awaitwatchDog;}
varoptions=newConnectOptions(){BrowserWSEndpoint=$"wss://www.externalbrowser.io?token={apikey}"};varurl="https://www.google.com/";using(varbrowser=awaitPuppeteerSharp.Puppeteer.ConnectAsync(options)){using(varpage=awaitbrowser.NewPageAsync()){awaitpage.GoToAsync(url);awaitpage.PdfAsync("wot.pdf");}}
A massive thanks toJetBrains for a community Resharper and Rider license to use on this project.
And a huge thanks to everyone who sponsors this project throughGithub sponsors:


About
Headless Chrome .NET API
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Languages
- C#89.4%
- JavaScript5.6%
- HTML1.9%
- TypeScript1.8%
- Other1.3%
