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.

WebView4 Update - wrt 'about:blank'

Post Reply
rgdawson
Posts: 22
Joined: Tue Apr 10, 2018 11:05 pm

WebView4 Update - wrt 'about:blank'

Post by rgdawson »

This change

* Navigate to "about:blank" in TWVBrowser if the user doesn't specify a default URL.

broke my app. I'm not sure precisely why, yet, perhaps some of my event handlers did not like when it navigated to 'about:blank'. It was easy enough to overcome, I just need to set DefaultUrl := '' in my WvBrowser.AfterCreated event handler. Why not leave it blank if it is blank?

R Greg Dawson
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: WebView4 Update - wrt 'about:blank'

Post by salvadordf »

Hi,

Sorry for causing you this problem.

The last update has several events to intercept some messages and they require replacing some WndPrcs for some internal windows created by Chromium to render the web contents.

CEF has a TChromium.OnRenderViewReady event that it's triggered when those windows are ready and we can replace all WndPrcs in that event but I couldn't find a good replacement for that event in WebView2. TWVBRowser.OnAfterCreated is called too soon for this.

WebView2 navigates internally to about:blank when a browser is created so I thought that we could use the TWVBRowser.OnNavigationStarting event but that event is only triggered if we call TWVBrowser.Navigate manually.

For this reason I decided to set about:blank as the value for the DefaultURL property because TWVBrowser calls Navigate with a DefaultURL parameter when it's initialized and this triggers the TWVBRowser.OnNavigationStarting event where we replace all the WndPrcs.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: WebView4 Update - wrt 'about:blank'

Post by salvadordf »

I just saw a second complaint about this.
I'll revert that change in the next update.
rgdawson
Posts: 22
Joined: Tue Apr 10, 2018 11:05 pm

Re: WebView4 Update - wrt 'about:blank'

Post by rgdawson »

salvadordf wrote: Tue Dec 21, 2021 8:52 am Hi,

Sorry for causing you this problem.

The last update has several events to intercept some messages and they require replacing some WndPrcs for some internal windows created by Chromium to render the web contents.

CEF has a TChromium.OnRenderViewReady event that it's triggered when those windows are ready and we can replace all WndPrcs in that event but I couldn't find a good replacement for that event in WebView2. TWVBRowser.OnAfterCreated is called too soon for this.

WebView2 navigates internally to about:blank when a browser is created so I thought that we could use the TWVBRowser.OnNavigationStarting event but that event is only triggered if we call TWVBrowser.Navigate manually.

For this reason I decided to set about:blank as the value for the DefaultURL property because TWVBrowser calls Navigate with a DefaultURL parameter when it's initialized and this triggers the TWVBRowser.OnNavigationStarting event where we replace all the WndPrcs.
I spent a little time trying to see what is going wrong. I see that you are going to revert it, but I thought I might share what I am seeing in my logging data.

In my app, I call CreateBrowser in FormShow, but I do not see any immediate evidence of internal navigation to about:blank. Later, after I get my own app all initialized, and I make my own call to Navigate, about:blank appears and my own call to Navigate gets messed up. It appears to get changed to about:blank somewhere between Starting and Complete. Here is what I see, after I call Navigate:

Code: Select all

INFO   17:48:22.981  Call Navigate('http://10.0.0.136:9000/material/')
INFO   17:48:23.015  OnNavigationStarting, Args.URI = http://10.0.0.136:9000/material/
INFO   17:48:23.015  OnNavigationCompleted,  Args.URI = about:blank
INFO   17:48:23.017  OnNavigationStarting, Args.URI = about:blank
INFO   17:48:23.018  OnNavigationCompleted,  Args.URI = about:blank
Hope that helps.

R Greg Dawson
rgdawson
Posts: 22
Joined: Tue Apr 10, 2018 11:05 pm

Re: WebView4 Update - wrt 'about:blank'

Post by rgdawson »

I swapped back and forth between *before* the about:blank change and *after*. Two "By the way" things I noticed.

(1) Even in the *before* version, if I set Default Url to 'about:blank' I get similar behavior. I guess that seems expected.
(2) On a fresh Windows 11 install, which has an old version of the WebView2 runtime, the *before* version would not initialize WebView2 saying that it was not installed correctly (no matter what I set for TargetCompatibleBrowserVersion. Using the *after* version, on a fresh Windows 11 install, WebView2 initialized fine, again no matter what I set for TargetCompatibleBrowserVersion. Obviously, I like the latter. (So, I guess don't revert *everything*). :)
Post Reply