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.
RetrieveText
RetrieveText
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?
- salvadordf
- Posts: 4620
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: RetrieveText
Hi,
TWVBrowserBase.RetrieveText executes the following JS code depending on the aVisibleTextOnly parameter :
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".
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);
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
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.