-
-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into protocol-using-webd…
…river-driver # Conflicts: # .github/workflows/dotnet.yml # lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs # lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json # lib/PuppeteerSharp.Tests/BrowserTests/ProcessTests.cs # lib/PuppeteerSharp.Tests/LauncherTests/PuppeteerConnectTests.cs # lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj # lib/PuppeteerSharp.Tooling/PuppeteerSharp.Tooling.csproj # lib/PuppeteerSharp/ConnectOptions.cs # lib/PuppeteerSharp/Launcher.cs # lib/PuppeteerSharp/PuppeteerSharp.csproj
- Loading branch information
Showing
390 changed files
with
3,989 additions
and
3,520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo-Local.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# How to test a Chrome Extension | ||
_Contributors: [Dario Kondratiuk](https://github.com/kblok)_ | ||
|
||
## Problem | ||
|
||
You need to use Puppeteer Sharp in an application set up for AOT compilation. | ||
|
||
## Solution | ||
|
||
You shouldn't need to do anything special to use Puppeteer Sharp in an AOT environment. The library is already prepared for it.\ | ||
The only challenge you might face is if you use any custom class to pass into or get from an Evaluate function. In that case you will need to provide a serialization context to PuppeteerSharp.\ | ||
Let's say you have a class like this: | ||
|
||
```csharp | ||
public class TestClass | ||
{ | ||
public string Name { get; set; } | ||
} | ||
``` | ||
|
||
You need to create a serialization context like this: | ||
|
||
```csharp | ||
[JsonSerializable(typeof(TestClass))] | ||
public partial class DemoJsonSerializationContext : JsonSerializerContext | ||
{} | ||
|
||
``` | ||
|
||
_For more information about `JsonSerializerContext` see [How to use source generation in System.Text.Json](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation?WT.mc_id=DT-MVP-5003814)._ | ||
|
||
Once you have your own context you have to pass it to PuppeteerSharp before launching the browser: | ||
|
||
```csharp | ||
Puppeteer.ExtraJsonSerializerContext = DemoJsonSerializationContext.Default; | ||
``` | ||
|
||
`ExtraJsonSerializerContext` will be used the first time PuppeteerSharp serializes or deserializes any object. So it's important to set it before launching the browser. Once set, you can't change it. | ||
|
||
## Example | ||
|
||
```csharp | ||
class MainClass | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
Puppeteer.ExtraJsonSerializerContext = DemoJsonSerializationContext.Default; | ||
var options = new LaunchOptions { Headless = true }; | ||
|
||
var browserFetcher = new BrowserFetcher(); | ||
await browserFetcher.DownloadAsync(); | ||
|
||
await using var browser = await Puppeteer.LaunchAsync(options); | ||
await using var page = await browser.NewPageAsync(); | ||
|
||
await page.GoToAsync("https://www.google.com"); | ||
|
||
var result = await page.EvaluateFunctionAsync<TestClass>("test => test", new TestClass { Name = "Dario"}); | ||
} | ||
} | ||
|
||
public class TestClass | ||
{ | ||
public string Name { get; set; } | ||
} | ||
|
||
[JsonSerializable(typeof(TestClass))] | ||
public partial class DemoJsonSerializationContext : JsonSerializerContext | ||
{} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
using Newtonsoft.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PuppeteerSharp.DevicesFetcher | ||
{ | ||
public class Device | ||
{ | ||
[JsonProperty("userAgent")] | ||
[JsonPropertyName("userAgent")] | ||
public string UserAgent { get; set; } | ||
[JsonProperty("name")] | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
[JsonProperty("viewport")] | ||
[JsonPropertyName("viewport")] | ||
public ViewPort Viewport { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
using Newtonsoft.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PuppeteerSharp.DevicesFetcher | ||
{ | ||
public class ViewPort | ||
{ | ||
[JsonProperty("width")] | ||
[JsonPropertyName("width")] | ||
public int Width { get; set; } | ||
[JsonProperty("height")] | ||
[JsonPropertyName("height")] | ||
public int Height { get; set; } | ||
|
||
[JsonProperty("deviceScaleFactor")] | ||
[JsonPropertyName("deviceScaleFactor")] | ||
public double DeviceScaleFactor { get; set; } | ||
|
||
[JsonProperty("isMobile")] | ||
[JsonPropertyName("isMobile")] | ||
public bool IsMobile { get; set; } | ||
[JsonProperty("hasTouch")] | ||
[JsonPropertyName("hasTouch")] | ||
public bool HasTouch { get; set; } | ||
[JsonProperty("isLandscape")] | ||
[JsonPropertyName("isLandscape")] | ||
public bool IsLandscape { get; set; } | ||
} | ||
} |
Oops, something went wrong.