Page 1 of 1

ResultObjectAsJson is empty

Posted: Tue Feb 08, 2022 11:05 pm
by brche
I am converting a Delphi application that is currently using TWebBrowser to use TWVBrowser.
Looking at the Demos I think it is fairly straightforward; however, when converting my JavaScript calls, I do not seem to be getting the results back.
I added an OnExecuteScriptCompleted handler; but I only get {} back in aResultObjectAsJson.

Re: ResultObjectAsJson is empty

Posted: Wed Feb 09, 2022 9:29 am
by salvadordf
Hi,

That could be caused by several reasons.

Run the JavaScript code in the DevTools console to see if it works as expected.

This is what the WebView2 API has to say about the ExecuteScript function :
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.1072.54#executescript
A function that has no explicit return value returns undefined. If the script that was run throws an unhandled exception, then the result is also "null". This method is applied asynchronously. If the method is run after the NavigationStarting event during a navigation, the script runs in the new document when loading it, around the time ContentLoading is run. This operation executes the script even if ICoreWebView2Settings::IsScriptEnabled is set to FALSE.
See the TWVBrowserBase.RetrieveHTML and TWVBrowserBase.doOnRetrieveHTMLCompleted functions to see a full ExecuteScript example.

Re: ResultObjectAsJson is empty

Posted: Wed Feb 09, 2022 7:06 pm
by brche
Thanks Salvador,
The problem was as simple as missing the () after the script. With TWebBrowser, we do not need them.

Brian