Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 16 additions & 10 deletions src/Playwright/Core/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,21 +1013,27 @@ await SendMessageToServerAsync(
Matches = options.IsNot,
Log = (e.Data[Connection.LogDataKey] as string[]) ?? Array.Empty<string>(),
};
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<object>(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<object>(receivedValue);
}
if (received.TryGetProperty("ariaSnapshot", out var ariaSnapshot) && ariaSnapshot.ValueKind == JsonValueKind.String)
{
result.ReceivedAriaSnapshot = ariaSnapshot.GetString();
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Playwright/Transport/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ 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 values must be serializable on .NET Framework.
// Store ErrorDetails as raw JSON text (not JsonElement).
Comment thread
kblok marked this conversation as resolved.
Outdated
exception.Data[ErrorDetailsDataKey] = message.ErrorDetails?.GetRawText();
exception.Data[LogDataKey] = message.Log;
callback.TaskCompletionSource.TrySetException(exception);
}
Expand Down
Loading