czWebview — Full-Featured WebView2 UserControl for VB6

Embed modern web content (HTML5, CSS3, ES6+) in your VB6 applications using the Microsoft Edge WebView2 Runtime. Zero external dependencies beyond a single DLL, no OCX registration required — just add the source files to your project and go.

GitHub Repository • MIT License

Why another WebView2 control?

Existing solutions for embedding a modern browser in VB6 are either commercial, require OCX registration, or don't expose enough of the WebView2 API. czWebview takes a different approach:

  • Pure source-code embed — just add one .ctl, one .cls, and one .tlb to your project. No registration, no installer headaches.
  • Complete API surface — 44 callback interfaces, 29 events, 34 public methods, and 48 properties. This matches (and is inspired by) wqweto's excellent cWebView2 class.
  • Synchronous & Asynchronous — Execute JavaScript and get results synchronously via a message pump, or go fully async with event-based callbacks.
  • Bidirectional JavaScript Bridge — PostWebMessage / chrome.webview.postMessage for clean VB6 ? JS communication.
  • Host Objects — Expose your VB6 COM objects directly to JavaScript.


Feature Highlights

  • Navigation — Navigate, GoBack, GoForward, Reload, Stop, NavigateToString (render HTML directly), synchronous NavigateSync
  • JavaScript Execution — ExecuteScript (sync with JSON result), ExecuteScriptAsync, AddScriptToExecuteOnDocumentCreated
  • Print & Capture — PrintToPdf, ShowPrintUI (browser or system dialog), CapturePreview (screenshot as PNG/JPG byte array)
  • Cookie Management — GetCookies, AddOrUpdateCookie, DeleteCookies, DeleteAllCookies
  • Downloads — DownloadStarting event with custom file path support
  • DevTools Protocol — CallDevToolsProtocolMethod for direct CDP calls (device emulation, network throttling, etc.)
  • Resource Filtering — AddWebResourceRequestedFilter + WebResourceRequested event for ad-blocking, request interception, etc.
  • Virtual Host Mapping — Serve local files via SetVirtualHostNameToFolderMapping (e.g., map "app.local" ? App.Path & "\www")
  • Authentication — BasicAuthenticationRequested event
  • Permissions — PermissionRequested event (camera, mic, geolocation, etc.)
  • Script Dialogs — ScriptDialogOpening event (intercept alert/confirm/prompt)
  • Memory Management — TrySuspend / ResumeFromSuspend for background tabs
  • Browsing Data — ClearBrowsingData (cache, cookies, history, passwords, and more)
  • UI Control — Mute/unmute audio, zoom control, user agent customization, status bar, full-screen detection, context menu events


Requirements

  • VB6 IDE (SP6 recommended)
  • WebView2 Runtime — pre-installed on Windows 10 (1803+) and Windows 11
  • WebView2Loader.dll — included in the repository (~115 KB, x86)
  • czWebview.tlb — pre-compiled and included, or rebuild with the included compile_tlb.bat (requires Windows SDK / MIDL)


Quick Start

1. Add to your project:
Code:
Project ? Add User Control ? Existing ? select src\czWebview.ctl
Project ? Add Class Module ? Existing ? select src\czWebviewCallback.cls
Project ? References ? Browse ? select typelib\czWebview.tlb
Place WebView2Loader.dll next to your .exe (or in App.Path)
2. Handle events:
[CODE=vb6]
Private Sub czWebview1_InitComplete(ByVal Success As Boolean, ByVal ErrorCode As Long)
If Success Then
czWebview1.Navigate "https://www.google.com"
Else
MsgBox "WebView2 init failed: &H" & Hex$(ErrorCode), vbCritical
End If
End Sub

Private Sub czWebview1_TitleChanged(ByVal Title As String)
Me.Caption = Title
End Sub

Private Sub czWebview1_NavigationCompleted(ByVal IsSuccess As Boolean, ByVal WebErrorStatus As Long)
lblStatus.Caption = IIf(IsSuccess, "Done", "Error: " & WebErrorStatus)
End Sub

Private Sub czWebview1_WebMessageReceived(ByVal Message As String, ByVal IsJSON As Boolean)
Debug.Print "From JS: " & Message
End Sub
[/CODE]

3. JavaScript Bridge:
[CODE=vb6]
' VB6 ? JavaScript
Dim result As String
result = czWebview1.ExecuteScript("document.title")
' result = """My Page Title"""

