IBrowserPool Interface coclass BrowserPool | Multi-browser pool pattern | All methods take browserIndex As Long
IBrowserPool mirrors most of ILiteView2Ctrl's functionality but adds browserIndex As Long as the first parameter to every method. This page documents only the pool-specific methods. For shared methods (Navigate, ExecuteScript, PushRecordset, etc.), see the ILiteView2Ctrl reference — just add browserIndex as the first argument.
Getting Started — Reg-Free Setup
Before you can use IBrowserPool, add this standard module to your project. It declares the Win32 API calls needed to load the OCX without COM registration, then exposes a GetPool() singleton you can call from any form.
Place the OCX in the same folder as your .accdb or .xlsm.
modLV2Pool.bas — add once per project
Option Explicit
' --- Win32 + OCX declarations (64-bit / 32-bit) ---
#If Win64 Then
Private Declare PtrSafe Function SetDllDirectory Lib "kernel32" _
Alias "SetDllDirectoryW" (ByVal lpPathName As LongPtr) As Long
Private Declare PtrSafe Function LiteView2_ActivateManifest _
Lib "LiteView2_x64.ocx" (ByVal path As LongPtr) As Long
Private Declare PtrSafe Function LiteView2_CreateBrowserPool _
Lib "LiteView2_x64.ocx" () As Object
#Else
Private Declare PtrSafe Function SetDllDirectory Lib "kernel32" _
Alias "SetDllDirectoryW" (ByVal lpPathName As LongPtr) As Long
Private Declare PtrSafe Function LiteView2_ActivateManifest _
Lib "LiteView2_x86.ocx" (ByVal path As LongPtr) As Long
Private Declare PtrSafe Function LiteView2_CreateBrowserPool _
Lib "LiteView2_x86.ocx" () As Object
#End If
Private m_Pool As Object
Public Function GetPool() As Object
If m_Pool Is Nothing Then
Dim p As String
p = CurrentProject.Path ' Access (Excel: ThisWorkbook.Path)
SetDllDirectory StrPtr(p) ' Tell Windows where the OCX lives
#If Win64 Then
LiteView2_ActivateManifest StrPtr(p & "\LiteView2_x64.ocx")
#Else
LiteView2_ActivateManifest StrPtr(p & "\LiteView2_x86.ocx")
#End If
Set m_Pool = LiteView2_CreateBrowserPool()
m_Pool.ActivateLicense "Your Company", "YOUR-LICENSE-KEY" ' omit this line during 30-day trial
End If
Set GetPool = m_Pool
End Function
Usage from any form
Dim pool As Object
Set pool = GetPool()
' Create a browser and embed it in a Frame control
Dim idx As Long
idx = pool.CreateInControl("about:blank", Me.Frame1)
' Map a local folder to the virtual hostname https://lv2.local/
pool.SetLocalContentRoot idx, CurrentProject.Path & "\html"
' Navigate to a local HTML file
pool.Navigate idx, "https://lv2.local/dashboard.html"
SetLocalContentRoot maps a folder on disk to the virtual hostname https://lv2.local/. Files in that folder are then accessible via URLs like https://lv2.local/dashboard.html. This avoids file:// URLs (which have security restrictions) and gives your local HTML files a proper HTTPS origin. See ILiteView2Ctrl › Local Content Mapping for details.
Licensing
ActivateLicense is called once per process, before creating any browser instances. The recommended place is inside GetPool(), right after LiteView2_CreateBrowserPool():
m_Pool.ActivateLicense "Your Company", "YOUR-LICENSE-KEY"
A 30-day trial starts automatically — all features are fully functional with no limitations. After trial expiry, the control displays a watermark and API methods return E_ACCESSDENIED. Add the ActivateLicense line with your purchased key to activate immediately. No license files, no registry entries — just one line of VBA code.
Reg-Free (IBrowserPool)
' Inside GetPool(), right after LiteView2_CreateBrowserPool()
m_Pool.ActivateLicense "My Company", "LICENSE-KEY-HERE"
Registered (Design-Time Control)
' In your Form_Load or WebViewReady event
m_lv.ActivateLicense "My Company", "LICENSE-KEY-HERE"
License Status Properties
' Works on both pool and control objects
Debug.Print "Status: " & obj.LicenseStatus
Debug.Print "Type: " & obj.LicenseType
Debug.Print "State: " & obj.LicenseState ' 0=Valid, 1=Trial, 2=Expired, 3=Invalid
Debug.Print "Days: " & obj.TrialDaysRemaining
Key Difference
Every ILiteView2Ctrl method gains a browserIndex As Long first parameter on IBrowserPool:
' ILiteView2Ctrl (design-time OCX — single browser)
m_lv.Navigate "https://example.com"
m_lv.PushRecordset rs, "onData"
' IBrowserPool (multi-browser pool — add browserIndex)
pool.Navigate browserIndex, "https://example.com"
pool.PushRecordset browserIndex, rs, "onData"
Create and destroy browser instances in the pool. Each Create call returns a unique index (1, 2, 3...) or 0 on failure.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| Create | hwndParent As Long, url As String, x As Long, y As Long, width As Long, height As Long | Long | Create browser, returns index (1,2,3...) or 0 on failure |
| Destroy | browserIndex As Long | Destroy browser | |
| DestroySync | browserIndex As Long | Destroy synchronously | |
| CreateWithProfile | hwndParent As Long, url As String, x As Long, y As Long, w As Long, h As Long, profileName As String | Long | Create with named profile |
| CreateWithProfileInPrivate | hwndParent As Long, url As String, x As Long, y As Long, w As Long, h As Long, profileName As String | Long | Create with InPrivate profile |
Create & Destroy Example
Source: frmLifecycleCore_Code.txt
' Create a browser in the pool
Dim idx As Long
idx = pool.Create(Me.hwnd, "about:blank", 0, 0, 800, 600)
If idx = 0 Then
MsgBox "Failed to create browser"
Exit Sub
End If
' Map local folder to https://lv2.local/ (call once per browser)
pool.SetLocalContentRoot idx, CurrentProject.Path & "\html"
' Navigate to a local HTML file
pool.Navigate idx, "https://lv2.local/dashboard.html"
' Cleanup
pool.Destroy idx
Park browsers to hide them while preserving state for later reuse, or destroy all parked browsers at once.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| Park | browserIndex As Long | Hide browser (park) — preserves state for reuse | |
| DestroyAllParked | Long | Destroy all parked browsers, returns count destroyed | |
| GetParkedBrowserCount | Long | Count of currently parked browsers |
Parking Example
' Park a browser to free resources but keep state
pool.Park browserIndex
Debug.Print "Parked browsers: " & pool.GetParkedBrowserCount
' Later: destroy all parked browsers
Dim freed As Long
freed = pool.DestroyAllParked
Debug.Print "Freed " & freed & " browsers"
Embed browsers into VBA Frame controls or reparent them to different windows.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| EmbedInControl | browserIndex As Long, control As Object | Embed browser in VBA Frame control | |
| CreateInControl | url As String, control As Object | Long | Create + embed in one call, returns index |
| CreateInControlWithProfile | url As String, control As Object, profileName As String | Long | Create + embed with named profile |
| Reparent | browserIndex As Long, hwndNewParent As Long, x As Long, y As Long, w As Long, h As Long | Move browser to new parent window |
Embedding Example
Source: src\frmBrowser.cls
' Map local folder first (required for lv2.local URLs)
pool.SetLocalContentRoot idx, CurrentProject.Path & "\html"
' Create and embed in an Access Frame control in one call
Dim idx As Long
idx = pool.CreateInControl("https://lv2.local/app.html", Me.fraWebView)
If idx > 0 Then
m_browserIndex = idx
End If
Manage browser profiles, InPrivate mode, and browsing data per browser instance.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| GetProfileName | browserIndex As Long | String | Get profile name for browser |
| IsInPrivateMode | browserIndex As Long | Boolean | Check if browser is InPrivate |
| GetProfilePath | browserIndex As Long | String | On-disk profile folder path |
| ClearProfileBrowsingData | browserIndex As Long, dataKinds As Long | Clear browsing data by kind flags | |
| ClearProfileBrowsingDataAll | browserIndex As Long | Clear all browsing data for profile |
Manage browser lifecycle, visibility, sizing, and suspension state.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| IsValidIndex | browserIndex As Long | Boolean | Check if browser index is still valid |
| GetBrowserCount | Long | Count of active browsers in pool | |
| Resize | browserIndex As Long, x As Long, y As Long, width As Long, height As Long | Resize browser | |
| SetVisible | browserIndex As Long, visible As Boolean | Set browser visibility | |
| TrySuspend | browserIndex As Long | Suspend browser to save resources | |
| ResumeBrowser | browserIndex As Long | Resume suspended browser | |
| IsSuspended | browserIndex As Long | Boolean | Check if browser is suspended |
These methods do NOT take a browserIndex parameter — they query the system.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| IsWebView2RuntimeInstalled | Boolean | Check if WebView2 runtime is installed | |
| GetWebView2RuntimeVersion | String | Get installed runtime version string | |
| GetWebView2RuntimePath | String | Get runtime installation path |
Runtime Detection Example
' Check runtime before creating browsers
If Not pool.IsWebView2RuntimeInstalled Then
MsgBox "WebView2 runtime not found. Please install it."
Exit Sub
End If
Debug.Print "Runtime version: " & pool.GetWebView2RuntimeVersion
Allow JavaScript in the browser to call VBA macros directly, without manual WebMessageReceived routing.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| EnableAutoDispatch | browserIndex As Long, enabled As Boolean | Enable or disable auto-dispatch of HTML/JS calls to VBA macros | |
| IsAutoDispatchEnabled | browserIndex As Long | Boolean | Check whether auto-dispatch is currently enabled for this browser |
| SetAllowedVBAMacros | browserIndex As Long, macroList As String | Set comma-separated whitelist of VBA macro names that JS is allowed to call | |
| ClearAllowedVBAMacros | browserIndex As Long | Clear the VBA macro whitelist (blocks all auto-dispatch calls) | |
| RegisterVbaCallback | browserIndex As Long, jsName As String, callbackObject As Object, methodName As String | Register a VBA object method as a callable function from JavaScript. jsName is the name JS uses to call it. | |
| UnregisterVbaCallback | browserIndex As Long | Unregister all VBA callbacks for this browser |
Query and control audio playback state for a browser instance.
| Member | Parameters | Returns | Description |
|---|---|---|---|
| GetIsDocumentPlayingAudio | browserIndex As Long | Boolean | Check if the document is currently playing audio |
| GetIsMuted | browserIndex As Long | Boolean | Get the current mute state of the browser |
| SetIsMuted | browserIndex As Long, muted As Boolean | Mute or unmute the browser audio |
Additional methods available only on IBrowserPool (not on ILiteView2Ctrl).
| Member | Parameters | Returns | Description |
|---|---|---|---|
| GetUserAgent | browserIndex As Long | String | Get the current User-Agent string for this browser |
| SetDefaultBackgroundColor | browserIndex As Long, argbColor As Long | Set the default background color as ARGB (e.g. &HFF000000 for opaque black) | |
| ShowSaveAsDialog | browserIndex As Long | Show the browser's native Save As dialog | |
| GetLastError | browserIndex As Long | String | Get the last error message for this browser instance |
| GetLastErrorCode | browserIndex As Long | Long | Get the last error code (HRESULT) for this browser instance |
| DestroyBrowserSync | browserIndex As Long, timeoutMs As Long | Synchronously destroy a browser with a timeout. Blocks until the browser is destroyed or the timeout expires. |