domus 1 Posted October 2, 2023 (edited) (had the audacity to ask this in StackOverflow, which was a mistake, so trying here) I know, a very esoteric and specific question, but I'm spending ages trying to figure out why none of the navigation events get triggered when I'm trying to get a web page capture inside an app that was launched with ShellExecute(0, 'open', PChar('WebpageFetcher.exe'), nil, nil, SW_HIDE), while they do get triggered when using SW_SHOW. Tried using both WVBrowser1.CreateBrowser(WVWindowParent1.Handle) and WVBrowser1.CreateWindowlessBrowser(WVWindowParent1.Handle). Both work perfectly when using SW_SHOW, but I'm guessing that because the main form is hidden when using SW_HIDE, the OnNavigationCompleted and OnCapturePreviewCompleted are not triggered. However, OnDOMContentLoaded does get triggered in all cases. Overlooking something very basic, I'm sure. I don't need to see any form, just get the capture. Might it be that, when using SW_HIDE, the app doesn't have a proper messaging loop running and these events don't get propagated...? If anyone has any pointers, appreciated. Edited October 2, 2023 by domus Share this post Link to post
Pawel Piotrowski 18 Posted October 2, 2023 What was the problem with StackOverflow ? Just curious. as for the invisible browser, I had a similar problem with the old TWebBrowser in a hidden TTabsheet on a visible TForm. I needed to show it at least once. I don't know the exact reason, but it seems it requires some message to be send to the web browser, before it will work properly. Try showing the form and then hiding it... if it works, then try to pin-point the windows message that it requires to start going. If you know it, then you can emulate it. I know, that is not a ready solution, but maybe that helps a bit. 1 Share this post Link to post
domus 1 Posted October 2, 2023 That helps a lot and was more or less my inkling. I'm proceeding in that direction now. It's just a tad frustrating that it all worked fine, until that very last bit of changing SW_SHOW into SW_HIDE. What SO is concerned, a hundred years ago, when it took off, you could start out asking a question and then (collaboratively) polish it over time, until it became something you could put inside Encyclopedia Britannica. Today, if your question doesn't immediately resemble an Encyclopedia Britannica entry, you have to put on donkey ears and sit in the corner for ten minutes (or, in SO terms, get downvoted). Discouraging. Share this post Link to post
domus 1 Posted October 2, 2023 1 hour ago, Pawel Piotrowski said: Try showing the form and then hiding it... That worked. Apparently it's a known issue, causing many headaches: https://weblog.west-wind.com/posts/2022/Jul/14/Fighting-WebView2-Visibility-on-Initialization Many thanks! Saved me a lot of time! Share this post Link to post
Pawel Piotrowski 18 Posted October 2, 2023 I had a look into my old code. To mitigate the need to show the tab I called WebBrowser1.HandleNeeded; before the call to WebBrowser1.Navigate Share this post Link to post
salvadordf 32 Posted October 2, 2023 The WebView2 feedback repository shows similar problems. I just tried to modify the TabbedBrowser demo to create the browser while WVWindowParent1 was not visible and the browser was created correctly. The navigation events worked even while the browser wasn't visible. Perhaps Microsoft fixed this recently. Share this post Link to post
domus 1 Posted October 2, 2023 3 minutes ago, Pawel Piotrowski said: WebBrowser1.HandleNeeded; Can't find that method for WebView2. Deprecated...? Share this post Link to post
domus 1 Posted October 2, 2023 5 minutes ago, salvadordf said: I just tried to modify the TabbedBrowser demo to create the browser while WVWindowParent1 was not visible and the browser was created correctly. Odd. Maybe the parent was temporarily visible...? Maybe another mechanism involved. Or I should just update the library. Share this post Link to post