Closed WhitWaldo closed 1 year ago
Your jsExpr
looks like its not returning any value (when looking at the last line, the doWork()
which does not get returned (, I'd try the following, instead of what you have above:
var jsExpr = """() => {
var val = {"name": "Playwright", "count": 5};
return val;
}""";
(there is no difference between using an arrow function and a normal function in this case, but an arrow function is more convenient)
And yes, we have the logic already in place to serialise a JavaScript value from the browser back into a .NET data structure using the generics.
You're right - I didn't transpose my example correctly.
However, I've narrowed the deserialization issue - if I'm deserializing to a class, this will work exactly as anticipated. But if I deserialize to a record, it fails with the return type mismatch exception.
I'm going to close this issue as it's no longer a feature request but a bug report, I think.
The
page.EvaluateAsync
function allows me to pass a JavaScript expression to evaluate on the page and if it were to return a primitive value like a number or string, I can retrieve the output value and use it in my selector logic.I'd like to request that this method be expanded on to allow it to deserialize JSON results as well. I'd like to pass a record into the generic type parameter (optionally decorated with the necessary
[JsonProprertyName]
attributes to match the expected property names in the response and be able to pass more than primitive results back from the JS evaluation.For example, if I wrote some JavaScript that returned the following:
I would expect Playwright to determine if the returned value is a string (assume it's been "stringified") or not (serialize it first), then deserialize to the expected type:
It looks like some sort of parsing capability is in place, but it's not quite working. Here's what I see today when trying to make this work:
This throws the following exception:
And if I serialize it first, I still get an exception (replace
return val;
withreturn JSON.stringify(val);
:But if I just have the JS expression return a primitive type:
Works fine.
Thank you for the consideration!