Skip to content

FAQ - Frequently Asked Questions

🔄 Initialization and Creation

❓ Q1: WebView2 creation failed — what to do?

Symptom: After calling Initialize, Create or Ready events are not triggered.

Possible Causes:

  1. WebView2 Runtime not installed
  2. WebView2 version on target machine is too old
  3. UserDataFolder path conflict

Solution:

vb
' Check if WebView2 is installed
' Look for path: C:\Program Files (x86)\Microsoft\EdgeWebView\Application

' Specify minimum version number
wv.EnvironmentOptions.TargetCompatibleBrowserVersion = "86.0.616.0"

cWebView2Host has internal retry logic — up to 10 creation attempts, auto-incrementing the UserDataFolder path each time.


❓ Q2: Should Initialize take a Form object or hWnd?

Both are supported:

vb
wv.Initialize Me.hWnd, "https://vb6.pro"    ' Pass window handle
wv.Initialize Me, "https://vb6.pro"          ' Pass Form object (auto-gets hWnd)

When passing a Form object, Form.hWnd is called internally to get the window handle. The effect is exactly the same.


❓ Q3: When to use two-parameter Initialize vs one-parameter?

  • Two-parameter Initialize(hWnd, url) - Most common, auto-navigates to specified URL
  • One-parameter Initialize(hWnd) - Use when you need to configure environment parameters before navigation
vb
' Simple scenario: navigate directly
wv.Initialize Me.hWnd, "https://vb6.pro"

' Advanced scenario: need to configure environment parameters
wv.Initialize Me.hWnd    ' Don't navigate immediately

Private Sub wv_Create()
    ' Configure before navigation
    wv.EnvironmentOptions.UserDataFolder = App.Path & "\UserData"
    wv.Security.CertificateErrorAction = CEA_AlwaysAllow
End Sub

Private Sub wv_Ready()
    wv.Navigate "https://example.com"
End Sub

🔗 Data Binding

❓ Q4: Must BindUI callback methods be Public?

Yes. BindUI uses CallByName to invoke host methods — VB6's CallByName can only call Public members.

vb
' Correct
Public Sub OnClick(ByVal EventName As String, ByVal Detail As String)

' Incorrect - will not be called
Private Sub OnClick(ByVal EventName As String, ByVal Detail As String)

❓ Q5: How to get DOM element values with BindUI?

The Detail parameter contains JSON-formatted event details that vary by event type. Manual parsing is required:

vb
Public Sub OnNameInput(ByVal EventName As String, ByVal Detail As String)
    ' Detail example: {"type":"input","value":"User input text"}
    Dim val As String
    val = JsonValue(Detail, "value")
    wv.SetData "name", val
End Sub

❓ Q6: Can SetData pass arrays or objects?

SetData's Value parameter is Variant, internally generating a JS literal directly. There are two approaches for complex structures:

vb
' Method 1: Use innerHTML attribute binding
wv.BindData "list", "#item-list", "innerHTML"
wv.SetData "list", "<li>Item 1</li><li>Item 2</li>"

' Method 2: Call JS function to process JSON
wv.JsRun "renderList(" & jsonString & ")"

⚡ JavaScript Execution

❓ Q7: What's the difference between JsRun and ExecuteScript?

FeatureJsRunExecuteScript
Execution modeSynchronous (blocking wait)Asynchronous (event callback)
Return valueDirect String returnJsAsyncResult event
WithEventsNot requiredRecommended
Typical scenarioGet result immediatelyDon't need to wait for result

❓ Q8: What's the difference between JsRun and Script.Eval?

FeatureJsRunScript.Eval
InputJS expression/property pathJS code block (supports return)
WrappingDirect executionWrapped as function, then executed
Usagewv.JsRun("document.title")wv.Script.Eval("return document.title")
Best forSimple expressionsComplex code blocks

Script.Eval wraps code as function EvalFuncName(){...}, injects and calls it, so return is needed to return values.


🛡️ Security

❓ Q9: How to ignore HTTPS certificate errors?

Must be set in the Create event, before navigation starts:

vb
Dim WithEvents wv As cWebView2Host

Private Sub Form_Load()
    Set wv = New cWebView2Host
    wv.Initialize Me.hWnd, "https://self-signed.example.com/"
End Sub

Private Sub wv_Create()
    ' Set before navigation
    wv.Security.CertificateErrorAction = CEA_AlwaysAllow
End Sub

If set after the Create event, it will not take effect.


❓ Q10: How to disable DevTools and context menus?

vb
Private Sub wv_Create()
    wv.AreDevToolsEnabled = False
    wv.AreDefaultContextMenusEnabled = False
End Sub

🍪 Cookies

❓ Q11: What's the difference between GetCookies and GetCookiesFull?

MethodRetrieval MethodHttpOnly CookiesPerformance
Cookies.GetCookiesdocument.cookieNot visibleFast
Cookies.GetCookiesFullCDP Network.getCookiesVisibleSlightly slower
Cookies.GetCookiesFullAsyncCDP asyncVisibleNon-blocking

For scenarios requiring access to HttpOnly cookies, you must use GetCookiesFull or GetCookiesFullAsync.


🖥️ Host Environment

❓ Q12: What limitations exist in Access?

Access uses MessageWindowAdapter — the following features are not available:

  • Host mouse events (HostMouse*)
  • Host keyboard events (HostKeyDown/Up/Press)
  • HostFocus / HostBlur events

Workarounds:

  • Use BindUI to bind DOM events
  • Use UserMouse series events (requires EnableUserMouseEvents = True)

❓ Q13: How to share or isolate sessions across multiple WebView2 instances?

Controlled via UserDataFolder:

vb
' Shared session: same UserDataFolder
wv1.EnvironmentOptions.UserDataFolder = App.Path & "\UserData"
wv2.EnvironmentOptions.UserDataFolder = App.Path & "\UserData"

' Isolated sessions: different UserDataFolders
wv1.EnvironmentOptions.UserDataFolder = App.Path & "\UserDir\account-001"
wv2.EnvironmentOptions.UserDataFolder = App.Path & "\UserDir\account-002"

Instances sharing a session will share cookies, localStorage, etc. Isolated sessions are completely independent.


📦 Local Resource Loading

❓ Q14: How to load local HTML files?

Three methods:

vb
' Method 1: Pass local folder path (simplest)
wv.Initialize Me.hWnd, App.Path & "\www"
' Auto-maps to http://vbman2.com/index.html

' Method 2: Virtual host name mapping (recommended, supports https protocol)
wv.Initialize Me.hWnd
' In wv_Ready:
wv.SetVirtualHostNameToFolderMapping "myapp.local", App.Path & "\www"
wv.Navigate "https://myapp.local/index.html"

' Method 3: Load from VB6 resource file (single-file distribution)
wv.Initialize Me.hWnd
' In wv_Ready:
wv.NavigateToString VBMAN2.Res(LoadResData("INDEX.HTML", "WWW")).ReturnString()

❓ Q15: Cross-origin issues with AJAX requests in local HTML?

When loading via SetVirtualHostNameToFolderMapping, the page runs under the https:// protocol and can normally access external APIs of the same protocol — no file:// protocol restrictions apply.


Last Updated: 2026-06-24

VB6 and LOGO copyright of Microsoft Corporation