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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

RetrieveText

Post Reply
jc4golf
Posts: 32
Joined: Wed Jun 23, 2021 12:33 am

RetrieveText

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

Re: RetrieveText

Post 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".
jc4golf
Posts: 32
Joined: Wed Jun 23, 2021 12:33 am

Re: RetrieveText

Post 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.
Post Reply