Page 1 of 1

RetrieveText

Posted: Tue Jul 30, 2024 12:57 am
by jc4golf
I'm using Webview4Delphi in a project of mine (learning as I go) and I've run across an issue with RetrieveTextCompleted. After issuing RetrieveText and RetrieveTextCompleted processes it, another RetrieveTextCompleted occurs (with 'null' in aText). I can test for 'null' to exit RetrieveTextCompleted, but that should not be necessary. What would cause RetrieveTextCompleted to occur without a RetrieveText call?

Re: RetrieveText

Posted: Tue Jul 30, 2024 10:07 am
by salvadordf
Hi,

TWVBrowserBase.RetrieveText executes the following JS code depending on the aVisibleTextOnly parameter :

Code: Select all

encodeURIComponent(document.body.innerText);

Code: Select all

encodeURIComponent(document.body.textContent);
This is an asynchronous operation and it may trigger the TWVBrowserBase.OnRetrieveTextCompleted event after a while.

I couldn't reproduce this issue on static pages. Perhaps the web page is reloading automatically or the browser is navigating to another URL.

Try to execute the previous JS code in the DevTools console to see if you can debug why it's returning "null".

Re: RetrieveText

Posted: Wed Jul 31, 2024 1:35 am
by jc4golf
Turns out I was executing code against the results of the RetrieveTextCompleted event, which caused the issue. Webwiew2 doesn't allow synchronous access to those results, so I added a PostMessage to do that.