You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can IJSHandle.EvaluateFunctionAsync return null ? #2805
I'm trying to use PuppeteerSharp.Dom and I believe it takes parsing approach when it comes to returning generic values as evaluation results compared to PuppeteerSharp which consider original variable type from JS and throws when requesting something like int when evaluating result is not Number so I was updating repo and got a question
Here at line 71IJSHandle.EvaluateFunctionAsync is called which is Task<JsonElement?> EvaluateFunctionAsync(string script, params object[] args)
But while I was testing I didn't see result as null a single time. For example getting non-existent smth. returns JsonElement and at that point I'm not sure what then should return null.
Looks like it's a mistake and JsonElement? must be changed to just JsonElement to remove confusion
And while I'm at it - did I get it right about translating/parsing types from evaluation results to generic types? I run some tests to check await page.EvaluateFunctionAsync<int>("() => '123'") dont work but await page.EvaluateFunctionAsync<int>("() => Number('123')") works
Yes it does. I'm mentioning it because I didn't catch an eye on anything that can return null while I was debugging.
But it's a big and complex project that I tbh can't dedicate enough time so sorry for wasting time if I'm wrong.
Basically JsonValueKind represent response and have Undefined and Null so my guess was that if some code that returns default and if it was missed during transition from JToken and result would never be null. Or it was intentional. Or there is a state when it will return null?
Yes it does. I'm mentioning it because I didn't catch an eye on anything that can return null while I was debugging. But it's a big and complex project that I tbh can't dedicate enough time so sorry for wasting time if I'm wrong.
Basically JsonValueKind represent response and have Undefined and Null so my guess was that if some code that returns default and if it was missed during transition from JToken and result would never be null. Or it was intentional. Or there is a state when it will return null?
I just rerun tests with conditional breakpoints and I didnt catch null result even once
So here is method that ensures result parsing and it's called on:
While its all syntetic there is quite a set of tests and not a single time I catch JsonElement being null
To check just copy solution, put breakpoints on mentioned lines and run all tests
I can try to aquire null result myself just to check if I'm wrong, but I need a hint how to do it as I'm not so deep into PuppeteerSharp library and dont know internals
I just catched an exception because result while calling IJSHandle.EvaluateFunctionAsync with script (element, name) => { return element.getAttribute(name) and name argument of data-address on random page, but it wasn't expected behaviour because I accidently click something and wasn't able to reproduce this, and now I'm not even sure if I closed browser windows or just did something with page or navigation that messes with it.
But I guess main question is resolved - method can return null value.
However I'm still not sure if it can return null under regular chromium state
Best I could get is JSHandle that says that it's value is null but
Activity
kblok commentedon Oct 25, 2024
I think
JsonElement?makes sense when the function returns no value at all.Regarding this:
That's part of switching to
System.Text.Jsonin v19.System.Text.Jsonis more strict than Newtonsoft.CaCTuCaTu4ECKuu commentedon Oct 25, 2024
Yes it does. I'm mentioning it because I didn't catch an eye on anything that can return null while I was debugging.
But it's a big and complex project that I tbh can't dedicate enough time so sorry for wasting time if I'm wrong.
Basically
JsonValueKindrepresent response and haveUndefinedandNullso my guess was that if some code that returnsdefaultand if it was missed during transition from JToken and result would never be null. Or it was intentional. Or there is a state when it will return null?kblok commentedon Oct 25, 2024
Do you have any example to look at?
CaCTuCaTu4ECKuu commentedon Oct 25, 2024
I just rerun tests with conditional breakpoints and I didnt catch null result even once
So here is method that ensures result parsing and it's called on:
EvaluateFunctionInternalAsync<T>- line 72IJSHandle.EvaluateFunctionAsync<T>- line 184GetAttributeAsync<T>from PuppeteerSharp.Dom.CodeGen.Partial - at line 642While its all syntetic there is quite a set of tests and not a single time I catch
JsonElementbeing nullTo check just copy solution, put breakpoints on mentioned lines and run all tests
I can try to aquire null result myself just to check if I'm wrong, but I need a hint how to do it as I'm not so deep into PuppeteerSharp library and dont know internals
CaCTuCaTu4ECKuu commentedon Oct 26, 2024
I just catched an exception because result while calling
IJSHandle.EvaluateFunctionAsyncwith script(element, name) => { return element.getAttribute(name)and name argument ofdata-addresson random page, but it wasn't expected behaviour because I accidently click something and wasn't able to reproduce this, and now I'm not even sure if I closed browser windows or just did something with page or navigation that messes with it.But I guess main question is resolved - method can return null value.
However I'm still not sure if it can return null under regular chromium state
Best I could get is JSHandle that says that it's value is null but
