Skip to content

Commit a3cca3a

Browse files
authored
Merge pull request #2740 from hardkoded/v19
V19 to Master
2 parents 78e2cf3 + 838ed8d commit a3cca3a

File tree

280 files changed

+1576
-1409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+1576
-1409
lines changed

.github/workflows/demo.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- master
77
- release-*
88
pull_request:
9-
branches: [master]
109
paths:
1110
- "**.cs"
1211
- "**.csproj"
@@ -35,7 +34,17 @@ jobs:
3534
working-directory: ./demos/PuppeteerSharpPdfDemo
3635
run: |
3736
dotnet restore PuppeteerSharpPdfDemo-Local.csproj
38-
- name: Run Project
37+
- name: Run on .NET
3938
working-directory: ./demos/PuppeteerSharpPdfDemo
4039
run: |
41-
dotnet run --project PuppeteerSharpPdfDemo-Local.csproj auto-exit
40+
dotnet run --project PuppeteerSharpPdfDemo-Local.csproj auto-exit -f net8.0
41+
- name: Run with AOT
42+
if: matrix.os == 'macos-latest'
43+
working-directory: ./demos/PuppeteerSharpPdfDemo
44+
run: |
45+
dotnet run --project PuppeteerSharpPdfDemo-Local.csproj -r osx-arm64 -c Release -f net8.0 auto-exit
46+
- name: Run on .NET Framework
47+
if: matrix.os == 'windows-2022'
48+
working-directory: ./demos/PuppeteerSharpPdfDemo
49+
run: |
50+
dotnet run --project PuppeteerSharpPdfDemo-Local.csproj auto-exit -f net471

.github/workflows/dotnet.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
- release-*
99
merge_group:
1010
pull_request:
11-
branches: [ master ]
1211
paths:
1312
- '**.yml'
1413
- '**.cs'
@@ -84,7 +83,7 @@ jobs:
8483
Get-ChildItem -Path cert:\CurrentUSer\my | where { $_.friendlyname -eq "Puppeteer" } | Export-Certificate -FilePath $env:GITHUB_WORKSPACE\lib\PuppeteerSharp.TestServer\testCert.cer
8584
- name: Check formatting
8685
if: ${{ matrix.os == 'ubuntu-latest' && matrix.browser == 'CHROME' && matrix.mode == 'headless' }}
87-
run: dotnet format ./lib/PuppeteerSharp.sln --verify-no-changes
86+
run: dotnet format ./lib/PuppeteerSharp.sln --verify-no-changes --exclude-diagnostics CA1865
8887
- name: Build
8988
working-directory: lib
9089
run: dotnet build PuppeteerSharp.sln

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ var result = await page.GetContentAsync();
112112
```cs
113113
await using var page = await browser.NewPageAsync();
114114
var seven = await page.EvaluateExpressionAsync<int>("4 + 3");
115-
var someObject = await page.EvaluateFunctionAsync<dynamic>("(value) => ({a: value})", 5);
116-
Console.WriteLine(someObject.a);
115+
var someObject = await page.EvaluateFunctionAsync<JsonElement>("(value) => ({a: value})", 5);
116+
Console.WriteLine(someObject.GetProperty("a").GetString());
117117
```
118-
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorEvalTests.cs#L16-L21' title='Snippet source file'>snippet source</a> | <a href='#snippet-Evaluate' title='Start of snippet'>anchor</a></sup>
118+
<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>
119119
<!-- endSnippet -->
120120

121121
### Wait For Selector

demos/PuppeteerSharpPdfDemo/Program.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Linq;
33
using System.IO;
4+
using System.Text.Json.Serialization;
5+
using System.Text.Json.Serialization.Metadata;
46
using System.Threading.Tasks;
57
using PuppeteerSharp;
68

@@ -10,6 +12,10 @@ class MainClass
1012
{
1113
public static async Task Main(string[] args)
1214
{
15+
#if NET8_0_OR_GREATER
16+
Puppeteer.ExtraJsonSerializerContext = DemoJsonSerializationContext.Default;
17+
#endif
18+
1319
var options = new LaunchOptions { Headless = true };
1420

1521
Console.WriteLine("Downloading chromium");
@@ -28,10 +34,26 @@ public static async Task Main(string[] args)
2834

2935
Console.WriteLine("Export completed");
3036

37+
#if NET8_0_OR_GREATER
38+
// AOT Test
39+
var result = await page.EvaluateFunctionAsync<TestClass>("test => test", new TestClass { Name = "Dario"});
40+
Console.WriteLine($"Name evaluated to {result.Name}");
41+
#endif
3142
if (!args.Any(arg => arg == "auto-exit"))
3243
{
3344
Console.ReadLine();
3445
}
3546
}
3647
}
48+
49+
#if NET8_0_OR_GREATER
50+
public class TestClass
51+
{
52+
public string Name { get; set; }
53+
}
54+
55+
[JsonSerializable(typeof(TestClass))]
56+
public partial class DemoJsonSerializationContext : JsonSerializerContext
57+
{}
58+
#endif
3759
}

demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo-Local.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
6-
<LangVersion>8.0</LangVersion>
4+
<TargetFrameworks>net8.0;net471</TargetFrameworks>
5+
<LangVersion>12</LangVersion>
6+
</PropertyGroup>
7+
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
8+
<PublishAot>true</PublishAot>
79
</PropertyGroup>
810
<ItemGroup>
911
<ProjectReference Include="..\..\lib\PuppeteerSharp\PuppeteerSharp.csproj" />

