From bdd47e213fb0e7f9796f955ff5b944c0e4bb7ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Tue, 20 Aug 2024 15:28:11 -0300 Subject: [PATCH] Fix AOT build (#2747) * Fix AOT build * Add TargetType * Make Enums AOT ready * use new serializer in tests * add some missing enums --- .github/workflows/demo.yml | 5 +- .../PuppeteerTestAttribute.cs | 8 +- .../TestExpectations/TestExpectation.cs | 5 ++ .../BrowserData/FirefoxChannel.cs | 3 + .../Cdp/Messaging/DispatchKeyEventType.cs | 3 + .../Cdp/Messaging/DragEventType.cs | 3 + .../Cdp/Messaging/FileChooserAction.cs | 3 + lib/PuppeteerSharp/Cdp/Messaging/LogSource.cs | 4 + .../Cdp/Messaging/MouseEventType.cs | 3 + .../Cdp/Messaging/NavigationType.cs | 4 + .../Messaging/PageFrameDetachedResponse.cs | 4 + .../Cdp/Messaging/RemoteObjectSubtype.cs | 2 + .../Cdp/Messaging/RemoteObjectType.cs | 2 + lib/PuppeteerSharp/ConsoleType.cs | 3 + lib/PuppeteerSharp/CookiePriority.cs | 4 + lib/PuppeteerSharp/CookieSourceScheme.cs | 4 + lib/PuppeteerSharp/DOMWorldType.cs | 2 + lib/PuppeteerSharp/DialogType.cs | 3 + lib/PuppeteerSharp/Helpers/Json/JsonHelper.cs | 2 +- .../Json/JsonStringEnumMemberConverter.cs | 81 ++++++++++--------- .../SystemTextJsonSerializationContext.cs | 1 + lib/PuppeteerSharp/InitializationStatus.cs | 4 + lib/PuppeteerSharp/InitiatorType.cs | 3 + lib/PuppeteerSharp/Input/MouseButton.cs | 3 + lib/PuppeteerSharp/Input/PointerType.cs | 3 + .../InterceptResolutionAction.cs | 4 + lib/PuppeteerSharp/Media/MediaType.cs | 3 + lib/PuppeteerSharp/MediaFeature.cs | 3 + .../Mobile/DeviceDescriptorName.cs | 4 + lib/PuppeteerSharp/OverridePermission.cs | 3 + .../PageAccessibility/CheckedState.cs | 4 + lib/PuppeteerSharp/PuppeteerSharp.csproj | 8 +- lib/PuppeteerSharp/RequestAbortErrorCode.cs | 4 + lib/PuppeteerSharp/ResourceType.cs | 2 + lib/PuppeteerSharp/SameSite.cs | 2 + lib/PuppeteerSharp/ScreenshotType.cs | 4 + lib/PuppeteerSharp/TargetType.cs | 2 + lib/PuppeteerSharp/VisionDeficiency.cs | 3 + .../WaitForFunctionPollingOption.cs | 4 + lib/PuppeteerSharp/WaitUntilNavigation.cs | 4 + 40 files changed, 164 insertions(+), 52 deletions(-) diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index 0a48afb52..1aa1ac79e 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -39,10 +39,11 @@ jobs: run: | dotnet run --project PuppeteerSharpPdfDemo-Local.csproj auto-exit -f net8.0 - name: Run with AOT - if: matrix.os == 'macos-latest' + if: matrix.os == 'windows-2022' working-directory: ./demos/PuppeteerSharpPdfDemo run: | - dotnet run --project PuppeteerSharpPdfDemo-Local.csproj -r osx-arm64 -c Release -f net8.0 auto-exit + dotnet publish PuppeteerSharpPdfDemo-Local.csproj -r win-x64 -o build -f net8.0 + build/PuppeteerSharpPdfDemo-Local.exe auto-exit - name: Run on .NET Framework if: matrix.os == 'windows-2022' working-directory: ./demos/PuppeteerSharpPdfDemo diff --git a/lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs b/lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs index babb7da34..6b4d1363f 100644 --- a/lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs +++ b/lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs @@ -172,13 +172,9 @@ private static TestExpectation[] GetUpstreamExpectations() => _upstreamExpectations ??= LoadExpectationsFromResource("PuppeteerSharp.Nunit.TestExpectations.TestExpectations.upstream.json"); private static readonly JsonSerializerOptions DefaultJsonSerializerOptions = - new JsonSerializerOptions() + new() { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - Converters = - { - new JsonStringEnumMemberConverter(), - }, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; private static TestExpectation[] LoadExpectationsFromResource(string resourceName) diff --git a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectation.cs b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectation.cs index 5d6982028..5a13f1166 100644 --- a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectation.cs +++ b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectation.cs @@ -21,7 +21,9 @@ // * SOFTWARE. using System.Runtime.Serialization; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Nunit.TestExpectations; @@ -54,6 +56,7 @@ public Regex TestIdRegex public TestExpectationResult[] Expectations { get; set; } + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum TestExpectationResult { [EnumMember(Value = "FAIL")] Fail, @@ -62,6 +65,7 @@ public enum TestExpectationResult [EnumMember(Value = "TIMEOUT")] Timeout, } + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum TestExpectationsParameter { [EnumMember(Value = "firefox")] @@ -80,6 +84,7 @@ public enum TestExpectationsParameter Headful, } + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum TestExpectationPlatform { [EnumMember(Value = "darwin")] diff --git a/lib/PuppeteerSharp/BrowserData/FirefoxChannel.cs b/lib/PuppeteerSharp/BrowserData/FirefoxChannel.cs index f231990d1..2598ebee2 100644 --- a/lib/PuppeteerSharp/BrowserData/FirefoxChannel.cs +++ b/lib/PuppeteerSharp/BrowserData/FirefoxChannel.cs @@ -21,12 +21,15 @@ // * SOFTWARE. using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.BrowserData; /// /// Firefox channels. /// +[JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum FirefoxChannel { /// diff --git a/lib/PuppeteerSharp/Cdp/Messaging/DispatchKeyEventType.cs b/lib/PuppeteerSharp/Cdp/Messaging/DispatchKeyEventType.cs index 7a0a05004..64f46620d 100644 --- a/lib/PuppeteerSharp/Cdp/Messaging/DispatchKeyEventType.cs +++ b/lib/PuppeteerSharp/Cdp/Messaging/DispatchKeyEventType.cs @@ -1,7 +1,10 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Cdp.Messaging { + [JsonConverter(typeof(JsonStringEnumMemberConverter))] internal enum DispatchKeyEventType { /// diff --git a/lib/PuppeteerSharp/Cdp/Messaging/DragEventType.cs b/lib/PuppeteerSharp/Cdp/Messaging/DragEventType.cs index 028db5e82..0de14ee02 100644 --- a/lib/PuppeteerSharp/Cdp/Messaging/DragEventType.cs +++ b/lib/PuppeteerSharp/Cdp/Messaging/DragEventType.cs @@ -1,7 +1,10 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Cdp.Messaging { + [JsonConverter(typeof(JsonStringEnumMemberConverter))] internal enum DragEventType { /// diff --git a/lib/PuppeteerSharp/Cdp/Messaging/FileChooserAction.cs b/lib/PuppeteerSharp/Cdp/Messaging/FileChooserAction.cs index acdc87dd3..18e52a1f0 100644 --- a/lib/PuppeteerSharp/Cdp/Messaging/FileChooserAction.cs +++ b/lib/PuppeteerSharp/Cdp/Messaging/FileChooserAction.cs @@ -1,7 +1,10 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Cdp.Messaging { + [JsonConverter(typeof(JsonStringEnumMemberConverter))] internal enum FileChooserAction { /// diff --git a/lib/PuppeteerSharp/Cdp/Messaging/LogSource.cs b/lib/PuppeteerSharp/Cdp/Messaging/LogSource.cs index f3d8d772f..a2f286a1c 100644 --- a/lib/PuppeteerSharp/Cdp/Messaging/LogSource.cs +++ b/lib/PuppeteerSharp/Cdp/Messaging/LogSource.cs @@ -1,5 +1,9 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp.Cdp.Messaging; +[JsonConverter(typeof(JsonStringEnumMemberConverter))] internal enum LogSource { Xml = 0, diff --git a/lib/PuppeteerSharp/Cdp/Messaging/MouseEventType.cs b/lib/PuppeteerSharp/Cdp/Messaging/MouseEventType.cs index 98f163823..b23397a3a 100644 --- a/lib/PuppeteerSharp/Cdp/Messaging/MouseEventType.cs +++ b/lib/PuppeteerSharp/Cdp/Messaging/MouseEventType.cs @@ -1,7 +1,10 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Cdp.Messaging { + [JsonConverter(typeof(JsonStringEnumMemberConverter))] internal enum MouseEventType { /// diff --git a/lib/PuppeteerSharp/Cdp/Messaging/NavigationType.cs b/lib/PuppeteerSharp/Cdp/Messaging/NavigationType.cs index 8164842b0..ee8963833 100644 --- a/lib/PuppeteerSharp/Cdp/Messaging/NavigationType.cs +++ b/lib/PuppeteerSharp/Cdp/Messaging/NavigationType.cs @@ -1,8 +1,12 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp.Cdp.Messaging; /// /// Navigation types. /// +[JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum NavigationType { /// diff --git a/lib/PuppeteerSharp/Cdp/Messaging/PageFrameDetachedResponse.cs b/lib/PuppeteerSharp/Cdp/Messaging/PageFrameDetachedResponse.cs index 3fb21fc9f..825561d54 100644 --- a/lib/PuppeteerSharp/Cdp/Messaging/PageFrameDetachedResponse.cs +++ b/lib/PuppeteerSharp/Cdp/Messaging/PageFrameDetachedResponse.cs @@ -1,5 +1,9 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp.Cdp.Messaging { + [JsonConverter(typeof(JsonStringEnumMemberConverter))] internal enum FrameDetachedReason { /// diff --git a/lib/PuppeteerSharp/Cdp/Messaging/RemoteObjectSubtype.cs b/lib/PuppeteerSharp/Cdp/Messaging/RemoteObjectSubtype.cs index 399380c62..a35b72bc0 100644 --- a/lib/PuppeteerSharp/Cdp/Messaging/RemoteObjectSubtype.cs +++ b/lib/PuppeteerSharp/Cdp/Messaging/RemoteObjectSubtype.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Serialization; using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Cdp.Messaging @@ -5,6 +6,7 @@ namespace PuppeteerSharp.Cdp.Messaging /// /// Remote object subtype. /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] [DefaultEnumValue((int)Other)] public enum RemoteObjectSubtype { diff --git a/lib/PuppeteerSharp/Cdp/Messaging/RemoteObjectType.cs b/lib/PuppeteerSharp/Cdp/Messaging/RemoteObjectType.cs index 260b9a102..563559e87 100644 --- a/lib/PuppeteerSharp/Cdp/Messaging/RemoteObjectType.cs +++ b/lib/PuppeteerSharp/Cdp/Messaging/RemoteObjectType.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Serialization; using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Cdp.Messaging @@ -5,6 +6,7 @@ namespace PuppeteerSharp.Cdp.Messaging /// /// Remote object type. /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] [DefaultEnumValue((int)Other)] public enum RemoteObjectType { diff --git a/lib/PuppeteerSharp/ConsoleType.cs b/lib/PuppeteerSharp/ConsoleType.cs index 3c53c78b8..05631834e 100644 --- a/lib/PuppeteerSharp/ConsoleType.cs +++ b/lib/PuppeteerSharp/ConsoleType.cs @@ -1,10 +1,13 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp { /// /// Console type used on . /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum ConsoleType { /// diff --git a/lib/PuppeteerSharp/CookiePriority.cs b/lib/PuppeteerSharp/CookiePriority.cs index d64888768..3ab5f81dd 100644 --- a/lib/PuppeteerSharp/CookiePriority.cs +++ b/lib/PuppeteerSharp/CookiePriority.cs @@ -20,11 +20,15 @@ // * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // * SOFTWARE. +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp; /// /// Represents the cookie's 'Priority' status. /// +[JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum CookiePriority { /// diff --git a/lib/PuppeteerSharp/CookieSourceScheme.cs b/lib/PuppeteerSharp/CookieSourceScheme.cs index 596b87b7d..06439f429 100644 --- a/lib/PuppeteerSharp/CookieSourceScheme.cs +++ b/lib/PuppeteerSharp/CookieSourceScheme.cs @@ -20,6 +20,9 @@ // * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // * SOFTWARE. +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp; /// @@ -27,6 +30,7 @@ namespace PuppeteerSharp; /// "Unset" allows protocol clients to emulate legacy cookie scope for the scheme. /// This is a temporary ability and it will be removed in the future. /// +[JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum CookieSourceScheme { /// diff --git a/lib/PuppeteerSharp/DOMWorldType.cs b/lib/PuppeteerSharp/DOMWorldType.cs index 195d89497..5e83cc2c1 100644 --- a/lib/PuppeteerSharp/DOMWorldType.cs +++ b/lib/PuppeteerSharp/DOMWorldType.cs @@ -1,8 +1,10 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp { + [JsonConverter(typeof(JsonStringEnumMemberConverter))] [DefaultEnumValue((int)Other)] internal enum DOMWorldType { diff --git a/lib/PuppeteerSharp/DialogType.cs b/lib/PuppeteerSharp/DialogType.cs index 7fc74ec68..2fa0e498a 100644 --- a/lib/PuppeteerSharp/DialogType.cs +++ b/lib/PuppeteerSharp/DialogType.cs @@ -1,4 +1,6 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp { @@ -6,6 +8,7 @@ namespace PuppeteerSharp /// Dialog type. /// /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum DialogType { /// diff --git a/lib/PuppeteerSharp/Helpers/Json/JsonHelper.cs b/lib/PuppeteerSharp/Helpers/Json/JsonHelper.cs index b9a843603..a4b791620 100644 --- a/lib/PuppeteerSharp/Helpers/Json/JsonHelper.cs +++ b/lib/PuppeteerSharp/Helpers/Json/JsonHelper.cs @@ -37,7 +37,7 @@ internal static class JsonHelper #endif Converters = { - new HttpMethodConverter(), new JSHandleConverter(), new JsonStringEnumMemberConverter(), + new HttpMethodConverter(), new JSHandleConverter(), }, }; }); diff --git a/lib/PuppeteerSharp/Helpers/Json/JsonStringEnumMemberConverter.cs b/lib/PuppeteerSharp/Helpers/Json/JsonStringEnumMemberConverter.cs index 3982494a8..d3b0db181 100644 --- a/lib/PuppeteerSharp/Helpers/Json/JsonStringEnumMemberConverter.cs +++ b/lib/PuppeteerSharp/Helpers/Json/JsonStringEnumMemberConverter.cs @@ -23,6 +23,7 @@ */ using System; +using System.Collections.Concurrent; using System.Text.Json; using System.Text.Json.Serialization; @@ -31,26 +32,28 @@ namespace PuppeteerSharp.Helpers.Json; /// /// Converts an enum value to or from a JSON string. /// -internal sealed class JsonStringEnumMemberConverter : JsonConverterFactory +/// The enum type. +internal class JsonStringEnumMemberConverter : JsonConverterFactory + where TEnum : struct, Enum { - /// - public override bool CanConvert(Type typeToConvert) - => (typeToConvert.IsEnum || Nullable.GetUnderlyingType(typeToConvert)?.IsEnum == true) && - !Attribute.IsDefined(typeToConvert, typeof(JsonStringIgnoreAttribute)); + private static readonly ConcurrentDictionary _jsonConverterCache = new(); - /// - public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) + public static JsonConverter CreateJsonConverter() { - var nullableType = Nullable.GetUnderlyingType(typeToConvert); - - return (JsonConverter)Activator.CreateInstance( - nullableType == null ? - typeof(EnumMemberConverter<>).MakeGenericType(typeToConvert) : - typeof(NullableEnumMemberConverter<>).MakeGenericType(nullableType)); + var nullableType = Nullable.GetUnderlyingType(typeof(TEnum)); + JsonConverter jsonConverter = nullableType == null ? new EnumMemberConverter() : new NullableEnumMemberConverter(); + _jsonConverterCache.TryAdd(typeof(TEnum), jsonConverter); + return jsonConverter; } - private static TEnum? Read(ref Utf8JsonReader reader) - where TEnum : struct, Enum + public override bool CanConvert(Type typeToConvert) + => typeToConvert.IsEnum || Nullable.GetUnderlyingType(typeToConvert)?.IsEnum == true; + + public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) + => _jsonConverterCache.TryGetValue(typeToConvert, out var jsonConverter) ? jsonConverter : CreateJsonConverter(); + + private static T? Read(ref Utf8JsonReader reader) + where T : struct, Enum { if (reader.TokenType == JsonTokenType.Null) { @@ -59,22 +62,22 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer if (reader.TokenType == JsonTokenType.String) { - return EnumHelper.FromValueString(reader.GetString()); + return EnumHelper.FromValueString(reader.GetString()); } if (reader.TokenType == JsonTokenType.Number) { - var enumTypeCode = Type.GetTypeCode(typeof(TEnum)); + var enumTypeCode = Type.GetTypeCode(typeof(T)); return enumTypeCode switch { - TypeCode.Int32 => (TEnum)(object)reader.GetInt32(), - TypeCode.Int64 => (TEnum)(object)reader.GetInt64(), - TypeCode.Int16 => (TEnum)(object)reader.GetInt16(), - TypeCode.Byte => (TEnum)(object)reader.GetByte(), - TypeCode.UInt32 => (TEnum)(object)reader.GetUInt32(), - TypeCode.UInt64 => (TEnum)(object)reader.GetUInt64(), - TypeCode.UInt16 => (TEnum)(object)reader.GetUInt16(), - TypeCode.SByte => (TEnum)(object)reader.GetSByte(), + TypeCode.Int32 => (T)(object)reader.GetInt32(), + TypeCode.Int64 => (T)(object)reader.GetInt64(), + TypeCode.Int16 => (T)(object)reader.GetInt16(), + TypeCode.Byte => (T)(object)reader.GetByte(), + TypeCode.UInt32 => (T)(object)reader.GetUInt32(), + TypeCode.UInt64 => (T)(object)reader.GetUInt64(), + TypeCode.UInt16 => (T)(object)reader.GetUInt16(), + TypeCode.SByte => (T)(object)reader.GetSByte(), _ => throw new JsonException($"Enum '{typeof(TEnum).Name}' of {enumTypeCode} type is not supported."), }; } @@ -82,8 +85,8 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer throw new JsonException(); } - private static void Write(Utf8JsonWriter writer, TEnum? value) - where TEnum : struct, Enum + private static void Write(Utf8JsonWriter writer, T? value) + where T : struct, Enum { if (value.HasValue) { @@ -95,23 +98,23 @@ private static void Write(Utf8JsonWriter writer, TEnum? value) } } - private class EnumMemberConverter : JsonConverter - where TEnum : struct, Enum + private class EnumMemberConverter : JsonConverter + where T : struct, Enum { - public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - => Read(ref reader) ?? default; + public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => Read(ref reader) ?? default; - public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options) - => Write(writer, value); + public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) + => Write(writer, value); } - private class NullableEnumMemberConverter : JsonConverter - where TEnum : struct, Enum + private class NullableEnumMemberConverter : JsonConverter + where T : struct, Enum { - public override TEnum? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - => Read(ref reader); + public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => Read(ref reader); - public override void Write(Utf8JsonWriter writer, TEnum? value, JsonSerializerOptions options) - => Write(writer, value); + public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options) + => Write(writer, value); } } diff --git a/lib/PuppeteerSharp/Helpers/Json/SystemTextJsonSerializationContext.cs b/lib/PuppeteerSharp/Helpers/Json/SystemTextJsonSerializationContext.cs index 85bcc1ca5..59d1821c5 100644 --- a/lib/PuppeteerSharp/Helpers/Json/SystemTextJsonSerializationContext.cs +++ b/lib/PuppeteerSharp/Helpers/Json/SystemTextJsonSerializationContext.cs @@ -205,6 +205,7 @@ namespace PuppeteerSharp.Helpers.Json; [JsonSerializable(typeof(TargetSendMessageToTargetRequest))] [JsonSerializable(typeof(TargetSetAutoAttachRequest))] [JsonSerializable(typeof(TargetSetDiscoverTargetsRequest))] +[JsonSerializable(typeof(TargetType))] [JsonSerializable(typeof(TracingCompleteResponse))] [JsonSerializable(typeof(TracingStartRequest))] [JsonSerializable(typeof(WSEndpointResponse))] diff --git a/lib/PuppeteerSharp/InitializationStatus.cs b/lib/PuppeteerSharp/InitializationStatus.cs index 59d337fc3..69fc66d28 100644 --- a/lib/PuppeteerSharp/InitializationStatus.cs +++ b/lib/PuppeteerSharp/InitializationStatus.cs @@ -1,5 +1,9 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp { + [JsonConverter(typeof(JsonStringEnumMemberConverter))] internal enum InitializationStatus { Aborted, diff --git a/lib/PuppeteerSharp/InitiatorType.cs b/lib/PuppeteerSharp/InitiatorType.cs index f12aee3bd..88b5181a9 100644 --- a/lib/PuppeteerSharp/InitiatorType.cs +++ b/lib/PuppeteerSharp/InitiatorType.cs @@ -1,10 +1,13 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp; /// /// Type of the . /// +[JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum InitiatorType { /// diff --git a/lib/PuppeteerSharp/Input/MouseButton.cs b/lib/PuppeteerSharp/Input/MouseButton.cs index bbbf4ea26..a11d8797e 100644 --- a/lib/PuppeteerSharp/Input/MouseButton.cs +++ b/lib/PuppeteerSharp/Input/MouseButton.cs @@ -1,11 +1,14 @@ using System; using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Input { /// /// The type of button click to use with , and . /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] [Flags] #pragma warning disable CA1714 // Flags enums should have plural names. We don't want to break compatibility for this public enum MouseButton diff --git a/lib/PuppeteerSharp/Input/PointerType.cs b/lib/PuppeteerSharp/Input/PointerType.cs index e736079b1..65262cd46 100644 --- a/lib/PuppeteerSharp/Input/PointerType.cs +++ b/lib/PuppeteerSharp/Input/PointerType.cs @@ -1,7 +1,10 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Input { + [JsonConverter(typeof(JsonStringEnumMemberConverter))] internal enum PointerType { /// diff --git a/lib/PuppeteerSharp/InterceptResolutionAction.cs b/lib/PuppeteerSharp/InterceptResolutionAction.cs index 2b37b7009..ec6244877 100644 --- a/lib/PuppeteerSharp/InterceptResolutionAction.cs +++ b/lib/PuppeteerSharp/InterceptResolutionAction.cs @@ -20,8 +20,12 @@ // * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // * SOFTWARE. +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp; +[JsonConverter(typeof(JsonStringEnumMemberConverter))] internal enum InterceptResolutionAction { Abort, diff --git a/lib/PuppeteerSharp/Media/MediaType.cs b/lib/PuppeteerSharp/Media/MediaType.cs index f093ccb08..6830e3127 100644 --- a/lib/PuppeteerSharp/Media/MediaType.cs +++ b/lib/PuppeteerSharp/Media/MediaType.cs @@ -1,10 +1,13 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp.Media { /// /// Media type. /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum MediaType { /// diff --git a/lib/PuppeteerSharp/MediaFeature.cs b/lib/PuppeteerSharp/MediaFeature.cs index 28435f3ed..b377274a9 100644 --- a/lib/PuppeteerSharp/MediaFeature.cs +++ b/lib/PuppeteerSharp/MediaFeature.cs @@ -1,10 +1,13 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp { /// /// Media Feature. See . /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum MediaFeature { /// diff --git a/lib/PuppeteerSharp/Mobile/DeviceDescriptorName.cs b/lib/PuppeteerSharp/Mobile/DeviceDescriptorName.cs index f0e9e9d74..025f3b1f8 100644 --- a/lib/PuppeteerSharp/Mobile/DeviceDescriptorName.cs +++ b/lib/PuppeteerSharp/Mobile/DeviceDescriptorName.cs @@ -1,8 +1,12 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp.Mobile { /// /// Device descriptor name. /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum DeviceDescriptorName { /// diff --git a/lib/PuppeteerSharp/OverridePermission.cs b/lib/PuppeteerSharp/OverridePermission.cs index 50de3bed8..5f69614fd 100644 --- a/lib/PuppeteerSharp/OverridePermission.cs +++ b/lib/PuppeteerSharp/OverridePermission.cs @@ -1,4 +1,6 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp { @@ -6,6 +8,7 @@ namespace PuppeteerSharp /// Override permission. /// /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum OverridePermission { /// diff --git a/lib/PuppeteerSharp/PageAccessibility/CheckedState.cs b/lib/PuppeteerSharp/PageAccessibility/CheckedState.cs index f93b642c0..fc0110b93 100644 --- a/lib/PuppeteerSharp/PageAccessibility/CheckedState.cs +++ b/lib/PuppeteerSharp/PageAccessibility/CheckedState.cs @@ -1,8 +1,12 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp.PageAccessibility { /// /// Three-state boolean. See and. /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum CheckedState { /// diff --git a/lib/PuppeteerSharp/PuppeteerSharp.csproj b/lib/PuppeteerSharp/PuppeteerSharp.csproj index c5ee49d4f..dbc981596 100644 --- a/lib/PuppeteerSharp/PuppeteerSharp.csproj +++ b/lib/PuppeteerSharp/PuppeteerSharp.csproj @@ -12,10 +12,10 @@ Headless Browser .NET API PuppeteerSharp - 19.0.0 - 19.0.0 - 19.0.0 - 19.0.0 + 19.0.1 + 19.0.1 + 19.0.1 + 19.0.1 false false embedded diff --git a/lib/PuppeteerSharp/RequestAbortErrorCode.cs b/lib/PuppeteerSharp/RequestAbortErrorCode.cs index fe55ce854..b06e1339f 100644 --- a/lib/PuppeteerSharp/RequestAbortErrorCode.cs +++ b/lib/PuppeteerSharp/RequestAbortErrorCode.cs @@ -1,8 +1,12 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp { /// /// Abort error codes. used by . /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum RequestAbortErrorCode { /// diff --git a/lib/PuppeteerSharp/ResourceType.cs b/lib/PuppeteerSharp/ResourceType.cs index 09a9485eb..2c77cbc65 100644 --- a/lib/PuppeteerSharp/ResourceType.cs +++ b/lib/PuppeteerSharp/ResourceType.cs @@ -1,4 +1,5 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp @@ -7,6 +8,7 @@ namespace PuppeteerSharp /// Resource type. /// /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] [DefaultEnumValue((int)Unknown)] public enum ResourceType { diff --git a/lib/PuppeteerSharp/SameSite.cs b/lib/PuppeteerSharp/SameSite.cs index b706a125b..ffd818424 100644 --- a/lib/PuppeteerSharp/SameSite.cs +++ b/lib/PuppeteerSharp/SameSite.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Serialization; using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp @@ -5,6 +6,7 @@ namespace PuppeteerSharp /// /// SameSite values in cookies. /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] [DefaultEnumValue((int)None)] public enum SameSite { diff --git a/lib/PuppeteerSharp/ScreenshotType.cs b/lib/PuppeteerSharp/ScreenshotType.cs index bc77dc17a..cd0048e91 100644 --- a/lib/PuppeteerSharp/ScreenshotType.cs +++ b/lib/PuppeteerSharp/ScreenshotType.cs @@ -1,9 +1,13 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp { /// /// Screenshot file type. /// /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum ScreenshotType { /// diff --git a/lib/PuppeteerSharp/TargetType.cs b/lib/PuppeteerSharp/TargetType.cs index 976aae596..e5c7d872e 100644 --- a/lib/PuppeteerSharp/TargetType.cs +++ b/lib/PuppeteerSharp/TargetType.cs @@ -1,4 +1,5 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp @@ -6,6 +7,7 @@ namespace PuppeteerSharp /// /// Target type. /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] [DefaultEnumValue((int)Other)] public enum TargetType { diff --git a/lib/PuppeteerSharp/VisionDeficiency.cs b/lib/PuppeteerSharp/VisionDeficiency.cs index 618043e13..7d9b68246 100644 --- a/lib/PuppeteerSharp/VisionDeficiency.cs +++ b/lib/PuppeteerSharp/VisionDeficiency.cs @@ -1,10 +1,13 @@ using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; namespace PuppeteerSharp { /// /// Types of vision deficiency to emulate using . /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum VisionDeficiency { /// diff --git a/lib/PuppeteerSharp/WaitForFunctionPollingOption.cs b/lib/PuppeteerSharp/WaitForFunctionPollingOption.cs index a77dc08aa..2ca8735b4 100644 --- a/lib/PuppeteerSharp/WaitForFunctionPollingOption.cs +++ b/lib/PuppeteerSharp/WaitForFunctionPollingOption.cs @@ -1,8 +1,12 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp { /// /// An interval at which the pageFunction is executed. /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum WaitForFunctionPollingOption { /// diff --git a/lib/PuppeteerSharp/WaitUntilNavigation.cs b/lib/PuppeteerSharp/WaitUntilNavigation.cs index dfbdac1bf..0f6def3bc 100644 --- a/lib/PuppeteerSharp/WaitUntilNavigation.cs +++ b/lib/PuppeteerSharp/WaitUntilNavigation.cs @@ -1,8 +1,12 @@ +using System.Text.Json.Serialization; +using PuppeteerSharp.Helpers.Json; + namespace PuppeteerSharp { /// /// Wait until navigation. /// + [JsonConverter(typeof(JsonStringEnumMemberConverter))] public enum WaitUntilNavigation { ///