60+ VBA WebView2 Events — Navigation, DOM, Downloads, Auth & More
_DLiteView2CtrlEvents dispinterface — all events fired by the LiteView2 OCX control
Works in VBA (Excel, Access, Word, Outlook, PowerPoint, Visio, Project), VB6, VB.NET, C#, C++, Delphi, Python, PowerShell, AutoIt — and any COM host.
Note
In VBA, name handler subs as LiteView2Ctrl1_EventName (matching the control's Name property). Events use the design-time OCX naming convention, not WithEvents.
Tip
All JSON methods (JsonGetValue, JsonSetValue, JsonExists, etc.) use a native C++ parser — no WebView2 round-trips. They are safe to call from any event handler, including WebMessageReceived. (Earlier versions used ExecuteScript internally, which caused deadlocks. The v2 native parser eliminates this.)
Tip
Events with a Cancel As Boolean parameter are cancelable — set Cancel = True to block the action.
Events you'll use in almost every project
These three events cover most VBA-browser interaction. The remaining 56 events cover downloads, authentication, new windows, process crashes, printing, DevTools, and other advanced scenarios — they're documented below when you need them.
WebView2 engine initialized. Safe to call SetLocalContentRoot, Navigate, etc. Primary readiness signal.
NavigationStarting Cancelable
url AsString, Cancel AsBoolean
Before navigation begins. Set Cancel = True to block.
NavigationCompleted
url AsString, success AsBoolean
After navigation completes. Fires AFTER window.onload.
WebMessageReceived
message AsString, source AsString
JS called window.chrome.webview.postMessage(). Use JsonGetValue to parse the message.
DocumentTitleChanged
title AsString
Page title changed.
SourceChanged
url AsString
Source URL changed.
CreateWebViewCompleted
hResult AsLong, success AsBoolean
Controller creation complete.
Per-Event Usage
' WebViewReady � engine initialized, safe to navigatePrivate Sub LiteView2Ctrl1_WebViewReady()
m_lv.SetLocalContentRoot CurrentProject.Path & "\demos"
m_lv.Navigate "https://lv2.local/index.html"End Sub' NavigationStarting � before navigation (cancelable)Private Sub LiteView2Ctrl1_NavigationStarting(ByVal url AsString, Cancel AsBoolean)
If InStr(url, "blocked-site.com") > 0Then Cancel = TrueEnd Sub' NavigationCompleted � after page loadsPrivate Sub LiteView2Ctrl1_NavigationCompleted(ByVal url AsString, ByVal success AsBoolean)
If Not success Then lblStatus.Caption = "Failed: " & m_lv.LastError
End Sub' WebMessageReceived � JS called postMessage(). Parse with JsonGetValue.Private Sub LiteView2Ctrl1_WebMessageReceived(ByVal message AsString, ByVal source AsString)
Dim action AsVariant
action = m_lv.JsonGetValue(message, "action")
If Not IsNull(action) ThenIf action = "ready"Then m_pageReady = TrueEnd IfEnd Sub' DocumentTitleChanged � page <title> changedPrivate Sub LiteView2Ctrl1_DocumentTitleChanged(ByVal title AsString)
Me.Caption = title
End Sub' SourceChanged � URL changedPrivate Sub LiteView2Ctrl1_SourceChanged(ByVal url AsString)
txtUrl.Value = url
End Sub' CreateWebViewCompleted � controller creation finishedPrivate Sub LiteView2Ctrl1_CreateWebViewCompleted(ByVal hResult AsLong, ByVal success AsBoolean)
If Not success Then MsgBox "WebView2 creation failed: 0x" & Hex(hResult)
End Sub
WebMessageReceived — JSON Parsing
' Safe: JsonGetValue uses native C++ parser (no WebView2 round-trip, no deadlock)Private Sub LiteView2Ctrl1_WebMessageReceived(ByVal message AsString, ByVal source AsString)
Dim action AsVariant
action = m_lv.JsonGetValue(message, "action")
If Not IsNull(action) Then
Debug.Print "Action: " & action
End IfEnd Sub
▶Print & Capture Events2 events
Event
Parameters
Description
PrintToPdfCompleted
filePath AsString, success AsBoolean
PDF generation finished.
CaptureScreenshotCompleted
filePath AsString, success AsBoolean
Screenshot captured.
Per-Event Usage
' PrintToPdfCompleted � PDF generation finishedPrivate Sub LiteView2Ctrl1_PrintToPdfCompleted(ByVal filePath AsString, ByVal success AsBoolean)
If success Then
lblStatus.Caption = "PDF: " & filePath
Else
lblStatus.Caption = "PDF generation failed."End IfEnd Sub' CaptureScreenshotCompleted � screenshot savedPrivate Sub LiteView2Ctrl1_CaptureScreenshotCompleted(ByVal filePath AsString, ByVal success AsBoolean)
If success Then Shell "explorer """ & filePath & """", vbNormalFocus
End Sub
Intercepted request (requires AddWebResourceRequestedFilter). Cancel = True to block.
WebResourceResponseReceived
uri AsString, statusCode AsLong, reasonPhrase AsString
Response received for tracked request.
Per-Event Usage
' WebResourceRequested � intercepted request (cancelable)' Requires AddWebResourceRequestedFilter to be called firstPrivate Sub LiteView2Ctrl1_WebResourceRequested(ByVal uri AsString, _
ByVal method AsString, ByVal resourceContext AsLong, _
Cancel AsBoolean)
If InStr(uri, "tracking.js") > 0Then Cancel = TrueEnd Sub' WebResourceResponseReceived � response info for tracked requestPrivate Sub LiteView2Ctrl1_WebResourceResponseReceived(ByVal uri AsString, _
ByVal statusCode AsLong, ByVal reasonPhrase AsString)
If statusCode >= 400Then Debug.Print "HTTP " & statusCode & ": " & uri
End Sub
▶Find Events3 events
Event
Parameters
Description
FindMatchCountChanged
matchCount AsLong
Total match count updated during find.
FindActiveMatchChanged
activeMatchIndex AsLong
Active/current match changed.
FindCompleted
matchCount AsLong
Find session completed.
Per-Event Usage
' FindMatchCountChanged � total match count updatedPrivate Sub LiteView2Ctrl1_FindMatchCountChanged(ByVal matchCount AsLong)
lblMatchCount.Caption = m_lv.FindActiveMatchIndex & " of " & matchCount
End Sub' FindActiveMatchChanged � current highlighted match changedPrivate Sub LiteView2Ctrl1_FindActiveMatchChanged(ByVal activeMatchIndex AsLong)
lblMatchCount.Caption = activeMatchIndex & " of " & m_lv.FindMatchCount
End Sub' FindCompleted � find session finishedPrivate Sub LiteView2Ctrl1_FindCompleted(ByVal matchCount AsLong)
If matchCount = 0Then lblStatus.Caption = "No matches."End Sub
▶Frame (iFrame) Events4 events
Event
Parameters
Description
FrameCreated
frameName, frameId AsString
New iFrame created in page.
FrameNavigationStarting Cancelable
frameId, uri AsString, isRedirected AsBoolean, Cancel AsBoolean
iFrame navigating. Cancel = True to block.
FrameNavigationCompleted
frameId, uri AsString, success AsBoolean, webErrorStatus AsLong
iFrame navigation completed.
FrameDestroyed
frameId AsString
iFrame removed from DOM.
Per-Event Usage
' FrameCreated � new iFrame createdPrivate Sub LiteView2Ctrl1_FrameCreated(ByVal frameName AsString, _
ByVal frameId AsString)
Debug.Print "Frame created: " & frameName & " (id=" & frameId & ")"End Sub' FrameNavigationStarting � iFrame navigating (cancelable)Private Sub LiteView2Ctrl1_FrameNavigationStarting(ByVal frameId AsString, _
ByVal uri AsString, ByVal isRedirected AsBoolean, Cancel AsBoolean)
If InStr(uri, "ads.example.com") > 0Then Cancel = TrueEnd Sub' FrameNavigationCompleted � iFrame finished loadingPrivate Sub LiteView2Ctrl1_FrameNavigationCompleted(ByVal frameId AsString, _
ByVal uri AsString, ByVal success AsBoolean, _
ByVal webErrorStatus AsLong)
If Not success Then Debug.Print "Frame failed: " & uri
End Sub' FrameDestroyed � iFrame removedPrivate Sub LiteView2Ctrl1_FrameDestroyed(ByVal frameId AsString)
Debug.Print "Frame destroyed: " & frameId
End Sub
Navigation to external scheme (mailto:, tel:, etc.).
NotificationReceived
notification AsString
Browser notification received.
ScreenCaptureStarting Cancelable
Cancel AsBoolean
Screen capture about to start.
SaveFileSecurityCheckStarting Cancelable
filePath AsString, Cancel AsBoolean
Save file security check.
Per-Event Usage
' PermissionRequested � camera, mic, location, etc.Private Sub LiteView2Ctrl1_PermissionRequested(ByVal uri AsString, _
ByVal permissionKind AsLong, ByVal isUserInitiated AsBoolean, _
state AsLong)
' state: 0=Default, 1=Allow, 2=Deny
state = 2' deny all permissionsEnd Sub' ContextMenuRequested � right-click menuPrivate Sub LiteView2Ctrl1_ContextMenuRequested(ByVal args AsObject)
Debug.Print "Right-click at " & args.LocationX & "," & args.LocationY
args.Handled = True' suppress default menuEnd Sub' LaunchingExternalUriScheme � mailto:, tel:, etc. (cancelable)Private Sub LiteView2Ctrl1_LaunchingExternalUriScheme(ByVal uri AsString, _
Cancel AsBoolean)
If Left(uri, 4) <> "tel:"Then Cancel = True' only allow tel: linksEnd Sub' NotificationReceived � browser notificationPrivate Sub LiteView2Ctrl1_NotificationReceived(ByVal notification AsString)
Debug.Print "Notification: " & notification
End Sub' ScreenCaptureStarting � screen capture about to start (cancelable)Private Sub LiteView2Ctrl1_ScreenCaptureStarting(Cancel AsBoolean)
Cancel = True' block screen sharingEnd Sub' SaveFileSecurityCheckStarting � file save security check (cancelable)Private Sub LiteView2Ctrl1_SaveFileSecurityCheckStarting(ByVal filePath AsString, _
Cancel AsBoolean)
If Right(filePath, 4) = ".exe"Then Cancel = True' block exe downloadsEnd Sub
▶Audio Events2 events
Event
Parameters
Description
IsMutedChanged
isMuted AsBoolean
Mute state changed.
IsDocumentPlayingAudioChanged
isPlayingAudio AsBoolean
Audio playback state changed.
Per-Event Usage
' IsMutedChanged � mute state toggledPrivate Sub LiteView2Ctrl1_IsMutedChanged(ByVal isMuted AsBoolean)
btnMute.Caption = IIf(isMuted, "Unmute", "Mute")
End Sub' IsDocumentPlayingAudioChanged � audio playback started/stoppedPrivate Sub LiteView2Ctrl1_IsDocumentPlayingAudioChanged(ByVal isPlayingAudio AsBoolean)
lblAudio.Visible = isPlayingAudio
End Sub
▶CAPTCHA Events2 events
Event
Parameters
Description
CaptchaDetected
captchaType, siteKey, pageUrl AsString
CAPTCHA challenge detected on current page.
CaptchaSolved
token AsString, success AsBoolean
CAPTCHA challenge resolution completed.
Per-Event Usage
' CaptchaDetected � CAPTCHA found on pagePrivate Sub LiteView2Ctrl1_CaptchaDetected(ByVal captchaType AsString, _
ByVal siteKey AsString, ByVal pageUrl AsString)
Debug.Print captchaType & " detected on " & pageUrl
m_lv.SolveCaptcha 30000' auto-solve with 30s timeoutEnd Sub' CaptchaSolved � CAPTCHA resolution completedPrivate Sub LiteView2Ctrl1_CaptchaSolved(ByVal token AsString, _
ByVal success AsBoolean)
If success Then m_lv.SubmitCaptchaToken token
End Sub
▶VB6/Hex Variants5 events
Note
These events fire instead of their standard counterparts when EventsUseHexadecimal = True. They provide Int64 values as hex BSTR strings for VB6 compatibility.
Event
Parameters
Description
NavigationCompletedHex
NavigationId as hex BSTR
Hex variant of NavigationCompleted.
ContentLoadingHex
NavigationId as hex BSTR
Hex variant of ContentLoading.
DownloadStartingHex
totalBytes as hex BSTR
Hex variant of DownloadStarting.
DownloadProgressChangedHex
downloadId/bytes as hex BSTR
Hex variant of DownloadProgressChanged.
DownloadCompletedHex
downloadId as hex BSTR
Hex variant of DownloadCompleted.
VB6/Hex Usage
' Enable hex mode BEFORE WebView2 init (Pre-Init property)
m_lv.EventsUseHexadecimal = True' NavigationCompletedHex � NavigationId as hex string instead of LongPrivate Sub LiteView2Ctrl1_NavigationCompletedHex(ByVal NavigationId AsString)
Debug.Print "NavId (hex): " & NavigationId ' e.g. "0x1A2B3C"End Sub' ContentLoadingHex � same pattern' DownloadStartingHex � totalBytes as hex BSTR' DownloadProgressChangedHex � downloadId/bytes as hex BSTR' DownloadCompletedHex � downloadId as hex BSTR' All fire INSTEAD OF their standard counterparts when hex mode is on
DevTools Protocol
Event
Parameters
Description
DevToolsProtocolEventReceived
eventName As String, eventDataJson As String
Fired when a subscribed Chrome DevTools Protocol (CDP) event occurs. Subscribe to events using CallDevToolsProtocolMethod first, then handle incoming events here. eventName is the CDP event name (e.g. "Network.requestWillBeSent"). eventDataJson is the event payload as a JSON string.
Usage
' Subscribe to a CDP event
m_lv.CallDevToolsProtocolMethod "Network.enable", "{}"' Handle the eventPrivate Sub m_lv_DevToolsProtocolEventReceived(ByVal eventName AsString, ByVal eventDataJson AsString)
If eventName = "Network.requestWillBeSent"Then
Debug.Print "Network request: " & m_lv.JsonGetValue(eventDataJson, "request.url")
End IfEnd Sub