Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Dec 20, 2023
1 parent 017176b commit 53d5bda
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/on-push-do-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Run MarkdownSnippets
run: |
dotnet tool install --global MarkdownSnippets.Tool
mdsnippets ${GITHUB_WORKSPACE}
mdsnippets ${GITHUB_WORKSPACE} --url-prefix https://github.com/hardkoded/puppeteer-sharp/blob/master
shell: bash
- name: Push changes
run: |
Expand All @@ -19,4 +19,4 @@ jobs:
remote="https://${GITHUB_ACTOR}:${{secrets.GITHUB_TOKEN}}@github.com/${GITHUB_REPOSITORY}.git"
branch="${GITHUB_REF:11}"
git push "${remote}" ${branch} || echo "nothing to push"
shell: bash
shell: bash
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ await using var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com");
await page.ScreenshotAsync(outputFile);
```
<sup><a href='/lib/PuppeteerSharp.Tests/ScreenshotTests/PageScreenshotTests.cs#L61-L69' title='Snippet source file'>snippet source</a> | <a href='#snippet-screenshotasync' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/ScreenshotTests/PageScreenshotTests.cs#L61-L69' title='Snippet source file'>snippet source</a> | <a href='#snippet-screenshotasync' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

You can also change the view port before generating the screenshot
Expand All @@ -70,7 +70,7 @@ await Page.SetViewportAsync(new ViewPortOptions
Height = 500
});
```
<sup><a href='/lib/PuppeteerSharp.Tests/ScreenshotTests/ElementHandleScreenshotTests.cs#L19-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-setviewportasync' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/ScreenshotTests/ElementHandleScreenshotTests.cs#L19-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-setviewportasync' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Generate PDF files
Expand All @@ -86,7 +86,7 @@ await page.GoToAsync("http://www.google.com"); // In case of fonts being loaded
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);
```
<sup><a href='/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs#L28-L38' title='Snippet source file'>snippet source</a> | <a href='#snippet-pdfasync' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs#L28-L38' title='Snippet source file'>snippet source</a> | <a href='#snippet-pdfasync' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Inject HTML
Expand All @@ -98,7 +98,7 @@ await using var page = await browser.NewPageAsync();
await page.SetContentAsync("<div>My Receipt</div>");
var result = await page.GetContentAsync();
```
<sup><a href='/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs#L19-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-setcontentasync' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs#L19-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-setcontentasync' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Evaluate Javascript
Expand All @@ -111,7 +111,7 @@ var seven = await page.EvaluateExpressionAsync<int>("4 + 3");
var someObject = await page.EvaluateFunctionAsync<dynamic>("(value) => ({a: value})", 5);
Console.WriteLine(someObject.a);
```
<sup><a href='/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorEvalTests.cs#L17-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-evaluate' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorEvalTests.cs#L17-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-evaluate' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Wait For Selector
Expand Down
18 changes: 12 additions & 6 deletions docfx_project/examples/DownloadFetcher.Download.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Thank to [Google for testing](https://developer.chrome.com/blog/chrome-for-testi
You will find the available versions [here](https://googlechromelabs.github.io/chrome-for-testing/known-good-versions.json).
Once you have the version you want, you can download it using the `BrowserFetcher` class.

```cs
<!-- snippet: CustomVersionsExample -->
<a id='snippet-customversionsexample'></a>
```cs
Console.WriteLine("Downloading browsers");

Expand All @@ -21,9 +24,9 @@ var chrome119 = await browserFetcher.DownloadAsync("119.0.5997.0");

Console.WriteLine("Navigating");
await using (var browser = await Puppeteer.LaunchAsync(new()
{
ExecutablePath = chrome118.GetExecutablePath(),
}))
{
ExecutablePath = chrome118.GetExecutablePath(),
}))
{
await using var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.whatismybrowser.com/");
Expand All @@ -35,9 +38,9 @@ await using (var browser = await Puppeteer.LaunchAsync(new()
}

await using (var browser = await Puppeteer.LaunchAsync(new()
{
ExecutablePath = chrome119.GetExecutablePath(),
}))
{
ExecutablePath = chrome119.GetExecutablePath(),
}))
{
await using var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.whatismybrowser.com/");
Expand All @@ -48,3 +51,6 @@ await using (var browser = await Puppeteer.LaunchAsync(new()
Console.WriteLine("Export completed");
}
```
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/Browsers/Chrome/ChromeDataTests.cs#L15-L50' title='Snippet source file'>snippet source</a> | <a href='#snippet-customversionsexample' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
```
2 changes: 2 additions & 0 deletions docfx_project/examples/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
href: Page.WaitForFunctionAsync.md
- name: How to log network requests
href: Page.Request.md
- name: How to download an specific browser
href: DownloadFetcher.Download.md
- name: Advanced
items:
- name: How to log CDP communication
Expand Down
40 changes: 40 additions & 0 deletions lib/PuppeteerSharp.Tests/Browsers/Chrome/ChromeDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,46 @@ namespace PuppeteerSharp.Tests.Browsers.Chrome
{
public class ChromeDataTests
{
public async Task Usage()
{
#region CustomVersionsExample
Console.WriteLine("Downloading browsers");

using var browserFetcher = new BrowserFetcher(SupportedBrowser.Chrome);
var chrome118 = await browserFetcher.DownloadAsync("118.0.5993.70");
var chrome119 = await browserFetcher.DownloadAsync("119.0.5997.0");

Console.WriteLine("Navigating");
await using (var browser = await Puppeteer.LaunchAsync(new()
{
ExecutablePath = chrome118.GetExecutablePath(),
}))
{
await using var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.whatismybrowser.com/");

Console.WriteLine("Generating PDF");
await page.PdfAsync(Path.Combine(Directory.GetCurrentDirectory(), "118.pdf"));

Console.WriteLine("Export completed");
}

await using (var browser = await Puppeteer.LaunchAsync(new()
{
ExecutablePath = chrome119.GetExecutablePath(),
}))
{
await using var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.whatismybrowser.com/");

Console.WriteLine("Generating PDF");
await page.PdfAsync(Path.Combine(Directory.GetCurrentDirectory(), "119.pdf"));

Console.WriteLine("Export completed");
}
#endregion
}

[PuppeteerTest("chrome-data.spec.ts", "Chrome", "should resolve download URLs")]
public void ShouldResolveDownloadUrls()
{
Expand Down

0 comments on commit 53d5bda

Please sign in to comment.