Open TcT2k opened 4 years ago
Hi @TcT2k,
This is actually the desired behavior, for now ...
We only support values that can be serialized to JSON, and anything else, including undefined, gets returned as null. We do get more information from CDP, but (especially in the case of errors), we discard it to stay backwards compatible with a previous non-CDP implementation of ExecuteScript that returned null for these kinds of values.
Updating this behavior will be a breaking change, which is something we are more than willing to explore. I'll circle back to this thread if we update this behavior!
Looks like Date objects being returned as {} is a quirk of CDP. I'm not sure there's any way to work around this on the C++ side, but in the Javascript you can work around it by calling toString() on the Date.
@quietfanatic
Looks like Date objects being returned as {} is a quirk of CDP. I'm not sure there's any way to work around this on the C++ side, but in the Javascript you can work around it by calling toString() on the Date.
Sure that's an easy workaround, would just be nice to have scripts the same regardless which webview get's used.
@pagoe-msft
Thanks for the answer (not really sure what CDP stands for). I know the ExecuteScript
documentation stats that it only returns JSON serialized values, but it was still surprising to me that a simple string was returned JSON encoded. Maybe some variant of ExecuteScript
could be added that returns the results more "raw", because that would enable the host application to just use a returned string without having to decode it first.
While I am integrating WebView2 into wxWidgets somebody came across the following discrepancies in javascript return values between Edge and Edge via WebView2 APIs ExecuteScript(). I'm pretty sure these are a problem in the WebView2 API:
A small javascript
function f(){var person = new Object();}f();
returns this:This script returns
function f(){var d = new Date('10/08/2017 21:30:40'); var tzoffset = d.getTimezoneOffset() * 60000; return new Date(d.getTime() - tzoffset);}f();
:https://github.com/wxWidgets/wxWidgets/pull/1700#issuecomment-575794999
AB#28632017