lib/.editorconfig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ dotnet_diagnostic.CA1054.severity = none
247247
dotnet_diagnostic.CA1056.severity = none
248248
# Avoid empty interfaces
249249
dotnet_diagnostic.CA1040.severity = none
250+
# Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance
251+
# This is not netstandard compatible
252+
dotnet_diagnostic.CA1510.severity = none
253+
# Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' when you have a string with a single char
254+
# This is not .NET 8 compatible
255+
dotnet_diagnostic.CA1865.severity = none
256+
# Use 'ObjectDisposedException.ThrowIf' instead of explicitly throwing a new exception instance
257+
# This is not netstandard compatible
258+
dotnet_diagnostic.CA1513.severity = none
259+
# Use Change the 'WriteAsync' method call to use the 'Stream.WriteAsync(ReadOnlyMemory<byte>, CancellationToken)' overload
260+
# This is not netstandard compatible
261+
dotnet_diagnostic.CA1835.severity = none
250262
# Use ConfigureAwait
251263
dotnet_diagnostic.CA2007.severity = error
252264
# CA1711: Identifiers should not have incorrect suffix
@@ -264,6 +276,8 @@ dotnet_diagnostic.CA1815.severity = suggestion
264276
# CA1848: Use the LoggerMessage delegates
265277
# TODO: REMOVE
266278
dotnet_diagnostic.CA1848.severity = none
279+
# internal sealed
280+
dotnet_diagnostic.CA1852.severity = error
267281
# CA1859: Use concrete types when possible for improved performance
268282
# It collides with https://www.jetbrains.com/help/rider/ReturnTypeCanBeEnumerable.Local.html
269283
dotnet_diagnostic.CA1859.severity = none
@@ -303,7 +317,7 @@ dotnet_diagnostic.CA1001.severity = error
303317
dotnet_diagnostic.CA1304.severity = error
304318
# CA1305: String.Format with culture
305319
dotnet_diagnostic.CA1305.severity = error
306-
# CA1304: CA1308: Normalize strings to uppercase
320+
# CA1308: Normalize strings to uppercase
307321
dotnet_diagnostic.CA1308.severity = none
308322
# CA1721: The property name 'DefaultArgs' is confusing given the existence of method 'GetDefaultArgs'. Rename or remove one of these members.
309323
dotnet_diagnostic.CA1721.severity = error

lib/Common/CommonProps.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
</None>
1212
</ItemGroup>
1313
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
14-
<Exec Command="dotnet format $(ProjectPath)" />
14+
<Exec Command="dotnet format $(ProjectPath) --exclude-diagnostics CA1865" />
1515
</Target>
1616
</Project>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using Newtonsoft.Json;
1+
using System.Text.Json.Serialization;
22

33
namespace PuppeteerSharp.DevicesFetcher
44
{
55
public class Device
66
{
7-
[JsonProperty("userAgent")]
7+
[JsonPropertyName("userAgent")]
88
public string UserAgent { get; set; }
9-
[JsonProperty("name")]
9+
[JsonPropertyName("name")]
1010
public string Name { get; set; }
11-
[JsonProperty("viewport")]
11+
[JsonPropertyName("viewport")]
1212
public ViewPort Viewport { get; set; }
1313
}
1414
}

lib/PuppeteerSharp.DevicesFetcher/Program.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
using System.Linq;
55
using System.Net.Http;
66
using System.Text;
7+
using System.Text.Json;
78
using System.Threading.Tasks;
8-
using Newtonsoft.Json;
9+
910
namespace PuppeteerSharp.DevicesFetcher
1011
{
1112
static class Program
@@ -34,7 +35,7 @@ static async Task Main(string[] args)
3435
Device[] devices;
3536
try
3637
{
37-
devices = JsonConvert.DeserializeObject<Device[]>(text);
38+
devices = JsonSerializer.Deserialize<Device[]>(text);
3839
}
3940
catch (Exception ex)
4041
{
@@ -70,14 +71,6 @@ public static class DeviceDescriptors
7071
new Lazy<IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor>>(() => new ReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor>(Devices));
7172
7273
internal static IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor> ToReadOnly() => _readOnlyDevices.Value;
73-
74-
/// <summary>
75-
/// Get the specified device description.
76-
/// </summary>
77-
/// <returns>The device descriptor.</returns>
78-
/// <param name=""name"">Device Name.</param>
79-
[Obsolete(""Use Puppeteer.Devices instead"")]
80-
public static DeviceDescriptor Get(DeviceDescriptorName name) => Devices[name];
8174
}
8275
}";
8376

lib/PuppeteerSharp.DevicesFetcher/PuppeteerSharp.DevicesFetcher.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
<TargetFramework>net8.0</TargetFramework>
66
<LangVersion>12</LangVersion>
77
</PropertyGroup>
8-
<ItemGroup>
9-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
10-
</ItemGroup>
11-
128
<ItemGroup>
139
<ProjectReference Include="..\PuppeteerSharp\PuppeteerSharp.csproj" />
1410
</ItemGroup>

0 commit comments

Comments
 (0)