Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

ResultObjectAsJson is empty

Post Reply
brche
Posts: 16
Joined: Tue Feb 08, 2022 10:29 pm

ResultObjectAsJson is empty

Post 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.
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: ResultObjectAsJson is empty

Post 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.
brche
Posts: 16
Joined: Tue Feb 08, 2022 10:29 pm

Re: ResultObjectAsJson is empty

Post by brche »

Thanks Salvador,
The problem was as simple as missing the () after the script. With TWebBrowser, we do not need them.

Brian
Post Reply