Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v20 #2761

Merged
merged 5 commits into from
Sep 3, 2024
Merged

v20 #2761

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/on-push-do-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ on:
push:
jobs:
docs:
runs-on: windows-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Run MarkdownSnippets
run: |
dotnet tool install --global MarkdownSnippets.Tool
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ See [this document](https://github.com/hardkoded/puppeteer-sharp/blob/master/CON

## Take screenshots

<!-- snippet: ScreenshotAsync -->
<a id='snippet-ScreenshotAsync'></a>
<!-- snippet: screenshotasync_example -->
<a id='snippet-screenshotasync_example'></a>
```cs
var browserFetcher = new BrowserFetcher();
await browserFetcher.DownloadAsync();
Expand All @@ -60,27 +60,27 @@ await using var page = await browser.NewPageAsync();
await page.GoToAsync("http://www.google.com");
await page.ScreenshotAsync(outputFile);
```
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/ScreenshotTests/PageScreenshotTests.cs#L54-L62' 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#L54-L62' title='Snippet source file'>snippet source</a> | <a href='#snippet-screenshotasync_example' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

You can also change the view port before generating the screenshot

<!-- snippet: SetViewportAsync -->
<a id='snippet-SetViewportAsync'></a>
<!-- snippet: setviewportasync_example -->
<a id='snippet-setviewportasync_example'></a>
```cs
await Page.SetViewportAsync(new ViewPortOptions
{
Width = 500,
Height = 500
});
```
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/ScreenshotTests/ElementHandleScreenshotTests.cs#L13-L19' 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#L13-L19' title='Snippet source file'>snippet source</a> | <a href='#snippet-setviewportasync_example' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Generate PDF files

<!-- snippet: PdfAsync -->
<a id='snippet-PdfAsync'></a>
<!-- snippet: pdfasync_example -->
<a id='snippet-pdfasync_example'></a>
```cs
var browserFetcher = new BrowserFetcher();
await browserFetcher.DownloadAsync();
Expand All @@ -90,32 +90,32 @@ 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='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs#L23-L33' 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#L23-L33' title='Snippet source file'>snippet source</a> | <a href='#snippet-pdfasync_example' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Inject HTML

<!-- snippet: SetContentAsync -->
<a id='snippet-SetContentAsync'></a>
<!-- snippet: setcontentasync_example -->
<a id='snippet-setcontentasync_example'></a>
```cs
await using var page = await browser.NewPageAsync();
await page.SetContentAsync("<div>My Receipt</div>");
var result = await page.GetContentAsync();
```
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs#L14-L20' 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#L14-L20' title='Snippet source file'>snippet source</a> | <a href='#snippet-setcontentasync_example' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Evaluate Javascript

<!-- snippet: Evaluate -->
<a id='snippet-Evaluate'></a>
<!-- snippet: evaluate_example -->
<a id='snippet-evaluate_example'></a>
```cs
await using var page = await browser.NewPageAsync();
var seven = await page.EvaluateExpressionAsync<int>("4 + 3");
var someObject = await page.EvaluateFunctionAsync<JsonElement>("(value) => ({a: value})", 5);
Console.WriteLine(someObject.GetProperty("a").GetString());
```
<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>
<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_example' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Wait For Selector
Expand Down
6 changes: 3 additions & 3 deletions docfx_project/docs/DownloadFetcher.Download.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ You will find the available versions [here](https://googlechromelabs.github.io/c
Once you have the version you want, you can download it using the `BrowserFetcher` class.

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

Expand Down Expand Up @@ -51,6 +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#L24-L59' title='Snippet source file'>snippet source</a> | <a href='#snippet-CustomVersionsExample' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/Browsers/Chrome/ChromeDataTests.cs#L24-L59' title='Snippet source file'>snippet source</a> | <a href='#snippet-customversions_example' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
```
6 changes: 3 additions & 3 deletions docfx_project/docs/ReuseChrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ from a location where it was previously downloaded instead of from the default l

Use `BrowserFetcherOptions` to specify the full path for where to download Chrome.

<!-- snippet: ReuseChromeExample -->
<a id='snippet-ReuseChromeExample'></a>
<!-- snippet: reusechrome_example -->
<a id='snippet-reusechrome_example'></a>
```cs
var downloadPath = "/Users/dario/chrome";
var browserFetcherOptions = new BrowserFetcherOptions { Path = downloadPath };
var browserFetcher = new BrowserFetcher(browserFetcherOptions);
var installedBrowser = await browserFetcher.DownloadAsync();
```
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/Browsers/Chrome/ChromeDataTests.cs#L14-L19' title='Snippet source file'>snippet source</a> | <a href='#snippet-ReuseChromeExample' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/Browsers/Chrome/ChromeDataTests.cs#L14-L19' title='Snippet source file'>snippet source</a> | <a href='#snippet-reusechrome_example' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Use `Puppeteer.LaunchAsync()` with `LaunchOptions` with the `LaunchOptions.ExecutablePath` property set to the
Expand Down
12 changes: 0 additions & 12 deletions lib/PuppeteerSharp.AspNetFramework/AspNetWebSocketTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace PuppeteerSharp.AspNetFramework
{
public class AspNetWebSocketTransport : WebSocketTransport
{
#region Static fields

/// <summary>
/// Gets a <see cref="TransportFactory"/> that creates <see cref="AspNetWebSocketTransport"/> instances.
/// </summary>
Expand All @@ -22,10 +20,6 @@ public class AspNetWebSocketTransport : WebSocketTransport
/// </summary>
public static readonly TransportTaskScheduler AspNetTransportScheduler = ScheduleBackgroundTask;

#endregion

#region Static methods

private static async Task<IConnectionTransport> CreateAspNetTransport(Uri url, IConnectionOptions connectionOptions, CancellationToken cancellationToken)
{
var webSocketFactory = connectionOptions.WebSocketFactory ?? DefaultWebSocketFactory;
Expand All @@ -40,15 +34,9 @@ Task ExecuteAsync(CancellationToken hostingCancellationToken)
HostingEnvironment.QueueBackgroundWorkItem(ExecuteAsync);
}

#endregion

#region Constructor(s)

/// <inheritdoc />
public AspNetWebSocketTransport(WebSocket client, bool queueRequests)
: base(client, AspNetTransportScheduler, queueRequests)
{ }

#endregion
}
}
4 changes: 2 additions & 2 deletions lib/PuppeteerSharp.Tests/Browsers/Chrome/ChromeDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ChromeDataTests
{
public async Task ReuseChromeExample()
{
#region ReuseChromeExample
#region reusechrome_example
var downloadPath = "/Users/dario/chrome";
var browserFetcherOptions = new BrowserFetcherOptions { Path = downloadPath };
var browserFetcher = new BrowserFetcher(browserFetcherOptions);
Expand All @@ -21,7 +21,7 @@ public async Task ReuseChromeExample()

public async Task Usage()
{
#region CustomVersionsExample
#region customversions_example
Console.WriteLine("Downloading browsers");

var browserFetcher = new BrowserFetcher(SupportedBrowser.Chrome);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class WaitForDevicePromptTests : PuppeteerPageBaseTest
{
public async Task Usage()
{
#region DeviceRequestPromptUsage
#region devicerequestprompt_usage
var promptTask = Page.WaitForDevicePromptAsync();
await Task.WhenAll(
promptTask,
Expand All @@ -25,7 +25,7 @@ await devicePrompt.WaitForDeviceAsync(device => device.Name.Contains("My Device"

public async Task PageUsage()
{
#region IPageWaitForDevicePromptAsyncUsage
#region ipagewaitfordevicepromptasync_usage
var promptTask = Page.WaitForDevicePromptAsync();
await Task.WhenAll(
promptTask,
Expand All @@ -41,7 +41,7 @@ await devicePrompt.WaitForDeviceAsync(device => device.Name.Contains("My Device"
public async Task FrameUsage()
{
var frame = Page.MainFrame;
#region IFrameWaitForDevicePromptAsyncUsage
#region iframewaitfordevicepromptasync_usage
var promptTask = frame.WaitForDevicePromptAsync();
await Task.WhenAll(
promptTask,
Expand Down
Loading
Loading