' Send message to page
czWebview1.PostWebMessageAsString "Hello from VB6!"
czWebview1.PostWebMessageAsJSON "{""action"":""update"",""value"":42}"
[/CODE]

[CODE=javascript]
// JavaScript ? VB6
chrome.webview.postMessage("Hello from JavaScript!");

// Listen for messages from VB6
chrome.webview.addEventListener('message', function(e) {
console.log('From VB6:', e.data);
});
[/CODE]

More Examples

Screenshot to file:
[CODE=vb6]
Dim baPng() As Byte
baPng = czWebview1.CapturePreview(czCaptureAs_PNG)
Open "screenshot.png" For Binary As #1
Put #1, , baPng
Close #1
[/CODE]

Save page as PDF:
[CODE=vb6]
If czWebview1.PrintToPdf("C:\output\page.pdf") Then
MsgBox "PDF saved!"
End If
[/CODE]

Cookie management:
[CODE=vb6]
' Add a cookie
czWebview1.AddOrUpdateCookie "session", "abc123", ".example.com", "/", , True, True

' Get all cookies for a URL
Dim cCookies As Collection
Set cCookies = czWebview1.GetCookies("https://example.com")
Dim cItem As Collection
For Each cItem In cCookies
Debug.Print cItem("Name") & " = " & cItem("Value")
Next

' Clear all cookies
czWebview1.DeleteAllCookies
[/CODE]

Block specific URLs (ad-blocking, etc.):
[CODE=vb6]
Private Sub Form_Load()
czWebview1.AddWebResourceRequestedFilter "*.ads.example.com/*"
End Sub

Private Sub czWebview1_WebResourceRequested(ByVal URI As String, _
ByVal ResourceContext As czWebView2ResourceFilter, _
Permit As czWebView2PermissionState)
Permit = czPERMISSION_STATE_DENY
End Sub
[/CODE]

Serve local files via virtual hostname:
[CODE=vb6]
czWebview1.SetVirtualHostNameToFolderMapping "app.local", App.Path & "\www", czHostResourceAccess_ALLOW
czWebview1.Navigate "https://app.local/index.html"
[/CODE]

DevTools Protocol — Emulate mobile device:
[CODE=vb6]
Dim sResult As String
sResult = czWebview1.CallDevToolsProtocolMethod("Emulation.setDeviceMetricsOverride", _
"{""width"":375,""height"":812,""deviceScaleFactor"":3,""mobile"":true}")
[/CODE]

Project Structure

Code:
czWebview/
??? src/
?   ??? czWebview.ctl               ' Main UserControl — public API
?   ??? czWebviewCallback.cls       ' Internal callback handler (44 interfaces)
??? typelib/
?   ??? czWebview.odl               ' Interface definitions (ODL source)
?   ??? czWebview.tlb               ' Compiled type library
?   ??? compile_tlb.bat             ' Auto-compile script (uses MIDL)
??? External/
?   ??? WebView2Loader.dll          ' Microsoft x86 loader (~115 KB)
??? demo/
?   ??? SimpleTest/                 ' Simple browser demo
?   ??? WhatsappBot/                ' WhatsApp Web bot demo
??? README.md
Included Demos

  1. SimpleTest — A minimal browser with navigation (back, forward, reload, address bar). Good starting point to see how the control works.
  2. WhatsappBot — A practical demo showing WhatsApp Web automation via JavaScript bridge. Demonstrates real-world usage of ExecuteScript, WebMessageReceived, and DOM interaction.


Architecture Notes

The control is split into two files for clean separation of concerns:

  • czWebview.ctl (~1,650 lines) — The public-facing UserControl. Contains all properties, methods, events, and the synchronous message pump (SpinThreadMessagePump) that enables blocking calls while still allowing COM callbacks to arrive.
  • czWebviewCallback.cls — Implements all 44 COM callback interfaces required by the WebView2 API. Events are forwarded to the UserControl via Friend subs.


This design keeps the callback plumbing out of your face — you only interact with the clean .ctl API surface.

Credits

  • Interface patterns inspired by cWebView2 by wqweto
  • WebView2 Runtime by Microsoft


License

MIT — use it, modify it, ship it. No restrictions.

Source code and full documentation on GitHub: https://github.com/cyberzilla/czWebview

Feedback, bug reports, and contributions are welcome!