_DLiteView2CtrlEvents 60+ events fired by the LiteView2 OCX control
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.
Print & Capture Events
2 events
| Event | Parameters | Description |
|---|---|---|
| PrintToPdfCompleted | filePath As String, success As Boolean | PDF generation finished. |
| CaptureScreenshotCompleted | filePath As String, success As Boolean | Screenshot captured. |
Per-Event Usage
' PrintToPdfCompleted — PDF generation finished
Private Sub LiteView2Ctrl1_PrintToPdfCompleted(ByVal filePath As String, ByVal success As Boolean)
If success Then
lblStatus.Caption = "PDF: " & filePath
Else
lblStatus.Caption = "PDF generation failed."
End If
End Sub
' CaptureScreenshotCompleted — screenshot saved
Private Sub LiteView2Ctrl1_CaptureScreenshotCompleted(ByVal filePath As String, ByVal success As Boolean)
If success Then Shell "explorer """ & filePath & """", vbNormalFocus
End Sub
Window & UI Events
7 events
| Event | Parameters | Description |
|---|---|---|
| NewWindowRequested Cancelable | url As String, Cancel As Boolean | Popup window requested. Set Cancel = True to block. |
| WindowCloseRequested | (none) | window.close() called from JS. |
| ScriptDialogOpening | message As String, dialogType As Long | alert/confirm/prompt dialog. |
| ContainsFullScreenElementChanged | containsFullScreenElement As Boolean | Fullscreen state changed. |
| StatusBarTextChanged | statusText As String | Status bar text changed. |
| ZoomFactorChanged | newZoomFactor As Double | Zoom level changed. |
| FaviconChanged | faviconUri As String | Page favicon changed. |
Per-Event Usage
' NewWindowRequested — popup requested (cancelable)
Private Sub LiteView2Ctrl1_NewWindowRequested(ByVal url As String, Cancel As Boolean)
Cancel = True ' block popup
m_lv.Navigate url ' load in same window instead
End Sub
' WindowCloseRequested — window.close() called from JS
Private Sub LiteView2Ctrl1_WindowCloseRequested()
DoCmd.Close acForm, Me.Name
End Sub
' ScriptDialogOpening — alert/confirm/prompt (type: 0=alert,1=confirm,2=prompt)
Private Sub LiteView2Ctrl1_ScriptDialogOpening(ByVal message As String, _
ByVal dialogType As Long)
Debug.Print "Dialog type " & dialogType & ": " & message
End Sub
' ContainsFullScreenElementChanged — fullscreen video etc.
Private Sub LiteView2Ctrl1_ContainsFullScreenElementChanged( _
ByVal containsFullScreenElement As Boolean)
Debug.Print "Fullscreen: " & containsFullScreenElement
End Sub
' StatusBarTextChanged — hover link text
Private Sub LiteView2Ctrl1_StatusBarTextChanged(ByVal statusText As String)
lblStatus.Caption = statusText
End Sub
' ZoomFactorChanged — zoom level changed
Private Sub LiteView2Ctrl1_ZoomFactorChanged(ByVal newZoomFactor As Double)
lblZoom.Caption = Format(newZoomFactor * 100, "0") & "%"
End Sub
' FaviconChanged — page favicon updated
Private Sub LiteView2Ctrl1_FaviconChanged(ByVal faviconUri As String)
Debug.Print "Favicon: " & faviconUri
End Sub
Download Events
5 events
| Event | Parameters | Description |
|---|---|---|
| DownloadStarting Cancelable | url, suggestedFileName As String, totalBytes As Long, mimeType As String, Cancel As Boolean, resultFilePath As String | Download about to begin. Cancel = True to block. Set resultFilePath to change save location. |
| DownloadProgressChanged | downloadId As Long, bytesReceived As Long, totalBytes As Long, state As Long | Download progress update. |
| DownloadCompleted | downloadId As Long, filePath As String, success As Boolean, interruptReason As Long | Download finished. |
| IsDefaultDownloadDialogOpenChanged | (none) | Download dialog state changed. |
| SaveAsUIShowing Cancelable | Cancel As Boolean | Save As dialog about to show. |
Per-Event Usage
' DownloadStarting — download about to begin (cancelable)
Private Sub LiteView2Ctrl1_DownloadStarting(ByVal url As String, _
ByVal suggestedFileName As String, ByVal totalBytes As Long, _
ByVal mimeType As String, Cancel As Boolean, resultFilePath As String)
Debug.Print suggestedFileName & " (" & totalBytes & " bytes, " & mimeType & ")"
' Cancel = True to block; set resultFilePath to redirect save location
End Sub
' DownloadProgressChanged — progress update (state: 0=InProgress,1=Interrupted,2=Completed)
Private Sub LiteView2Ctrl1_DownloadProgressChanged(ByVal downloadId As Long, _
ByVal bytesReceived As Long, ByVal totalBytes As Long, ByVal state As Long)
If totalBytes > 0 Then
lblProgress.Caption = Format(bytesReceived / totalBytes * 100, "0") & "%"
End If
End Sub
' DownloadCompleted — download finished
Private Sub LiteView2Ctrl1_DownloadCompleted(ByVal downloadId As Long, _
ByVal resultFilePath As String, ByVal success As Boolean, _
ByVal interruptReason As Long)
If success Then Debug.Print "Saved: " & resultFilePath
End Sub
' IsDefaultDownloadDialogOpenChanged — download dialog toggled
Private Sub LiteView2Ctrl1_IsDefaultDownloadDialogOpenChanged()
Debug.Print "Dialog open: " & m_lv.IsDownloadDialogOpen
End Sub
' SaveAsUIShowing — Save As dialog about to show (cancelable)
Private Sub LiteView2Ctrl1_SaveAsUIShowing(Cancel As Boolean)
Cancel = True ' suppress Save As dialog
End Sub
Authentication Events
3 events
| Event | Parameters | Description |
|---|---|---|
| BasicAuthenticationRequested | uri, challenge As String, username As String, password As String, handled As Boolean | Server requests HTTP Basic Auth credentials. |
| ClientCertificateRequested | uri As String, handled As Boolean | Client certificate requested. |
| ServerCertificateErrorDetected | uri As String, errorStatus As Long, certificateSubject As String, action As Long | SSL/TLS certificate error. |
Per-Event Usage
' BasicAuthenticationRequested — HTTP Basic Auth challenge
Private Sub LiteView2Ctrl1_BasicAuthenticationRequested(ByVal uri As String, _
ByVal challenge As String, username As String, _
password As String, handled As Boolean)
username = "admin": password = "secret": handled = True
End Sub
' ClientCertificateRequested — client certificate needed
Private Sub LiteView2Ctrl1_ClientCertificateRequested(ByVal uri As String, _
handled As Boolean)
Debug.Print "Client cert requested for: " & uri
End Sub
' ServerCertificateErrorDetected — SSL/TLS error (action: 0=Default, 1=AlwaysAllow)
Private Sub LiteView2Ctrl1_ServerCertificateErrorDetected(ByVal uri As String, _
ByVal errorStatus As Long, ByVal certificateSubject As String, _
action As Long)
Debug.Print "SSL error " & errorStatus & " for " & certificateSubject
action = 1 ' allow (for dev/testing only)
End Sub
Process Events
2 events
| Event | Parameters | Description |
|---|---|---|
| ProcessFailed | processKind As Long, reason As Long, exitCode As Long, reasonMessage As String, frameInfo As String | Browser process crashed or exited unexpectedly. |
| BrowserProcessExited | exitKind As Long, processId As Long | Browser process exited. |
Per-Event Usage
' ProcessFailed — browser crashed or exited unexpectedly
Private Sub LiteView2Ctrl1_ProcessFailed(ByVal processKind As Long, _
ByVal reason As Long, ByVal exitCode As Long, _
ByVal reasonMessage As String, ByVal frameInfo As String)
MsgBox "Process crashed: " & reasonMessage, vbCritical
End Sub
' BrowserProcessExited — browser process terminated
Private Sub LiteView2Ctrl1_BrowserProcessExited(ByVal exitKind As Long, _
ByVal processId As Long)
Debug.Print "Process " & processId & " exited (kind=" & exitKind & ")"
End Sub
Web Resource Events
2 events
| Event | Parameters | Description |
|---|---|---|
| WebResourceRequested Cancelable | uri, method As String, resourceContext As Long, Cancel As Boolean | Intercepted request (requires AddWebResourceRequestedFilter). Cancel = True to block. |
| WebResourceResponseReceived | uri As String, statusCode As Long, reasonPhrase As String | Response received for tracked request. |
Per-Event Usage
' WebResourceRequested — intercepted request (cancelable)
' Requires AddWebResourceRequestedFilter to be called first
Private Sub LiteView2Ctrl1_WebResourceRequested(ByVal uri As String, _
ByVal method As String, ByVal resourceContext As Long, _
Cancel As Boolean)
If InStr(uri, "tracking.js") > 0 Then Cancel = True
End Sub
' WebResourceResponseReceived — response info for tracked request
Private Sub LiteView2Ctrl1_WebResourceResponseReceived(ByVal uri As String, _
ByVal statusCode As Long, ByVal reasonPhrase As String)
If statusCode >= 400 Then Debug.Print "HTTP " & statusCode & ": " & uri
End Sub
Find Events
3 events
| Event | Parameters | Description |
|---|---|---|
| FindMatchCountChanged | matchCount As Long | Total match count updated during find. |
| FindActiveMatchChanged | activeMatchIndex As Long | Active/current match changed. |
| FindCompleted | matchCount As Long | Find session completed. |
Per-Event Usage
' FindMatchCountChanged — total match count updated
Private Sub LiteView2Ctrl1_FindMatchCountChanged(ByVal matchCount As Long)
lblMatchCount.Caption = m_lv.FindActiveMatchIndex & " of " & matchCount
End Sub
' FindActiveMatchChanged — current highlighted match changed
Private Sub LiteView2Ctrl1_FindActiveMatchChanged(ByVal activeMatchIndex As Long)
lblMatchCount.Caption = activeMatchIndex & " of " & m_lv.FindMatchCount
End Sub
' FindCompleted — find session finished
Private Sub LiteView2Ctrl1_FindCompleted(ByVal matchCount As Long)
If matchCount = 0 Then lblStatus.Caption = "No matches."
End Sub
Frame (iFrame) Events
4 events
| Event | Parameters | Description |
|---|---|---|
| FrameCreated | frameName, frameId As String | New iFrame created in page. |
| FrameNavigationStarting Cancelable | frameId, uri As String, isRedirected As Boolean, Cancel As Boolean | iFrame navigating. Cancel = True to block. |
| FrameNavigationCompleted | frameId, uri As String, success As Boolean, webErrorStatus As Long | iFrame navigation completed. |
| FrameDestroyed | frameId As String | iFrame removed from DOM. |
Per-Event Usage
' FrameCreated — new iFrame created
Private Sub LiteView2Ctrl1_FrameCreated(ByVal frameName As String, _
ByVal frameId As String)
Debug.Print "Frame created: " & frameName & " (id=" & frameId & ")"
End Sub
' FrameNavigationStarting — iFrame navigating (cancelable)
Private Sub LiteView2Ctrl1_FrameNavigationStarting(ByVal frameId As String, _
ByVal uri As String, ByVal isRedirected As Boolean, Cancel As Boolean)
If InStr(uri, "ads.example.com") > 0 Then Cancel = True
End Sub
' FrameNavigationCompleted — iFrame finished loading
Private Sub LiteView2Ctrl1_FrameNavigationCompleted(ByVal frameId As String, _
ByVal uri As String, ByVal success As Boolean, _
ByVal webErrorStatus As Long)
If Not success Then Debug.Print "Frame failed: " & uri
End Sub
' FrameDestroyed — iFrame removed
Private Sub LiteView2Ctrl1_FrameDestroyed(ByVal frameId As String)
Debug.Print "Frame destroyed: " & frameId
End Sub
Input Events
9 events
| Event | Parameters | Description |
|---|---|---|
| Click | (none) | Control clicked. |
| DblClick | (none) | Control double-clicked. |
| KeyPress | keyCode As Long | Key pressed while control has focus. |
| MouseEnter | (none) | Mouse entered control area. |
| MouseLeave | (none) | Mouse left control area. |
| GotFocus | (none) | Control received focus. |
| LostFocus | (none) | Control lost focus. |
| AcceleratorKeyPressed | keyEventKind As Long, virtualKey As Long, keyEventLParam As Long, handled As Boolean | Keyboard accelerator pressed. |
| MoveFocusRequested | reason As Long, Handled As Boolean | Focus move requested (Tab/Shift+Tab). |
Per-Event Usage
' Click / DblClick — control mouse events
Private Sub LiteView2Ctrl1_Click()
Debug.Print "Click"
End Sub
Private Sub LiteView2Ctrl1_DblClick()
Debug.Print "Double-click"
End Sub
' KeyPress — key pressed while control has focus
Private Sub LiteView2Ctrl1_KeyPress(ByVal keyCode As Long)
Debug.Print "Key: " & keyCode & " (" & Chr(keyCode) & ")"
End Sub
' MouseEnter / MouseLeave — mouse hover tracking
Private Sub LiteView2Ctrl1_MouseEnter()
Me.LiteView2Ctrl1.BorderColor = vbBlue
End Sub
Private Sub LiteView2Ctrl1_MouseLeave()
Me.LiteView2Ctrl1.BorderColor = vbBlack
End Sub
' GotFocus / LostFocus — focus tracking
Private Sub LiteView2Ctrl1_GotFocus()
Debug.Print "WebView got focus"
End Sub
Private Sub LiteView2Ctrl1_LostFocus()
Debug.Print "WebView lost focus"
End Sub
' AcceleratorKeyPressed — keyboard shortcut (handled=True to consume)
Private Sub LiteView2Ctrl1_AcceleratorKeyPressed(ByVal keyEventKind As Long, _
ByVal virtualKey As Long, ByVal keyEventLParam As Long, _
handled As Boolean)
If virtualKey = 116 Then handled = True ' block F5 refresh
End Sub
' MoveFocusRequested — Tab/Shift+Tab out of WebView
Private Sub LiteView2Ctrl1_MoveFocusRequested(ByVal reason As Long, _
Handled As Boolean)
' reason: 0=Next, 1=Previous
Handled = True ' keep focus in WebView
End Sub
Permission & Security Events
6 events
| Event | Parameters | Description |
|---|---|---|
| PermissionRequested | uri As String, permissionKind As Long, isUserInitiated As Boolean, state As Long | Permission requested (camera, mic, location, etc.). |
| ContextMenuRequested | args As Object | Right-click context menu. args has LocationX, LocationY, PageUri, LinkUri, Handled properties. |
| LaunchingExternalUriScheme Cancelable | uri As String, Cancel As Boolean | Navigation to external scheme (mailto:, tel:, etc.). |
| NotificationReceived | notification As String | Browser notification received. |
| ScreenCaptureStarting Cancelable | Cancel As Boolean | Screen capture about to start. |
| SaveFileSecurityCheckStarting Cancelable | filePath As String, Cancel As Boolean | Save file security check. |
Per-Event Usage
' PermissionRequested — camera, mic, location, etc.
Private Sub LiteView2Ctrl1_PermissionRequested(ByVal uri As String, _
ByVal permissionKind As Long, ByVal isUserInitiated As Boolean, _
state As Long)
' state: 0=Default, 1=Allow, 2=Deny
state = 2 ' deny all permissions
End Sub
' ContextMenuRequested — right-click menu
Private Sub LiteView2Ctrl1_ContextMenuRequested(ByVal args As Object)
Debug.Print "Right-click at " & args.LocationX & "," & args.LocationY
args.Handled = True ' suppress default menu
End Sub
' LaunchingExternalUriScheme — mailto:, tel:, etc. (cancelable)
Private Sub LiteView2Ctrl1_LaunchingExternalUriScheme(ByVal uri As String, _
Cancel As Boolean)
If Left(uri, 4) <> "tel:" Then Cancel = True ' only allow tel: links
End Sub
' NotificationReceived — browser notification
Private Sub LiteView2Ctrl1_NotificationReceived(ByVal notification As String)
Debug.Print "Notification: " & notification
End Sub
' ScreenCaptureStarting — screen capture about to start (cancelable)
Private Sub LiteView2Ctrl1_ScreenCaptureStarting(Cancel As Boolean)
Cancel = True ' block screen sharing
End Sub
' SaveFileSecurityCheckStarting — file save security check (cancelable)
Private Sub LiteView2Ctrl1_SaveFileSecurityCheckStarting(ByVal filePath As String, _
Cancel As Boolean)
If Right(filePath, 4) = ".exe" Then Cancel = True ' block exe downloads
End Sub
Audio Events
2 events
| Event | Parameters | Description |
|---|---|---|
| IsMutedChanged | isMuted As Boolean | Mute state changed. |
| IsDocumentPlayingAudioChanged | isPlayingAudio As Boolean | Audio playback state changed. |
Per-Event Usage
' IsMutedChanged — mute state toggled
Private Sub LiteView2Ctrl1_IsMutedChanged(ByVal isMuted As Boolean)
btnMute.Caption = IIf(isMuted, "Unmute", "Mute")
End Sub
' IsDocumentPlayingAudioChanged — audio playback started/stopped
Private Sub LiteView2Ctrl1_IsDocumentPlayingAudioChanged(ByVal isPlayingAudio As Boolean)
lblAudio.Visible = isPlayingAudio
End Sub
CAPTCHA Events
2 events
| Event | Parameters | Description |
|---|---|---|
| CaptchaDetected | captchaType, siteKey, pageUrl As String | CAPTCHA challenge detected on current page. |
| CaptchaSolved | token As String, success As Boolean | CAPTCHA challenge resolution completed. |
Per-Event Usage
' CaptchaDetected — CAPTCHA found on page
Private Sub LiteView2Ctrl1_CaptchaDetected(ByVal captchaType As String, _
ByVal siteKey As String, ByVal pageUrl As String)
Debug.Print captchaType & " detected on " & pageUrl
m_lv.SolveCaptcha 30000 ' auto-solve with 30s timeout
End Sub
' CaptchaSolved — CAPTCHA resolution completed
Private Sub LiteView2Ctrl1_CaptchaSolved(ByVal token As String, _
ByVal success As Boolean)
If success Then m_lv.SubmitCaptchaToken token
End Sub
VB6/Hex Variants
5 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 Long
Private Sub LiteView2Ctrl1_NavigationCompletedHex(ByVal NavigationId As String)
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 event
Private Sub m_lv_DevToolsProtocolEventReceived(ByVal eventName As String, ByVal eventDataJson As String)
If eventName = "Network.requestWillBeSent" Then
Debug.Print "Network request: " & m_lv.JsonGetValue(eventDataJson, "request.url")
End If
End Sub