Jump to content
domus

Does WebView2 function when inside an app launched with SW_HIDE command?

Recommended Posts

(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 by domus

Share this post


Link to post

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.

  • Like 1

Share this post


Link to post

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. :classic_rolleyes:

 

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

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

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
3 minutes ago, Pawel Piotrowski said:

WebBrowser1.HandleNeeded;

Can't find that method for WebView2. Deprecated...?

Share this post


Link to post
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×