diff --git a/src/Playwright/Core/Frame.cs b/src/Playwright/Core/Frame.cs index 4b48def53..19891796a 100644 --- a/src/Playwright/Core/Frame.cs +++ b/src/Playwright/Core/Frame.cs @@ -1013,21 +1013,27 @@ await SendMessageToServerAsync( Matches = options.IsNot, Log = (e.Data[Connection.LogDataKey] as string[]) ?? Array.Empty(), }; - if (e.Data[Connection.ErrorDetailsDataKey] is JsonElement details && details.ValueKind == JsonValueKind.Object) + // ErrorDetails is stored as raw JSON text for .NET Framework Exception.Data compatibility. + if (e.Data[Connection.ErrorDetailsDataKey] is string detailsJson && !string.IsNullOrEmpty(detailsJson)) { - if (details.TryGetProperty("customErrorMessage", out var customErrorMessage) && customErrorMessage.ValueKind == JsonValueKind.String) + using var detailsDocument = JsonDocument.Parse(detailsJson); + var details = detailsDocument.RootElement; + if (details.ValueKind == JsonValueKind.Object) { - result.ErrorMessage = "Error: " + customErrorMessage.GetString(); - } - if (details.TryGetProperty("received", out var received) && received.ValueKind == JsonValueKind.Object) - { - if (received.TryGetProperty("value", out var receivedValue)) + if (details.TryGetProperty("customErrorMessage", out var customErrorMessage) && customErrorMessage.ValueKind == JsonValueKind.String) { - result.Received = ScriptsHelper.ParseEvaluateResult(receivedValue); + result.ErrorMessage = "Error: " + customErrorMessage.GetString(); } - if (received.TryGetProperty("ariaSnapshot", out var ariaSnapshot) && ariaSnapshot.ValueKind == JsonValueKind.String) + if (details.TryGetProperty("received", out var received) && received.ValueKind == JsonValueKind.Object) { - result.ReceivedAriaSnapshot = ariaSnapshot.GetString(); + if (received.TryGetProperty("value", out var receivedValue)) + { + result.Received = ScriptsHelper.ParseEvaluateResult(receivedValue); + } + if (received.TryGetProperty("ariaSnapshot", out var ariaSnapshot) && ariaSnapshot.ValueKind == JsonValueKind.String) + { + result.ReceivedAriaSnapshot = ariaSnapshot.GetString(); + } } } } diff --git a/src/Playwright/Transport/Connection.cs b/src/Playwright/Transport/Connection.cs index 3471ba9e4..b13fb5721 100644 --- a/src/Playwright/Transport/Connection.cs +++ b/src/Playwright/Transport/Connection.cs @@ -286,7 +286,7 @@ internal void Dispatch(PlaywrightServerMessage message) if (message.Error != null && message.Result == null) { var exception = ParseException(message.Error.Error, FormatCallLog(message.Log)); - exception.Data[ErrorDetailsDataKey] = message.ErrorDetails; + exception.Data[ErrorDetailsDataKey] = message.ErrorDetails?.GetRawText(); exception.Data[LogDataKey] = message.Log; callback.TaskCompletionSource.TrySetException(exception); }