Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB6: UserDataFolder and UserAgent are ignored
#2
Hello,



OK, I had a look.




The first issue, setting the UserDataFolder is being ignored, because at least one instance of the WebView2 control is already created by that time. You can only set this one time and it must be before any instance has been created.




This is mostly due to a design decision mistake on my end.

At first when I build the wrapper control, I thought it was a good idea to automatically create the WebView2 control when the control is initialised. It sure seemed like a nice feature.

Boy was I wrong there.. and especially when using VB6.




This has a lot of side effects, like in the VB6 IDE it is already creating the webview2 control when in design mode. That then interferes with properties, the ability to navigate there and a variety of usability things. Even detecting design mode is problematic as it happens after that -out of process- webview2 control is created.

I did have the foresight to have a property "CreateWebViewOnCreate" that one can set to false in the OnCreate event. Sadly .. that particular event does not work in VB6 or VBA whereis it works in a variety of other programming environments.

So far I have not been able to figure out why it doesn't trigger.

This will be fixed, but at least there is a workaround now, see below.



So ... the above is a "catch 22" as the Americans say. Yes there are workarounds like always creating the AntView control dynamically, but that is ... cumbersome.




Starting with version 1.1 of the AntView control the property CreateWebViewOnCreate defaults to false.

Existing users of my control can fix that either by:

- adding CreateWebView to their logic



or



- create a new global object based on AntViewGlobal and set CreateWebViewOnCreate to True in that object. All the AntView control instances will look there when they are created.

I expect AntView 1.1 to go in public beta soon.






In recap:


Setting the UserDataFolder before creating the control with CreateWebView like below will work in the new build I will email you in a few minutes.



The code with the new build then looks like:

Code:
Private Sub Form_Load()
  EdgeWebBrowser.UserDataFolder = "C:\Users\Wil\AppData\Roaming\Soft22\WebView"
  EdgeWebBrowser.CreateWebView
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Debug.Print EdgeWebBrowser.UserDataFolder
  Debug.Print EdgeWebBrowser.UserAgent
  EdgeWebBrowser.CloseBrowserProcess
  EdgeWebBrowser.CloseWebView
End Sub





The second issue.

The UserAgent setting being ignored.

In the latest public version (1.0.111-2) you can set most properties now before the control is created. This wasn't the case in the past as for Microsoft you can't set properties for WebView2 before the out of process control has been created.

This is now handled for most properties via caching the setting in the wrapper as it otherwise makes it all a bit finicky as to determine when you can/cannot use a property.

By caching those properties for AntView you can work with those properties like normal properties... except for the UserAgent.



The UserAgent property presented a problem for me. I don't know the default/current value before the control exists.

So while I can -at least in theory- catch your setting, querying that setting before it exists would give another result as after it exists. Which is why I haven't added the caching feature for the UserAgent property.



The workaround? Set it once the control exists.

Eg. like so:

Code:
Private Sub EdgeWebBrowser_OnCreateWebviewCompleted(ByVal HResult As Long)
  EdgeWebBrowser.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0"
End Sub


Then it works.



--

Wil
Reply


Messages In This Thread
RE: VB6: UserDataFolder and UserAgent are ignored - by wila - 2022-04-17, 13:47:40

Forum Jump:


Users browsing this thread: 2 Guest(s)